add test for eur --> chf (asset in usd)

This commit is contained in:
Frederik Jaeckel 2024-03-06 23:02:24 +01:00
parent d7aaa5eacc
commit 79926fbe5d
2 changed files with 124 additions and 5 deletions

View file

@ -511,20 +511,22 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
Returns:
dict: dictionary to create cashbook-line record
"""
asset_book = Cashbook(aline['booktransf'])
from_book = Cashbook(aline['cashbook'])
to_book = Cashbook(aline['booktransf'])
# add 2nd currency if currencies are different
aline = Line.add_2nd_currency(aline, asset_book.currency)
aline = Line.add_2nd_currency(aline, from_book.currency)
target_amount = aline.get('amount_2nd_currency', aline['amount'])
asset_rate = asset_book.asset.rate
asset_rate = to_book.asset.rate
with Transaction().set_context({'date': aline['date']}):
# convert rate of asset to currency of target-cashbook
asset_rate = Currency.compute(
asset_book.asset.currency, asset_rate, asset_book.currency,
to_book.asset.currency, asset_rate, to_book.currency,
round=False)
aline['quantity'] = Decimal('0.0')
if asset_rate:
aline['quantity'] = target_amount / asset_rate
aline['quantity'] = (target_amount / asset_rate).quantize(
Decimal(Decimal(1) / 10 ** to_book.quantity_digits))
return aline
to_create = []