Skip to content

Commit

Permalink
allow configuring how rounding occurs for finance transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rkw committed Jun 19, 2024
1 parent acdaa88 commit 129ef25
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 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.6 - 19/06/2024

- allow configuring how rounding occurs for finance transactions

## 0.1.5 - 18/06/2024

- fixed incorrect payment status for Flex transactions
Expand Down
24 changes: 22 additions & 2 deletions monzo_utils/model/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,29 @@ def all_finance_transactions(self):
if 'all_finance_transactions' in self.cache:
return self.cache['all_finance_transactions']

amounts = [int(self.payment_config['amount'] / self.payment_config['months'] * 100) / 100]
total = int(self.payment_config['amount'] * 100)

final_payment = round(self.payment_config['amount'] - (amounts[0] * (self.payment_config['months']-1)), 2)
if 'round' in self.payment_config and self.payment_config['round'] == 'up':
if total % self.payment_config['months'] != 0:
adjusted = total

while adjusted % self.payment_config['months'] != 0:
adjusted += 1

initial_payment = adjusted / self.payment_config['months']

final_payment = total - (initial_payment * (self.payment_config['months']-1))

amounts = [initial_payment / 100, final_payment / 100]
else:
amounts = [int(self.payment_config['amount'] / self.payment_config['months'] * 100) / 100]
else:
amounts = [int(self.payment_config['amount'] / self.payment_config['months'] * 100) / 100]

final_payment = round(self.payment_config['amount'] - (amounts[0] * (self.payment_config['months']-1)), 2)

if final_payment not in amounts:
amounts.append(final_payment)

if final_payment not in amounts:
amounts.append(final_payment)
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.5',
version='0.1.6',
description='Monzo Utils',
author='Mark Wadham',
url='https://github.com/m4rkw/monzo-utils',
Expand Down

0 comments on commit 129ef25

Please sign in to comment.