line/splitline: fremdwährung ok+test+migration
This commit is contained in:
parent
0f6180ebdb
commit
25dcdde09b
10 changed files with 485 additions and 217 deletions
29
splitline.py
29
splitline.py
|
@ -12,6 +12,7 @@ from trytond.i18n import gettext
|
|||
from trytond.transaction import Transaction
|
||||
from .line import sel_linetype, sel_bookingtype, STATES, DEPENDS
|
||||
from .book import sel_state_book
|
||||
from .mixin import SecondCurrencyMixin
|
||||
|
||||
|
||||
sel_linetype = [
|
||||
|
@ -25,7 +26,7 @@ sel_target = [
|
|||
]
|
||||
|
||||
|
||||
class SplitLine(ModelSQL, ModelView):
|
||||
class SplitLine(SecondCurrencyMixin, ModelSQL, ModelView):
|
||||
'Split booking line'
|
||||
__name__ = 'cashbook.split'
|
||||
|
||||
|
@ -57,6 +58,7 @@ class SplitLine(ModelSQL, ModelView):
|
|||
domain=[
|
||||
('owner.id', '=', Eval('owner_cashbook', -1)),
|
||||
('id', '!=', Eval('cashbook', -1)),
|
||||
('btype', '!=', None),
|
||||
],
|
||||
states={
|
||||
'readonly': STATES['readonly'],
|
||||
|
@ -106,26 +108,6 @@ class SplitLine(ModelSQL, ModelView):
|
|||
'type': gettext('cashbook.msg_line_bookingtype_%s' % self.line.bookingtype),
|
||||
}
|
||||
|
||||
def get_amount_by_second_currency(self, to_currency, amount=None):
|
||||
""" get amount, calculate credit/debit from currency of current
|
||||
cashbook to 'to_currency'
|
||||
"""
|
||||
Currency = Pool().get('currency.currency')
|
||||
|
||||
values = {
|
||||
'amount': amount if amount is not None else self.amount,
|
||||
}
|
||||
|
||||
if to_currency.id != self.line.cashbook.currency.id:
|
||||
with Transaction().set_context({
|
||||
'date': self.line.date,
|
||||
}):
|
||||
values['amount'] = Currency.compute(
|
||||
self.line.cashbook.currency,
|
||||
values['amount'],
|
||||
to_currency)
|
||||
return values
|
||||
|
||||
@fields.depends('splittype', 'category', 'booktransf')
|
||||
def on_change_splittype(self):
|
||||
""" clear category if not valid type
|
||||
|
@ -228,6 +210,11 @@ class SplitLine(ModelSQL, ModelView):
|
|||
Line2 = Pool().get('cashbook.line')
|
||||
|
||||
vlist = [x.copy() for x in vlist]
|
||||
for values in vlist:
|
||||
line = Line2(values.get('line', None))
|
||||
if line:
|
||||
values.update(cls.add_2nd_currency(values, line.cashbook.currency))
|
||||
|
||||
records = super(SplitLine, cls).create(vlist)
|
||||
|
||||
to_update_line = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue