Skip to content

Commit

Permalink
[IMP] account_lock_to_date: Added feature for updating the accounting…
Browse files Browse the repository at this point in the history
… block based on a number of days after today's date
  • Loading branch information
LorenzoC0 committed Jan 15, 2025
1 parent a8c69ea commit 8dabbc4
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 14 deletions.
1 change: 1 addition & 0 deletions account_lock_to_date/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Authors
~~~~~~~

* ForgeFlow
* Innovyou

Contributors
~~~~~~~~~~~~
Expand Down
6 changes: 4 additions & 2 deletions account_lock_to_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
],
}
13 changes: 13 additions & 0 deletions account_lock_to_date/data/cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<odoo>
<record id="ir_cron_account_lock_to_date_periodic" model="ir.cron">
<field name="name">Account Lock To Date Periodic</field>
<field name="model_id" ref="base.model_res_company" />
<field name="state">code</field>
<field name="code">model.update_lock_to_date_periodic()</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall">False</field>
<field name="active">True</field>
</record>
</odoo>
25 changes: 25 additions & 0 deletions account_lock_to_date/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([])

Check warning on line 46 in account_lock_to_date/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

account_lock_to_date/models/res_company.py#L46

Added line #L46 was not covered by tests
for company in company_ids:
if company.is_lock_to_date_periodic:
company.fiscalyear_lock_to_date = datetime.now() + relativedelta(

Check warning on line 49 in account_lock_to_date/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

account_lock_to_date/models/res_company.py#L49

Added line #L49 was not covered by tests
days=company.lock_to_date_periodicity_advisers + 1
)
company.period_lock_to_date = datetime.now() + relativedelta(

Check warning on line 52 in account_lock_to_date/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

account_lock_to_date/models/res_company.py#L52

Added line #L52 was not covered by tests
days=company.lock_to_date_periodicity + 1
)

def write(self, vals):
# fiscalyear_lock_date can't be set to a prior date
Expand Down
12 changes: 8 additions & 4 deletions account_lock_to_date/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -407,6 +408,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow</li>
<li>Innovyou</li>
</ul>
</div>
<div class="section" id="contributors">
Expand All @@ -426,7 +428,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
56 changes: 50 additions & 6 deletions account_lock_to_date/wizards/account_update_lock_to_date.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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(

Check warning on line 79 in account_lock_to_date/wizards/account_update_lock_to_date.py

View check run for this annotation

Codecov / codecov/patch

account_lock_to_date/wizards/account_update_lock_to_date.py#L79

Added line #L79 was not covered by tests
_("Please input a number of days for the lock to date.")
)
self.company_id.sudo().write(

Check warning on line 82 in account_lock_to_date/wizards/account_update_lock_to_date.py

View check run for this annotation

Codecov / codecov/patch

account_lock_to_date/wizards/account_update_lock_to_date.py#L82

Added line #L82 was not covered by tests
{
"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,
}
)
19 changes: 17 additions & 2 deletions account_lock_to_date/wizards/account_update_lock_to_date.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,23 @@
options="{'no_create': True}"
groups="base.group_multi_company"
/>
<field name="period_lock_to_date" />
<field name="fiscalyear_lock_to_date" />
<field name="is_lock_to_date_periodic" />
<field
name="lock_to_date_periodicity"
attrs="{'invisible': [('is_lock_to_date_periodic', '=', False)]}"
/>
<field
name="lock_to_date_periodicity_advisers"
attrs="{'invisible': [('is_lock_to_date_periodic', '=', False)]}"
/>
<field
name="period_lock_to_date"
attrs="{'invisible': [('is_lock_to_date_periodic', '=', True)]}"
/>
<field
name="fiscalyear_lock_to_date"
attrs="{'invisible': [('is_lock_to_date_periodic', '=', True)]}"
/>
</group>
</sheet>
<footer>
Expand Down

0 comments on commit 8dabbc4

Please sign in to comment.