Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chart with average basket price #450

Merged
merged 2 commits into from
Dec 1, 2023
Merged

Add chart with average basket price #450

merged 2 commits into from
Dec 1, 2023

Conversation

tvedeane
Copy link
Contributor

This adds a new graph:

image

Testing it requires some data:

INSERT INTO "public"."statistics_processedpurchasefiles" ("id", "file_name", "processed_on") VALUES
(1, 'test', '2023-11-27 18:02:48.434505+00');
INSERT INTO "public"."statistics_purchasebasket" ("id", "purchase_date", "cashier", "purchase_counter", "gross_amount", "first_net_amount", "second_net_amount", "discount", "source_file_id", "tapir_user_id") VALUES
(3, '2023-11-27 18:02:48.434505+00', 1000, 2000, 28.88, 20, 20, 0, 1, 1066),
(4, '2023-11-01 18:02:48.434505+00', 1000, 2000, 28.88, 20, 20, 0, 1, 1066),
(5, '2023-10-27 18:02:48.434505+00', 1000, 2000, 28.88, 20, 20, 0, 1, 1066),
(6, '2023-10-27 18:02:48.434505+00', 1000, 2000, 128.88, 20, 20, 0, 1, 1066),
(7, '2023-07-27 18:02:48.434505+00', 1000, 2000, 28.88, 20, 20, 0, 1, 1066),
(8, '2023-07-27 18:02:48.434505+00', 1000, 2000, 28.88, 20, 20, 0, 1, 1065);

And then you can go to: http://localhost:8000/accounts/user/1066/

tapir_user = get_object_or_404(TapirUser, pk=(self.kwargs["pk"]))
logged_user = self.request.user
if tapir_user.pk != logged_user.pk and not logged_user.has_perm(
PERMISSION_COOP_MANAGE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure about this line - maybe it should be another permission?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think PERMISSION_ACCOUNTS_VIEW is more appropriate.
Also, you can use the PermissionRequiredMixin to check for permissions, you can then reuse the same logic as the the TapirUserDetailView :

def get_permission_required(self):
if self.request.user.pk == self.kwargs["pk"]:
return []
return [PERMISSION_ACCOUNTS_VIEW]

Copy link
Contributor

@Theophile-Madet Theophile-Madet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for doing this 🙇

There was a confusion about what number we want to show, see the comments.
Otherwise, appart from a few small improvements, the structure is good 💯

tapir_user = get_object_or_404(TapirUser, pk=(self.kwargs["pk"]))
logged_user = self.request.user
if tapir_user.pk != logged_user.pk and not logged_user.has_perm(
PERMISSION_COOP_MANAGE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think PERMISSION_ACCOUNTS_VIEW is more appropriate.
Also, you can use the PermissionRequiredMixin to check for permissions, you can then reuse the same logic as the the TapirUserDetailView :

def get_permission_required(self):
if self.request.user.pk == self.kwargs["pk"]:
return []
return [PERMISSION_ACCOUNTS_VIEW]

@Theophile-Madet
Copy link
Contributor

Theophile-Madet commented Nov 29, 2023

About adding test data, usually we do it through the models .objects.create() in python code, we can easily execute arbitrary code with docker compose exec web poetry run python manage.py shell_plus. This way we are sure that Django finds the database as it expects it.
If you're feeling extra motivated, you could add stuff to tapir.utils.management.commands.generate_test_data_functions.reset_all_test_data, that's the function that generates our test data.

@Theophile-Madet
Copy link
Contributor

Thanks again for contributing, it's great 🎉

@tvedeane
Copy link
Contributor Author

I applied all the suggestions. Thanks for the review :)

Copy link
Contributor

@Theophile-Madet Theophile-Madet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@Theophile-Madet Theophile-Madet merged commit 4d08c3d into SuperCoopBerlin:master Dec 1, 2023
@tvedeane tvedeane deleted the chart-price-basket branch December 1, 2023 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants