tests: increase complexity when booking cash->asset
This commit is contained in:
parent
79926fbe5d
commit
2e8f81bd99
2 changed files with 52 additions and 21 deletions
38
planner.py
38
planner.py
|
@ -498,35 +498,36 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
IrDate = pool.get('ir.date')
|
||||
Line = pool.get('cashbook.line')
|
||||
Currency = pool.get('currency.currency')
|
||||
Cashbook = pool.get('cashbook.book')
|
||||
|
||||
def add_asset_values(aline):
|
||||
def add_asset_values(aline, from_book, to_book):
|
||||
""" compute quantity from rate of asset and
|
||||
amount to invest
|
||||
|
||||
Args:
|
||||
aline (dict): prepared dictionary to create
|
||||
cashbook-line-record
|
||||
from_book (record): cashbook record,
|
||||
to_book (record): cashbook record
|
||||
|
||||
Returns:
|
||||
dict: dictionary to create cashbook-line record
|
||||
"""
|
||||
from_book = Cashbook(aline['cashbook'])
|
||||
to_book = Cashbook(aline['booktransf'])
|
||||
|
||||
# add 2nd currency if currencies are different
|
||||
aline = Line.add_2nd_currency(aline, from_book.currency)
|
||||
target_amount = aline.get('amount_2nd_currency', aline['amount'])
|
||||
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(
|
||||
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).quantize(
|
||||
Decimal(Decimal(1) / 10 ** to_book.quantity_digits))
|
||||
# convert amount to target-currency
|
||||
target_amount = Currency.compute(
|
||||
from_book.currency, aline['amount'],
|
||||
to_book.currency, round=False)
|
||||
# convert asset-rate of target-cashbook to target-currency
|
||||
asset_rate = (Currency.compute(
|
||||
to_book.asset.currency, to_book.asset.rate,
|
||||
to_book.currency, round=False) * Decimal(
|
||||
to_book.asset.uom.factor /
|
||||
to_book.quantity_uom.factor))
|
||||
|
||||
aline['quantity'] = Decimal('0.0')
|
||||
if asset_rate:
|
||||
aline['quantity'] = (target_amount / asset_rate).quantize(
|
||||
Decimal(Decimal(1) / 10 ** to_book.quantity_digits))
|
||||
return aline
|
||||
|
||||
to_create = []
|
||||
|
@ -548,7 +549,8 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
if record.booktransf:
|
||||
line['booktransf'] = record.booktransf.id
|
||||
if record.booktransf.feature == 'asset':
|
||||
line.update(add_asset_values(line))
|
||||
line.update(add_asset_values(
|
||||
line, record.cashbook, record.booktransf))
|
||||
|
||||
if record.wfcheck:
|
||||
to_create_check.append(line)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue