line: fremd-währungs(und andere)-daten extern erweiterbar
This commit is contained in:
parent
f2ecd3e174
commit
a9773a42df
1 changed files with 20 additions and 14 deletions
34
line.py
34
line.py
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the cashbook-module from m-ds for Tryton.
|
||||
# This file is part of the cashbook-module from m-ds.de for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
|
@ -804,7 +804,7 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
|||
return result
|
||||
|
||||
@classmethod
|
||||
def get_debit_credit(cls, values):
|
||||
def get_debit_credit(cls, values, line=None):
|
||||
""" compute debit/credit from amount
|
||||
"""
|
||||
if isinstance(values, dict):
|
||||
|
@ -814,21 +814,22 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
|||
type_ = getattr(values, 'bookingtype', None)
|
||||
amount = getattr(values, 'amount', None)
|
||||
|
||||
result = {}
|
||||
if type_:
|
||||
if amount is not None:
|
||||
if type_ in ['in', 'mvin', 'spin']:
|
||||
return {
|
||||
result.update({
|
||||
'debit': Decimal('0.0'),
|
||||
'credit': amount,
|
||||
}
|
||||
})
|
||||
elif type_ in ['out', 'mvout', 'spout']:
|
||||
return {
|
||||
result.update({
|
||||
'debit': amount,
|
||||
'credit': Decimal('0.0'),
|
||||
}
|
||||
})
|
||||
else :
|
||||
raise ValueError('invalid "bookingtype"')
|
||||
return {}
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def update_amount_by_splitlines(cls, lines):
|
||||
|
@ -950,20 +951,25 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
|||
default.setdefault('state', cls.default_state())
|
||||
return super(Line, cls).copy(moves, default=default)
|
||||
|
||||
@classmethod
|
||||
def add_2nd_unit_values(cls, values):
|
||||
""" extend create-values
|
||||
"""
|
||||
Cashbook = Pool().get('cashbook.book')
|
||||
cashbook = values.get('cashbook', None)
|
||||
if cashbook:
|
||||
values.update(cls.add_2nd_currency(values, Cashbook(cashbook).currency))
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
""" add debit/credit
|
||||
"""
|
||||
Cashbook = Pool().get('cashbook.book')
|
||||
|
||||
vlist = [x.copy() for x in vlist]
|
||||
for values in vlist:
|
||||
values.update(cls.get_debit_credit(values))
|
||||
values.update(cls.clear_by_bookingtype(values))
|
||||
|
||||
cashbook = values.get('cashbook', None)
|
||||
if cashbook:
|
||||
values.update(cls.add_2nd_currency(values, Cashbook(cashbook).currency))
|
||||
values.update(cls.add_2nd_unit_values(values))
|
||||
|
||||
# deny add to reconciliation if state is not 'check', 'recon' or 'done'
|
||||
if values.get('reconciliation', None):
|
||||
|
@ -1017,7 +1023,7 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
|||
values2.update(cls.clear_by_bookingtype(values, line))
|
||||
values2.update(cls.get_debit_credit({
|
||||
x:values.get(x, getattr(line, x)) for x in ['amount', 'bookingtype']
|
||||
}))
|
||||
}, line=line))
|
||||
to_write.extend([lines, values2])
|
||||
else :
|
||||
to_write.extend([lines, values])
|
||||
|
|
Loading…
Reference in a new issue