Skip to content

Commit

Permalink
Fixed Flex total display amount when paid off flex items removed from…
Browse files Browse the repository at this point in the history
… the list
  • Loading branch information
m4rkw committed Jun 23, 2024
1 parent 129ef25 commit f4dfb9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 21 additions & 8 deletions monzo_utils/model/flex_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f4dfb9d

Please sign in to comment.