Prevent posting move from not posted statement
issue8864 review288581003
This commit is contained in:
1 parent
50dca17a4d
commit
49a5b37d97
5 files changed
+33
-1
No files matched your search
@@ -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
|
||||
|
||||
+18
@@ -5,10 +5,14 @@ from operator import itemgetter
|
||||
|
||||
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 @@ class Move(metaclass=PoolMeta):
|
||||
@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)
|
||||
@@ -36,5 +36,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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>
|
||||
+2
-1
@@ -629,7 +629,8 @@ class Statement(Workflow, ModelSQL, ModelView):
|
||||
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)
|
||||
|
||||
|
||||
@@ -209,6 +209,14 @@ Validate statement::
|
||||
>>> 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')
|
||||
|
||||
Reference in new issue
Block a user