line: fremd-währungs(und andere)-daten extern erweiterbar

This commit is contained in:
Frederik Jaeckel 2023-01-15 00:34:44 +01:00
parent f2ecd3e174
commit a9773a42df

34
line.py
View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 # The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms. # full copyright notices and license terms.
@ -804,7 +804,7 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
return result return result
@classmethod @classmethod
def get_debit_credit(cls, values): def get_debit_credit(cls, values, line=None):
""" compute debit/credit from amount """ compute debit/credit from amount
""" """
if isinstance(values, dict): if isinstance(values, dict):
@ -814,21 +814,22 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
type_ = getattr(values, 'bookingtype', None) type_ = getattr(values, 'bookingtype', None)
amount = getattr(values, 'amount', None) amount = getattr(values, 'amount', None)
result = {}
if type_: if type_:
if amount is not None: if amount is not None:
if type_ in ['in', 'mvin', 'spin']: if type_ in ['in', 'mvin', 'spin']:
return { result.update({
'debit': Decimal('0.0'), 'debit': Decimal('0.0'),
'credit': amount, 'credit': amount,
} })
elif type_ in ['out', 'mvout', 'spout']: elif type_ in ['out', 'mvout', 'spout']:
return { result.update({
'debit': amount, 'debit': amount,
'credit': Decimal('0.0'), 'credit': Decimal('0.0'),
} })
else : else :
raise ValueError('invalid "bookingtype"') raise ValueError('invalid "bookingtype"')
return {} return result
@classmethod @classmethod
def update_amount_by_splitlines(cls, lines): def update_amount_by_splitlines(cls, lines):
@ -950,20 +951,25 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
default.setdefault('state', cls.default_state()) default.setdefault('state', cls.default_state())
return super(Line, cls).copy(moves, default=default) 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 @classmethod
def create(cls, vlist): def create(cls, vlist):
""" add debit/credit """ add debit/credit
""" """
Cashbook = Pool().get('cashbook.book')
vlist = [x.copy() for x in vlist] vlist = [x.copy() for x in vlist]
for values in vlist: for values in vlist:
values.update(cls.get_debit_credit(values)) values.update(cls.get_debit_credit(values))
values.update(cls.clear_by_bookingtype(values)) values.update(cls.clear_by_bookingtype(values))
values.update(cls.add_2nd_unit_values(values))
cashbook = values.get('cashbook', None)
if cashbook:
values.update(cls.add_2nd_currency(values, Cashbook(cashbook).currency))
# deny add to reconciliation if state is not 'check', 'recon' or 'done' # deny add to reconciliation if state is not 'check', 'recon' or 'done'
if values.get('reconciliation', None): 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.clear_by_bookingtype(values, line))
values2.update(cls.get_debit_credit({ values2.update(cls.get_debit_credit({
x:values.get(x, getattr(line, x)) for x in ['amount', 'bookingtype'] x:values.get(x, getattr(line, x)) for x in ['amount', 'bookingtype']
})) }, line=line))
to_write.extend([lines, values2]) to_write.extend([lines, values2])
else : else :
to_write.extend([lines, values]) to_write.extend([lines, values])