1
0
Fork 0
mirror of https://github.com/dancojocaru2000/foxbank.git synced 2025-02-22 23:39:36 +02:00

Added transfer between different currency accounts

This commit is contained in:
Kenneth Bruen 2022-01-03 21:49:38 +02:00
parent 9a1e1b4fce
commit c7c8f3c765
Signed by: kbruen
GPG key ID: C1980A470C3EE5B1
2 changed files with 9 additions and 3 deletions

View file

@ -6,7 +6,7 @@ from marshmallow import Schema, fields
import re
from ..decorators import ensure_logged_in
from ..db_utils import get_transactions, get_account, get_accounts, insert_transaction, whose_account, insert_notification
from ..db_utils import get_transactions, get_account, get_accounts, insert_transaction, whose_account, insert_notification, get_forex_rate
from ..models import Account, Notification, Transaction
from ..utils.iban import check_iban
from .. import decorators, returns
@ -82,15 +82,18 @@ class TransactionsList(MethodView):
if destination_iban[4:8] == 'FOXB':
for acc in get_accounts():
if destination_iban == acc.iban:
rate = get_forex_rate(account.currency, acc.currency)
reverse_transaction = Transaction.new_transaction(
date_time=date,
transaction_type='receive_transfer',
status='processed',
other_party={'iban': account.iban,},
extra={
'currency': account.currency,
'amount': -amount,
'currency': acc.currency,
'amount': int(-amount * rate),
'description': description,
'originalAmount': -amount,
'originalCurrency': account.currency,
},
)
insert_transaction(acc.id, reverse_transaction)

View file

@ -308,6 +308,9 @@ class Module(ModuleType):
@get_db
def get_forex_rate(self, from_currency: str, to_currency: str) -> float | None:
if from_currency == to_currency:
return 1.0
cur = self.db.cursor()
if from_currency == 'RON' or to_currency == 'RON':