2017-08-17 13:10:25 +02:00
|
|
|
# Copyright 2017 ACSONE SA/NV
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2020-01-17 11:41:26 +01:00
|
|
|
from odoo import _, api, fields, models
|
2017-08-17 13:10:25 +02:00
|
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
|
|
|
|
|
|
class AccountUpdateLockDate(models.TransientModel):
|
2020-01-17 11:41:26 +01:00
|
|
|
_name = "account.update.lock_date"
|
|
|
|
_description = "Account Update Lock_date"
|
2017-08-17 13:10:25 +02:00
|
|
|
|
2020-01-17 11:41:26 +01:00
|
|
|
company_id = fields.Many2one(comodel_name="res.company", required=True)
|
2017-08-17 13:10:25 +02:00
|
|
|
period_lock_date = fields.Date(
|
|
|
|
string="Lock Date for Non-Advisers",
|
|
|
|
help="Only users with the 'Adviser' role can edit accounts prior to "
|
2020-01-17 11:41:26 +01:00
|
|
|
"and inclusive of this date. Use it for period locking inside an "
|
|
|
|
"open fiscal year, for example.",
|
|
|
|
)
|
2017-08-17 13:10:25 +02:00
|
|
|
fiscalyear_lock_date = fields.Date(
|
2021-11-18 19:14:45 +01:00
|
|
|
string="Lock Date for All Users",
|
2017-08-17 13:10:25 +02:00
|
|
|
help="No users, including Advisers, can edit accounts prior to and "
|
2020-01-17 11:41:26 +01:00
|
|
|
"inclusive of this date. Use it for fiscal year locking for "
|
|
|
|
"example.",
|
|
|
|
)
|
2021-11-18 19:14:45 +01:00
|
|
|
tax_lock_date = fields.Date(
|
|
|
|
string="Tax Lock Date",
|
|
|
|
help="No users can edit journal entries related to a tax prior and "
|
|
|
|
"inclusive of this date.",
|
|
|
|
)
|
2017-08-17 13:10:25 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def default_get(self, field_list):
|
2020-01-17 11:39:54 +01:00
|
|
|
res = super().default_get(field_list)
|
|
|
|
company = self.env.company
|
2020-01-17 11:41:26 +01:00
|
|
|
res.update(
|
|
|
|
{
|
|
|
|
"company_id": company.id,
|
|
|
|
"period_lock_date": company.period_lock_date,
|
|
|
|
"fiscalyear_lock_date": company.fiscalyear_lock_date,
|
2021-11-18 19:14:45 +01:00
|
|
|
"tax_lock_date": company.tax_lock_date,
|
2020-01-17 11:41:26 +01:00
|
|
|
}
|
|
|
|
)
|
2017-08-17 13:10:25 +02:00
|
|
|
return res
|
|
|
|
|
|
|
|
def _check_execute_allowed(self):
|
|
|
|
self.ensure_one()
|
2020-01-17 11:41:26 +01:00
|
|
|
has_adviser_group = self.env.user.has_group("account.group_account_manager")
|
2020-01-17 11:39:54 +01:00
|
|
|
if not (has_adviser_group or self.env.user._is_admin()):
|
2017-08-17 13:10:25 +02:00
|
|
|
raise UserError(_("You are not allowed to execute this action."))
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
self.ensure_one()
|
|
|
|
self._check_execute_allowed()
|
2020-01-17 11:41:26 +01:00
|
|
|
self.company_id.sudo().write(
|
|
|
|
{
|
|
|
|
"period_lock_date": self.period_lock_date,
|
|
|
|
"fiscalyear_lock_date": self.fiscalyear_lock_date,
|
2021-11-18 19:14:45 +01:00
|
|
|
"tax_lock_date": self.tax_lock_date,
|
2020-01-17 11:41:26 +01:00
|
|
|
}
|
|
|
|
)
|