From a9773a42dfdd2ffb0df4adb49912fa13016b0332 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Sun, 15 Jan 2023 00:34:44 +0100 Subject: [PATCH] =?UTF-8?q?line:=20fremd-w=C3=A4hrungs(und=20andere)-daten?= =?UTF-8?q?=20extern=20erweiterbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- line.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/line.py b/line.py index ad1ea15..7c877bc 100644 --- a/line.py +++ b/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])