From 59ce50299a8a7f34f48cf159245d974792d7bf22 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sun, 27 Apr 2025 15:57:55 -0300 Subject: [PATCH] fix(transactions): duplicate totals when account is shared with owner or owner-less and shared #247 --- app/apps/transactions/models.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/apps/transactions/models.py b/app/apps/transactions/models.py index 2b45b86..6fd6d36 100644 --- a/app/apps/transactions/models.py +++ b/app/apps/transactions/models.py @@ -118,13 +118,20 @@ class SoftDeleteManager(models.Manager): qs = SoftDeleteQuerySet(self.model, using=self._db) user = get_current_user() if user and not user.is_anonymous: - return qs.filter( - Q(account__visibility="public") - | Q(account__owner=user) - | Q(account__shared_with=user) - | Q(account__visibility="private", account__owner=None), - deleted=False, - ).distinct() + account_ids = ( + qs.filter( + Q(account__visibility="public") + | Q(account__owner=user) + | Q(account__shared_with=user) + | Q(account__visibility="private", account__owner=None), + deleted=False, + ) + .values_list("account__id", flat=True) + .distinct() + ) + + return qs.filter(account_id__in=account_ids, deleted=False) + else: return qs.filter( deleted=False,