Add again the function "check_modify" in the account.move.line module.

Prepare the function delete to only delte when the account.move.line move is not posted.

Task #158863
This commit is contained in:
Juanjo Garcia 2023-05-18 15:50:24 +02:00
parent 7a90745971
commit 43245fd3df

View file

@ -7,6 +7,7 @@ from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, Bool from trytond.pyson import Eval, Bool
from trytond.i18n import gettext from trytond.i18n import gettext
from trytond.exceptions import UserError from trytond.exceptions import UserError
from trytond.model.exceptions import AccessError
__all__ = ['Configuration', 'Account', 'Move', 'MoveLine'] __all__ = ['Configuration', 'Account', 'Move', 'MoveLine']
@ -178,6 +179,16 @@ class Move(metaclass=PoolMeta):
class MoveLine(metaclass=PoolMeta): class MoveLine(metaclass=PoolMeta):
__name__ = 'account.move.line' __name__ = 'account.move.line'
@classmethod
def check_modify(cls, lines, modified_fields=None):
'''
Check if the lines can be modified
'''
if modified_fields is None:
return
super(MoveLine, cls).check_modify(lines, modified_fields)
@classmethod @classmethod
def validate(cls, lines): def validate(cls, lines):
super(MoveLine, cls).validate(lines) super(MoveLine, cls).validate(lines)
@ -245,6 +256,14 @@ class MoveLine(metaclass=PoolMeta):
AnalyticLine.write(todraft_lines, { AnalyticLine.write(todraft_lines, {
'state': 'draft', 'state': 'draft',
}) })
for line in lines:
if line.move.state == 'posted':
raise AccessError(gettext(
'account.msg_modify_line_posted_move',
line=line.rec_name,
move=line.move.rec_name,
))
super(MoveLine, cls).delete(lines) super(MoveLine, cls).delete(lines)
@dualmethod @dualmethod