fix: show right user in statistics overview

This commit is contained in:
leander committed 2026-11-04 22:32:25 +01:00
1 parent dd859a6b67
commit 121e4c25de
2 files changed
+16 -1

No files matched your search

+1 -1
View File
@@ -247,7 +247,7 @@ class UserProfile(models.Model):
)
def product_order_stats(self):
return OrderLine.objects.filter(order__customer__pk=self.pk).product_order_stats()
return OrderLine.objects.filter(order__customer_id=self.user_id).product_order_stats()
def order_sum_total(self) -> Decimal:
return Order.objects.filter(customer_id=self.user_id).aggregate(sum=Sum("order_sum"))["sum"] or 0
+15
View File
@@ -289,6 +289,21 @@ def test_userprofile_product_order_stats(user, product):
assert result[0]["product_name"] == "borg"
def test_userprofile_product_order_stats_uses_the_profiles_user(db, product): # noqa: ARG001
# Create the profiles in the opposite order of the users, so profile and user ids differ
alice = DjangoUser.objects.create_user(username="alice")
bob = DjangoUser.objects.create_user(username="bob")
bob_profile = UserProfile.objects.create(user=bob)
alice_profile = UserProfile.objects.create(user=alice)
assert alice_profile.pk != alice.pk
o = Order.objects.create(customer=alice, order_sum=30)
OrderLine.objects.create(order=o, product=product, amount=1, unit_price=30)
assert [row["product_name"] for row in alice_profile.product_order_stats()] == ["borg"]
assert list(bob_profile.product_order_stats()) == []
def test_image_url_with_email(user):
expected_hash = hashlib.sha256(user.email.lower().strip().encode()).hexdigest()
assert expected_hash in user.profile.image_url()