2
0
account-financial-tools/account_journal_lock_date/models/account_move.py

39 lines
1.1 KiB
Python
Raw Normal View History

2017-03-31 19:00:59 +02:00
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, _
from ..exceptions import JournalLockDateError
class AccountMove(models.Model):
_inherit = 'account.move'
@api.model
def create(self, values):
move = super().create(values)
move._check_lock_date()
return move
@api.multi
def write(self, values):
self._check_lock_date()
res = super().write(values)
self._check_lock_date()
return res
2017-03-31 19:00:59 +02:00
@api.multi
def _check_lock_date(self):
res = super(AccountMove, self)._check_lock_date()
if self.env['account.journal']._can_bypass_journal_lock_date():
return res
for move in self:
lock_date = move.journal_id.journal_lock_date
if lock_date and move.date <= lock_date:
raise JournalLockDateError(
_("You cannot add/modify entries prior to and "
"inclusive of the journal lock date %s") %
(lock_date, ))
return res