From 0f60f8d486096225f8f9b6ee51a1851bf7a1d1c8 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Tue, 25 Feb 2025 10:48:43 -0300 Subject: [PATCH] fix(rules): Update or Create Transaction rule unable to match againt dates and other types --- app/apps/rules/models.py | 6 ++---- app/apps/rules/tasks.py | 8 +++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/apps/rules/models.py b/app/apps/rules/models.py index 412b781..9d462fe 100644 --- a/app/apps/rules/models.py +++ b/app/apps/rules/models.py @@ -297,10 +297,8 @@ class UpdateOrCreateTransactionRuleAction(models.Model): search_query = Q() def add_to_query(field_name, value, operator): - if isinstance(value, (int, str)): - lookup = f"{field_name}__{operator}" - return Q(**{lookup: value}) - return Q() + lookup = f"{field_name}__{operator}" + return Q(**{lookup: value}) if self.search_account: value = simple.eval(self.search_account) diff --git a/app/apps/rules/tasks.py b/app/apps/rules/tasks.py index af54d76..2d3227c 100644 --- a/app/apps/rules/tasks.py +++ b/app/apps/rules/tasks.py @@ -131,14 +131,16 @@ def _process_update_or_create_transaction_action(action, simple_eval): # Build search query using the helper method search_query = action.build_search_query(simple_eval) + logger.info("Searching transactions using: %s", search_query) # Find latest matching transaction or create new if search_query: - transaction = ( - Transaction.objects.filter(search_query).order_by("-date", "-id").first() - ) + transactions = Transaction.objects.filter(search_query).order_by("-date", "-id") + transaction = transactions.first() + logger.info("Found at least one matching transaction, using latest") else: transaction = None + logger.info("No matching transaction found, creating a new transaction") if not transaction: transaction = Transaction()