From f2f6d9cdd915460517aa944d80ab2ce57483722d Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 2 Oct 2024 21:01:58 +0200 Subject: [PATCH] fix(users): fix count calculation when FK is null. ref #419 --- open_prices/users/models.py | 6 +++--- open_prices/users/tests.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/open_prices/users/models.py b/open_prices/users/models.py index 4fb84689..77684319 100644 --- a/open_prices/users/models.py +++ b/open_prices/users/models.py @@ -46,7 +46,7 @@ def update_location_count(self): from open_prices.prices.models import Price self.location_count = ( - Price.objects.filter(owner=self.user_id) + Price.objects.filter(owner=self.user_id, location_id__isnull=False) .values_list("location_id", flat=True) .distinct() .count() @@ -57,7 +57,7 @@ def update_product_count(self): from open_prices.prices.models import Price self.product_count = ( - Price.objects.filter(owner=self.user_id) + Price.objects.filter(owner=self.user_id, product_id__isnull=False) .values_list("product_id", flat=True) .distinct() .count() @@ -68,7 +68,7 @@ def update_proof_count(self): from open_prices.prices.models import Price self.proof_count = ( - Price.objects.filter(owner=self.user_id) + Price.objects.filter(owner=self.user_id, proof_id__isnull=False) .values_list("proof_id", flat=True) .distinct() .count() diff --git a/open_prices/users/tests.py b/open_prices/users/tests.py index 06efe36b..ab03d2fa 100644 --- a/open_prices/users/tests.py +++ b/open_prices/users/tests.py @@ -47,7 +47,6 @@ def setUpTestData(cls): product_code="0123456789101", location_osm_id=cls.location.osm_id, location_osm_type=cls.location.osm_type, - proof_id=cls.proof.id, price=2.0, owner=cls.user.user_id, )