Create booking from standard-cashbook to asset-cashbook
This commit is contained in:
parent
9c40e8990a
commit
d7aaa5eacc
2 changed files with 46 additions and 21 deletions
47
planner.py
47
planner.py
|
@ -489,11 +489,43 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
|
||||
@classmethod
|
||||
def run_booking(cls, records):
|
||||
""" do prepared booking
|
||||
""" create planned bookings
|
||||
|
||||
Args:
|
||||
records (list): list of planned bokings
|
||||
"""
|
||||
pool = Pool()
|
||||
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):
|
||||
""" compute quantity from rate of asset and
|
||||
amount to invest
|
||||
|
||||
Args:
|
||||
aline (dict): prepared dictionary to create
|
||||
cashbook-line-record
|
||||
|
||||
Returns:
|
||||
dict: dictionary to create cashbook-line record
|
||||
"""
|
||||
asset_book = Cashbook(aline['booktransf'])
|
||||
|
||||
# add 2nd currency if currencies are different
|
||||
aline = Line.add_2nd_currency(aline, asset_book.currency)
|
||||
target_amount = aline.get('amount_2nd_currency', aline['amount'])
|
||||
asset_rate = asset_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,
|
||||
round=False)
|
||||
aline['quantity'] = Decimal('0.0')
|
||||
if asset_rate:
|
||||
aline['quantity'] = target_amount / asset_rate
|
||||
return aline
|
||||
|
||||
to_create = []
|
||||
to_create_check = []
|
||||
|
@ -514,28 +546,17 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
if record.booktransf:
|
||||
line['booktransf'] = record.booktransf.id
|
||||
if record.booktransf.feature == 'asset':
|
||||
# add 2nd currency if currencies are different
|
||||
line = Line.add_2nd_currency(
|
||||
line, record.booktransf.currency)
|
||||
print('-- line-1:', line)
|
||||
if record.booktransf.current_rate:
|
||||
line['quantity'] = (line.get(
|
||||
'amount_2nd_currency', record.amount) /
|
||||
record.booktransf.asset.rate)
|
||||
line.update(add_asset_values(line))
|
||||
|
||||
print('-- line-2:', line)
|
||||
if record.wfcheck:
|
||||
to_create_check.append(line)
|
||||
else:
|
||||
to_create.append(line)
|
||||
|
||||
if to_create_check:
|
||||
print('-- to_create_check:', to_create_check)
|
||||
lines = Line.create(to_create_check)
|
||||
Line.wfcheck(lines)
|
||||
|
||||
if to_create:
|
||||
print('-- to_create:', to_create)
|
||||
Line.create(to_create)
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue