From d62a64e186244ec528506f90f840a6009c031fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 21 Feb 2023 12:37:07 +0100 Subject: [PATCH] Allow statement line with amount of zero --- modules/account_statement/CHANGELOG | 1 + modules/account_statement/message.xml | 3 --- modules/account_statement/statement.py | 14 ++++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/account_statement/CHANGELOG b/modules/account_statement/CHANGELOG index 0d810a8a16..126d0d3bb2 100644 --- a/modules/account_statement/CHANGELOG +++ b/modules/account_statement/CHANGELOG @@ -1,3 +1,4 @@ +* Allow line with amount of zero * Remove support for Python 3.7 * Add support for Python 3.11 diff --git a/modules/account_statement/message.xml b/modules/account_statement/message.xml index d46ddec636..bab7027298 100644 --- a/modules/account_statement/message.xml +++ b/modules/account_statement/message.xml @@ -36,9 +36,6 @@ this repository contains the full copyright notices and license terms. --> To post statement "%(statement)s" you must create lines for pending %(amount)s of origin "%(origin)s". - - Statement line amount cannot be zero. - To post the move "%(move)s" you must post the statement "%(statement)s". diff --git a/modules/account_statement/statement.py b/modules/account_statement/statement.py index ab0f69689b..bf36fd2544 100644 --- a/modules/account_statement/statement.py +++ b/modules/account_statement/statement.py @@ -12,7 +12,7 @@ from sql.operators import Concat from trytond.config import config from trytond.i18n import gettext from trytond.model import ( - Check, DictSchemaMixin, Index, ModelSQL, ModelView, Workflow, fields, + DictSchemaMixin, Index, ModelSQL, ModelView, Workflow, fields, sequence_ordered) from trytond.model.exceptions import AccessError from trytond.modules.company import CompanyReport @@ -554,6 +554,8 @@ class Statement(Workflow, ModelSQL, ModelView): amount_second_currency = 0 for line in lines: move_line = line.get_move_line() + if not move_line: + continue move_line.move = move amount += move_line.debit - move_line.credit if move_line.amount_second_currency: @@ -798,11 +800,6 @@ class Line(origin_mixin(_states), sequence_ordered(), ModelSQL, ModelView): 'required': (Eval('party_required', False) & (Eval('statement_state') == 'draft')), } - t = cls.__table__() - cls._sql_constraints += [ - ('check_statement_line_amount', Check(t, t.amount != 0), - 'account_statement.msg_line_amount_non_zero'), - ] @classmethod def __register__(cls, module): @@ -821,6 +818,9 @@ class Line(origin_mixin(_states), sequence_ordered(), ModelSQL, ModelView): where=table.invoice != Null)) table_h.drop_column('invoice') + # Migration from 6.6: Allow amount of zero + table_h.drop_constraint('check_statement_line_amount') + @property @fields.depends('related_to') def invoice(self): @@ -1043,6 +1043,8 @@ class Line(origin_mixin(_states), sequence_ordered(), ModelSQL, ModelView): MoveLine = pool.get('account.move.line') Currency = Pool().get('currency.currency') zero = Decimal("0.0") + if not self.amount: + return with Transaction().set_context(date=self.date): amount = Currency.compute(self.statement.journal.currency, self.amount, self.statement.company.currency)