changeset 06e865fb149c in modules/account_statement:default
details: 
https://hg.tryton.org/modules/account_statement?cmd=changeset;node=06e865fb149c
description:
        Prevent posting move from not posted statement

        issue8864
        review288581003
diffstat:

 CHANGELOG                            |   2 ++
 account.py                           |  18 ++++++++++++++++++
 message.xml                          |   3 +++
 statement.py                         |   3 ++-
 tests/scenario_account_statement.rst |   8 ++++++++
 5 files changed, 33 insertions(+), 1 deletions(-)

diffs (88 lines):

diff -r 4d122b7a7611 -r 06e865fb149c CHANGELOG
--- a/CHANGELOG Thu Dec 05 21:38:03 2019 +0100
+++ b/CHANGELOG Thu Dec 05 21:38:47 2019 +0100
@@ -1,3 +1,5 @@
+* Prevent posting move from statement that is not posted
+
 Version 5.4.0 - 2019-11-04
 * Bug fixes (see mercurial logs for details)
 * Require fresh session to post a statement
diff -r 4d122b7a7611 -r 06e865fb149c account.py
--- a/account.py        Thu Dec 05 21:38:03 2019 +0100
+++ b/account.py        Thu Dec 05 21:38:47 2019 +0100
@@ -5,10 +5,14 @@
 
 from sql.operators import Concat
 
+from trytond.i18n import gettext
+from trytond.model import ModelView
 from trytond.pool import PoolMeta, Pool
 from trytond.transaction import Transaction
 from trytond.tools import grouped_slice, reduce_ids
 
+from trytond.modules.account.exceptions import PostError
+
 __all__ = ['Journal', 'Move']
 
 
@@ -55,3 +59,17 @@
     @classmethod
     def _get_origin(cls):
         return super(Move, cls)._get_origin() + ['account.statement']
+
+    @classmethod
+    @ModelView.button
+    def post(cls, moves):
+        pool = Pool()
+        Statement = pool.get('account.statement')
+        for move in moves:
+            if (isinstance(move.origin, Statement)
+                    and move.origin.state != 'posted'):
+                raise PostError(
+                    gettext('account_statement.msg_post_statement_move',
+                        move=move.rec_name,
+                        statement=move.origin.rec_name))
+        super().post(moves)
diff -r 4d122b7a7611 -r 06e865fb149c message.xml
--- a/message.xml       Thu Dec 05 21:38:03 2019 +0100
+++ b/message.xml       Thu Dec 05 21:38:47 2019 +0100
@@ -36,5 +36,8 @@
         <record model="ir.message" id="msg_line_amount_non_zero">
             <field name="text">Statement line amount cannot be zero.</field>
         </record>
+        <record model="ir.message" id="msg_post_statement_move">
+            <field name="text">To post the move "%(move)s" you must post the 
statement "%(statement)s".</field>
+        </record>
     </data>
 </tryton>
diff -r 4d122b7a7611 -r 06e865fb149c statement.py
--- a/statement.py      Thu Dec 05 21:38:03 2019 +0100
+++ b/statement.py      Thu Dec 05 21:38:47 2019 +0100
@@ -629,7 +629,8 @@
                             statement=statement.rec_name,
                             amount=amount,
                             origin=origin.rec_name))
-
+        # Write state to skip statement test on Move.post
+        cls.write(statements, {'state': 'posted'})
         lines = [l for s in statements for l in s.lines]
         StatementLine.post_move(lines)
 
diff -r 4d122b7a7611 -r 06e865fb149c tests/scenario_account_statement.rst
--- a/tests/scenario_account_statement.rst      Thu Dec 05 21:38:03 2019 +0100
+++ b/tests/scenario_account_statement.rst      Thu Dec 05 21:38:47 2019 +0100
@@ -209,6 +209,14 @@
     >>> statement.state
     'validated'
 
+Try posting a move::
+
+    >>> statement_line = statement.lines[0]
+    >>> statement_line.move.click('post')  # doctest: +IGNORE_EXCEPTION_DETAIL
+    Traceback (most recent call last):
+        ...
+    trytond.modules.account.exceptions.PostError: ...
+
 Cancel statement::
 
     >>> statement.click('cancel')

Reply via email to