mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-25 10:08:36 +02:00
fix(rules): Update or Create Transaction rule unable to match againt dates and other types
This commit is contained in:
@@ -297,10 +297,8 @@ class UpdateOrCreateTransactionRuleAction(models.Model):
|
|||||||
search_query = Q()
|
search_query = Q()
|
||||||
|
|
||||||
def add_to_query(field_name, value, operator):
|
def add_to_query(field_name, value, operator):
|
||||||
if isinstance(value, (int, str)):
|
lookup = f"{field_name}__{operator}"
|
||||||
lookup = f"{field_name}__{operator}"
|
return Q(**{lookup: value})
|
||||||
return Q(**{lookup: value})
|
|
||||||
return Q()
|
|
||||||
|
|
||||||
if self.search_account:
|
if self.search_account:
|
||||||
value = simple.eval(self.search_account)
|
value = simple.eval(self.search_account)
|
||||||
|
|||||||
@@ -131,14 +131,16 @@ def _process_update_or_create_transaction_action(action, simple_eval):
|
|||||||
|
|
||||||
# Build search query using the helper method
|
# Build search query using the helper method
|
||||||
search_query = action.build_search_query(simple_eval)
|
search_query = action.build_search_query(simple_eval)
|
||||||
|
logger.info("Searching transactions using: %s", search_query)
|
||||||
|
|
||||||
# Find latest matching transaction or create new
|
# Find latest matching transaction or create new
|
||||||
if search_query:
|
if search_query:
|
||||||
transaction = (
|
transactions = Transaction.objects.filter(search_query).order_by("-date", "-id")
|
||||||
Transaction.objects.filter(search_query).order_by("-date", "-id").first()
|
transaction = transactions.first()
|
||||||
)
|
logger.info("Found at least one matching transaction, using latest")
|
||||||
else:
|
else:
|
||||||
transaction = None
|
transaction = None
|
||||||
|
logger.info("No matching transaction found, creating a new transaction")
|
||||||
|
|
||||||
if not transaction:
|
if not transaction:
|
||||||
transaction = Transaction()
|
transaction = Transaction()
|
||||||
|
|||||||
Reference in New Issue
Block a user