From f4dfb9dc56a565bda8b45f16f0da291aa74d443c Mon Sep 17 00:00:00 2001 From: mark Date: Sun, 23 Jun 2024 12:24:37 +0100 Subject: [PATCH] Fixed Flex total display amount when paid off flex items removed from the list --- CHANGELOG.md | 4 ++++ monzo_utils/model/flex_summary.py | 29 +++++++++++++++++++++-------- setup.py | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3947159..4d2d81c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.7 - 23/06/2024 + +- Fixed Flex total display amount when paid off flex items removed from the list + ## 0.1.6 - 19/06/2024 - allow configuring how rounding occurs for finance transactions diff --git a/monzo_utils/model/flex_summary.py b/monzo_utils/model/flex_summary.py index 01472cd..0201ae2 100644 --- a/monzo_utils/model/flex_summary.py +++ b/monzo_utils/model/flex_summary.py @@ -31,6 +31,9 @@ def name(self): @property def display_amount(self): + if self.last_payment: + return self.last_payment.money_in + return self.flex_total @@ -72,15 +75,25 @@ def last_payment(self): account = Account.one("select * from account where name = %s", [self.config['flex_account']]) - transaction = Transaction.one("select * from transaction where account_id = %s and declined = %s and money_in = %s and description = %s and `date` > %s order by created_at asc limit 1", [ - account.id, - 0, - self.display_amount, - 'Flex', - self.last_salary_date - ]) + transactions_by_diff = {} + + for transaction in Transaction.find("select * from transaction where account_id = %s and declined = %s and description = %s and `date` > %s order by created_at asc", [ + account.id, + 0, + 'Flex', + self.last_salary_date + ]): + if transaction.settled.day == 16: + diff = int(abs(self.flex_total - transaction.money_in) * 100) + + if diff not in transactions_by_diff: + transactions_by_diff[diff] = [] + + transactions_by_diff[diff].append(transaction) - if not transaction: + if len(transactions_by_diff) >0: + transaction = transactions_by_diff[sorted(transactions_by_diff.keys())[0]][0] + else: transaction = None self.cache['last_payment'] = transaction diff --git a/setup.py b/setup.py index e744959..abff664 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name='monzo-utils', - version='0.1.6', + version='0.1.7', description='Monzo Utils', author='Mark Wadham', url='https://github.com/m4rkw/monzo-utils',