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).
|
|
|
|
|
2022-11-25 17:57:35 +01:00
|
|
|
from odoo import _, fields, models
|
2021-03-09 16:53:35 +01:00
|
|
|
from odoo.exceptions import UserError
|
2020-10-08 01:58:13 +02:00
|
|
|
from odoo.tools.misc import format_date
|
2017-03-31 19:00:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AccountMove(models.Model):
|
|
|
|
|
2020-10-08 00:28:42 +02:00
|
|
|
_inherit = "account.move"
|
2017-03-31 19:00:59 +02:00
|
|
|
|
2020-10-08 01:58:13 +02:00
|
|
|
def _check_fiscalyear_lock_date(self):
|
|
|
|
res = super()._check_fiscalyear_lock_date()
|
2020-08-20 15:22:40 +02:00
|
|
|
if self.env.context.get("bypass_journal_lock_date"):
|
2017-03-31 19:00:59 +02:00
|
|
|
return res
|
2022-11-25 17:57:35 +01:00
|
|
|
|
|
|
|
date_min = fields.date.min
|
2017-03-31 19:00:59 +02:00
|
|
|
for move in self:
|
2020-10-08 00:28:42 +02:00
|
|
|
if self.user_has_groups("account.group_account_manager"):
|
2022-11-25 17:57:35 +01:00
|
|
|
lock_date = move.journal_id.fiscalyear_lock_date or date_min
|
2020-08-20 15:22:40 +02:00
|
|
|
else:
|
|
|
|
lock_date = max(
|
2022-11-25 17:57:35 +01:00
|
|
|
move.journal_id.period_lock_date or date_min,
|
|
|
|
move.journal_id.fiscalyear_lock_date or date_min,
|
2020-08-20 15:22:40 +02:00
|
|
|
)
|
|
|
|
if move.date <= lock_date:
|
2020-10-08 01:58:13 +02:00
|
|
|
lock_date = format_date(self.env, lock_date)
|
2020-10-08 00:28:42 +02:00
|
|
|
if self.user_has_groups("account.group_account_manager"):
|
2020-08-20 15:22:40 +02:00
|
|
|
message = _(
|
2022-05-18 17:46:08 +02:00
|
|
|
"You cannot add/modify entries for the journal '%(journal)s' "
|
|
|
|
"prior to and inclusive of the lock date %(journal_date)s"
|
|
|
|
) % {
|
|
|
|
"journal": move.journal_id.display_name,
|
|
|
|
"journal_date": lock_date,
|
|
|
|
}
|
2020-08-20 15:22:40 +02:00
|
|
|
else:
|
|
|
|
message = _(
|
2022-05-18 17:46:08 +02:00
|
|
|
"You cannot add/modify entries for the journal '%(journal)s' "
|
|
|
|
"prior to and inclusive of the lock date %(journal_date)s. "
|
2020-08-20 15:22:40 +02:00
|
|
|
"Check the Journal settings or ask someone "
|
|
|
|
"with the 'Adviser' role"
|
2022-05-18 17:46:08 +02:00
|
|
|
) % {
|
|
|
|
"journal": move.journal_id.display_name,
|
|
|
|
"journal_date": lock_date,
|
|
|
|
}
|
2021-03-09 16:53:35 +01:00
|
|
|
raise UserError(message)
|
2017-03-31 19:00:59 +02:00
|
|
|
return res
|