Maintainers
This module is maintained by the OCA.
-![Odoo Community Association](https://odoo-community.org/logo.png)
![Odoo Community Association](https://odoo-community.org/logo.png)
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
diff --git a/account_lock_to_date/wizards/account_update_lock_to_date.py b/account_lock_to_date/wizards/account_update_lock_to_date.py index 4f89c38025d..65f0e61f23b 100644 --- a/account_lock_to_date/wizards/account_update_lock_to_date.py +++ b/account_lock_to_date/wizards/account_update_lock_to_date.py @@ -1,6 +1,8 @@ # Copyright 2019 ForgeFlow S.L. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import datetime, timedelta + from odoo import SUPERUSER_ID, _, api, fields, models from odoo.exceptions import ValidationError @@ -27,6 +29,22 @@ class AccountUpdateLockToDate(models.TransientModel): "inclusive of this date. Use it for fiscal year locking for " "example.", ) + is_lock_to_date_periodic = fields.Boolean( + string="Express the interval as number of days.", + help="Express the interval as number of days.", + default=False, + ) + lock_to_date_periodicity_advisers = fields.Integer( + string="Periodicity for Advisers", + default="30", + help="Number of days after which all users, including advisers, " + "cannot write in accounting.", + ) + lock_to_date_periodicity = fields.Integer( + string="Periodicity for Non-Advisers", + default="15", + help="Number of days after which non-advisers cannot write in accounting.", + ) @api.model def default_get(self, field_list): @@ -35,8 +53,11 @@ def default_get(self, field_list): res.update( { "company_id": company.id, + "is_lock_to_date_periodic": company.is_lock_to_date_periodic, "period_lock_to_date": company.period_lock_to_date, "fiscalyear_lock_to_date": company.fiscalyear_lock_to_date, + "lock_to_date_periodicity_advisers": company.lock_to_date_periodicity_advisers, + "lock_to_date_periodicity": company.lock_to_date_periodicity, } ) return res @@ -50,9 +71,32 @@ def _check_execute_allowed(self): def execute(self): self.ensure_one() self._check_execute_allowed() - self.company_id.sudo().write( - { - "period_lock_to_date": self.period_lock_to_date, - "fiscalyear_lock_to_date": self.fiscalyear_lock_to_date, - } - ) + if self.is_lock_to_date_periodic: + if ( + not self.lock_to_date_periodicity_advisers + or not self.lock_to_date_periodicity + ): + raise ValidationError( + _("Please input a number of days for the lock to date.") + ) + self.company_id.sudo().write( + { + "is_lock_to_date_periodic": self.is_lock_to_date_periodic, + "lock_to_date_periodicity": self.lock_to_date_periodicity, + "lock_to_date_periodicity_advisers": self.lock_to_date_periodicity_advisers, + "period_lock_to_date": datetime.now().date() + + timedelta(days=self.lock_to_date_periodicity), + "fiscalyear_lock_to_date": datetime.now().date() + + timedelta(days=self.lock_to_date_periodicity_advisers), + } + ) + else: + self.company_id.sudo().write( + { + "is_lock_to_date_periodic": self.is_lock_to_date_periodic, + "lock_to_date_periodicity": self.lock_to_date_periodicity, + "lock_to_date_periodicity_advisers": self.lock_to_date_periodicity_advisers, + "period_lock_to_date": self.period_lock_to_date, + "fiscalyear_lock_to_date": self.fiscalyear_lock_to_date, + } + ) diff --git a/account_lock_to_date/wizards/account_update_lock_to_date.xml b/account_lock_to_date/wizards/account_update_lock_to_date.xml index 2d1e8086e2b..f16a2406d9b 100644 --- a/account_lock_to_date/wizards/account_update_lock_to_date.xml +++ b/account_lock_to_date/wizards/account_update_lock_to_date.xml @@ -15,8 +15,23 @@ options="{'no_create': True}" groups="base.group_multi_company" /> -