Warn user when posting a statement with canceled or paid lines

issue9729
review329371002
This commit is contained in:
Adrià Tarroja Caubet committed 2021-02-12 20:20:09 +01:00
1 parent 090ac206e3
commit 2ee5c0eb2b
3 files changed
+20 -1

No files matched your search

+1
View File
@@ -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
+3
View File
@@ -27,6 +27,9 @@ this repository contains the full copyright notices and license terms. -->
<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>
+16 -1
View File
@@ -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 @@ class Statement(Workflow, ModelSQL, ModelView):
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)