line: valid handling of 2nd-currency + test

This commit is contained in:
Frederik Jaeckel 2022-08-23 15:34:36 +02:00
parent 50c3ef04bc
commit 04fdd9dc9e
3 changed files with 303 additions and 5 deletions

30
line.py
View file

@ -251,17 +251,17 @@ class Line(Workflow, ModelSQL, ModelView):
))
# in case of 'mvin' or 'mvout' - create counterpart
if (line.bookingtype in ['mvout', 'mvin']) and (line.reference is None):
to_create_line.append({
values = {
'cashbook': line.booktransf.id,
'bookingtype': 'mvin' if line.bookingtype == 'mvout' else 'mvout',
'date': line.date,
'description': line.description,
'amount': line.amount,
'credit': line.debit,
'debit': line.credit,
'booktransf': line.cashbook.id,
'reference': line.id,
})
}
values.update(line.get_amount_by_second_currency(line.booktransf.currency))
values.update(cls.get_debit_credit(values))
to_create_line.append(values)
# add number to line
if line.cashbook.number_atcheck == True:
@ -342,6 +342,26 @@ class Line(Workflow, ModelSQL, ModelView):
'type': gettext('cashbook.msg_line_bookingtype_%s' % self.bookingtype),
}
def get_amount_by_second_currency(self, to_currency):
""" get amount, calculate credit/debit from currency of current
cashbook to 'to_currency'
"""
Currency = Pool().get('currency.currency')
values = {
'amount': self.amount,
}
if to_currency.id != self.cashbook.currency.id:
with Transaction().set_context({
'date': self.date,
}):
values['amount'] = Currency.compute(
self.cashbook.currency,
self.amount,
to_currency)
return values
@staticmethod
def order_state(tables):
""" edit = 0, check/done = 1