changeset 90cc8fdb0fd2 in modules/account_statement:default details: https://hg.tryton.org/modules/account_statement?cmd=changeset;node=90cc8fdb0fd2 description: Warn user when posting a statement with canceled or paid lines
issue9729 review329371002 diffstat: CHANGELOG | 1 + message.xml | 3 +++ statement.py | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletions(-) diffs (56 lines): diff -r 8d7e2b001590 -r 90cc8fdb0fd2 CHANGELOG --- a/CHANGELOG Tue Feb 09 00:32:17 2021 +0100 +++ b/CHANGELOG Fri Feb 12 20:20:09 2021 +0100 @@ -1,3 +1,4 @@ +* Warn user when posting a statement with cancelled or paid invoices * Fill move line's origin with statement line Version 5.8.0 - 2020-11-02 diff -r 8d7e2b001590 -r 90cc8fdb0fd2 message.xml --- a/message.xml Tue Feb 09 00:32:17 2021 +0100 +++ b/message.xml Fri Feb 12 20:20:09 2021 +0100 @@ -27,6 +27,9 @@ <record model="ir.message" id="msg_statement_delete_cancel"> <field name="text">To delete statement "%(statement)s" you must cancel it.</field> </record> + <record model="ir.message" id="msg_statement_invoice_paid_cancelled"> + <field name="text">The validation of the statements will remove already paid or cancelled invoices from the statements' lines.</field> + </record> <record model="ir.message" id="msg_statement_paid_invoice_draft"> <field name="text">The validation of the statements will remove paid invoices from other statements.</field> </record> diff -r 8d7e2b001590 -r 90cc8fdb0fd2 statement.py --- a/statement.py Tue Feb 09 00:32:17 2021 +0100 +++ b/statement.py Fri Feb 12 20:20:09 2021 +0100 @@ -1,5 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +import hashlib from decimal import Decimal from collections import namedtuple, defaultdict from itertools import groupby @@ -499,9 +500,23 @@ pool = Pool() Line = pool.get('account.statement.line') Warning = pool.get('res.user.warning') - + paid_cancelled_invoice_lines = [] for statement in statements: getattr(statement, 'validate_%s' % statement.validation)() + paid_cancelled_invoice_lines.extend(l for l in statement.lines + if l.invoice and l.invoice.state in {'cancelled', 'paid'}) + + if paid_cancelled_invoice_lines: + warning_key = ('%s.statement_paid_cancelled_invoice_lines' % + hashlib.md5(str(paid_cancelled_invoice_lines).encode( + 'utf-8')).hexdigest()) + if Warning.check(warning_key): + raise StatementValidateWarning(warning_key, + gettext('account_statement' + '.msg_statement_invoice_paid_cancelled')) + Line.write(paid_cancelled_invoice_lines, { + 'invoice': None, + }) cls.create_move(statements)