diff --git a/account_lock_to_date/README.rst b/account_lock_to_date/README.rst index edbeed48b58..8a06b7fcbaf 100644 --- a/account_lock_to_date/README.rst +++ b/account_lock_to_date/README.rst @@ -65,6 +65,7 @@ Authors ~~~~~~~ * ForgeFlow +* Innovyou Contributors ~~~~~~~~~~~~ diff --git a/account_lock_to_date/__manifest__.py b/account_lock_to_date/__manifest__.py index e662bbfa758..e37c167c138 100644 --- a/account_lock_to_date/__manifest__.py +++ b/account_lock_to_date/__manifest__.py @@ -1,19 +1,21 @@ # Copyright 2019 ForgeFlow S.L. # Copyright 2023 Simone Rubino - Aion Tech +# Copyright 2025 Innovyou # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Account Lock To Date", "summary": """ Allows to set an account lock date in the future.""", - "version": "16.0.1.0.0", + "version": "16.0.2.0.0", "license": "AGPL-3", - "author": "ForgeFlow, Odoo Community Association (OCA)", + "author": "ForgeFlow, Innovyou, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "installable": True, "depends": ["account"], "data": [ "security/ir.model.access.csv", "wizards/account_update_lock_to_date.xml", + "data/cron.xml", ], } diff --git a/account_lock_to_date/data/cron.xml b/account_lock_to_date/data/cron.xml new file mode 100644 index 00000000000..b1f9eb361f7 --- /dev/null +++ b/account_lock_to_date/data/cron.xml @@ -0,0 +1,13 @@ + + + Account Lock To Date Periodic + + code + model.update_lock_to_date_periodic() + 1 + days + -1 + False + True + + diff --git a/account_lock_to_date/models/res_company.py b/account_lock_to_date/models/res_company.py index 6adc757d1e4..2530a119fb6 100644 --- a/account_lock_to_date/models/res_company.py +++ b/account_lock_to_date/models/res_company.py @@ -27,6 +27,31 @@ class ResCompany(models.Model): help="No users, including Advisers, can edit accounts after " "this date. Use it for fiscal year locking for example.", ) + is_lock_to_date_periodic = fields.Boolean( + string="Lock Date Periodic", default=False + ) + lock_to_date_periodicity_advisers = fields.Integer( + string="Periodicity for Advisers", + default="15", + 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.", + ) + + def update_lock_to_date_periodic(self): + company_ids = self.env["res.company"].search([]) + for company in company_ids: + if company.is_lock_to_date_periodic: + company.fiscalyear_lock_to_date = datetime.now() + relativedelta( + days=company.lock_to_date_periodicity_advisers + 1 + ) + company.period_lock_to_date = datetime.now() + relativedelta( + days=company.lock_to_date_periodicity + 1 + ) def write(self, vals): # fiscalyear_lock_date can't be set to a prior date diff --git a/account_lock_to_date/static/description/index.html b/account_lock_to_date/static/description/index.html index c6732afad6f..099c778117b 100644 --- a/account_lock_to_date/static/description/index.html +++ b/account_lock_to_date/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -407,6 +408,7 @@

Credits

Authors

@@ -426,7 +428,9 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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" /> - - + + + + +