Skip to content

Commit

Permalink
fixed incorrect payment status for Flex transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rkw committed Jun 14, 2024
1 parent 6aef05a commit e36816a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
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.4 - 14/06/2024

- fixed incorrect payment status for Flex transactions

## 0.1.3 - 26/05/2024

- support auto topup of pots
Expand Down
36 changes: 36 additions & 0 deletions monzo_utils/model/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from monzo_utils.model.payment import Payment
from monzo_utils.model.account import Account
from monzo_utils.model.transaction import Transaction
from monzo_utils.lib.transactions_seen import TransactionsSeen

class Flex(Payment):

Expand Down Expand Up @@ -135,3 +136,38 @@ def amount_for_period(self, salary_from_date, salary_to_date):
return 0

return amount


# older last payment, may be before start_date
@property
def older_last_payment(self):
if 'older_last_payment' in self.cache:
return self.cache['older_last_payment']

where, params = self.get_transaction_where_condition()

sql = "select * from transaction"

if 'metadata' in self.payment_config:
for i in range(0, len(self.payment_config['metadata'])):
sql += " join transaction_metadata meta%d on transaction.id = meta%d.transaction_id" % (i+1, i+1)

transactions = Transaction.find(
f"{sql} where {where} order by created_at desc",
params
)

for transaction in transactions:
if transaction.date.day != self.config['flex_payment_date']:
continue

if transaction.id not in TransactionsSeen().seen:
TransactionsSeen().seen[transaction.id] = 1

self.cache['older_last_payment'] = transaction

return self.cache['older_last_payment']

self.cache['older_last_payment'] = None

return self.cache['older_last_payment']
36 changes: 36 additions & 0 deletions monzo_utils/model/flex_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from monzo_utils.model.payment import Payment
from monzo_utils.model.account import Account
from monzo_utils.model.transaction import Transaction
from monzo_utils.lib.transactions_seen import TransactionsSeen

class FlexSummary(Payment):

Expand Down Expand Up @@ -85,3 +86,38 @@ def last_payment(self):
self.cache['last_payment'] = transaction

return transaction


# older last payment, may be before start_date
@property
def older_last_payment(self):
if 'older_last_payment' in self.cache:
return self.cache['older_last_payment']

where, params = self.get_transaction_where_condition()

sql = "select * from transaction"

if 'metadata' in self.payment_config:
for i in range(0, len(self.payment_config['metadata'])):
sql += " join transaction_metadata meta%d on transaction.id = meta%d.transaction_id" % (i+1, i+1)

transactions = Transaction.find(
f"{sql} where {where} order by created_at desc",
params
)

for transaction in transactions:
if transaction.date.day != self.config['flex_payment_date']:
continue

if transaction.id not in TransactionsSeen().seen:
TransactionsSeen().seen[transaction.id] = 1

self.cache['older_last_payment'] = transaction

return self.cache['older_last_payment']

self.cache['older_last_payment'] = None

return self.cache['older_last_payment']
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.3',
version='0.1.4',
description='Monzo Utils',
author='Mark Wadham',
url='https://github.com/m4rkw/monzo-utils',
Expand Down

0 comments on commit e36816a

Please sign in to comment.