Skip to content

Commit b4af7e6

Browse files
committed
[MIG] account_lock_date_update to v18
1 parent f892bb2 commit b4af7e6

File tree

7 files changed

+81
-45
lines changed

7 files changed

+81
-45
lines changed

account_lock_date_update/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"summary": """
77
Allow an Account adviser to update locking date without having
88
access to all technical settings""",
9-
"version": "17.0.1.0.1",
9+
"version": "18.0.1.0.0",
1010
"license": "AGPL-3",
1111
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
1212
"website": "https://github.com/OCA/account-financial-tools",
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Allow an Account adviser to update locking dates without having access
2-
to all technical settings.
1+
Allow an Account adviser to update accounting lock dates.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
To use this module, you need to be a Billing Administrator and go to:
22

3-
- Invoicing -\> Accounting -\> Actions -\> Update accounting lock dates
3+
- Invoicing -\> Accounting -\> Lock Dates
44
- Change values and click on **Update** button
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
22
access_account_update_lock_date_full,Full access on account.update.lock_date,model_account_update_lock_date,account.group_account_manager,1,1,1,1
3+
access_account_update_lock_date_readonly,Readonly access on account.update.lock_date to auditor,model_account_update_lock_date,account.group_account_readonly,1,0,0,0

account_lock_date_update/tests/test_account_lock_date_update.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2017 ACSONE SA/NV
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo import fields
4+
from odoo import Command, fields
55
from odoo.exceptions import AccessError
66
from odoo.tests.common import TransactionCase
77

@@ -26,33 +26,41 @@ def setUpClass(cls):
2626
cls.adviser_group = cls.env.ref("account.group_account_manager")
2727

2828
def test_01_update_without_access(self):
29-
self.demo_user.write({"groups_id": [(3, self.adviser_group.id)]})
29+
self.demo_user.write({"groups_id": [Command.unlink(self.adviser_group.id)]})
3030
with self.assertRaises(AccessError):
3131
self.env["account.update.lock_date"].with_user(self.demo_user.id).create(
3232
{"company_id": self.company.id}
3333
)
3434

3535
def test_02_update_with_access(self):
36-
self.demo_user.write({"groups_id": [(4, self.adviser_group.id)]})
36+
self.demo_user.write({"groups_id": [Command.link(self.adviser_group.id)]})
3737
wizard = (
3838
self.env["account.update.lock_date"]
3939
.with_user(self.demo_user.id)
4040
.create({"company_id": self.company.id})
4141
)
4242
wizard.write(
4343
{
44-
"period_lock_date": "2000-02-01",
45-
"fiscalyear_lock_date": "2000-01-01",
46-
"tax_lock_date": "2000-01-01",
44+
"sale_lock_date": "2000-05-01",
45+
"purchase_lock_date": "2000-04-01",
46+
"tax_lock_date": "2000-03-01",
47+
"fiscalyear_lock_date": "2000-02-01",
48+
"hard_lock_date": "2000-01-01",
4749
}
4850
)
4951
wizard.with_user(self.demo_user.id).execute()
5052
self.assertEqual(
51-
fields.Date.to_string(self.company.period_lock_date), "2000-02-01"
53+
fields.Date.to_string(self.company.sale_lock_date), "2000-05-01"
5254
)
5355
self.assertEqual(
54-
fields.Date.to_string(self.company.fiscalyear_lock_date), "2000-01-01"
56+
fields.Date.to_string(self.company.purchase_lock_date), "2000-04-01"
5557
)
5658
self.assertEqual(
57-
fields.Date.to_string(self.company.tax_lock_date), "2000-01-01"
59+
fields.Date.to_string(self.company.tax_lock_date), "2000-03-01"
60+
)
61+
self.assertEqual(
62+
fields.Date.to_string(self.company.fiscalyear_lock_date), "2000-02-01"
63+
)
64+
self.assertEqual(
65+
fields.Date.to_string(self.company.hard_lock_date), "2000-01-01"
5866
)

account_lock_date_update/wizards/account_update_lock_date.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,47 @@
33

44
from odoo import _, api, fields, models
55
from odoo.exceptions import UserError
6+
from odoo.tools.misc import format_date
7+
8+
from odoo.addons.account.models.company import LOCK_DATE_FIELDS
69

710

811
class AccountUpdateLockDate(models.TransientModel):
912
_name = "account.update.lock_date"
1013
_description = "Wizard to Update Accounting Lock Dates"
1114

1215
company_id = fields.Many2one(comodel_name="res.company", required=True)
13-
period_lock_date = fields.Date(
14-
string="Lock Date for Non-Advisers",
15-
help="Only users with the 'Adviser' role can edit accounts prior to "
16-
"and inclusive of this date. Use it for period locking inside an "
17-
"open fiscal year, for example.",
18-
)
1916
fiscalyear_lock_date = fields.Date(
20-
string="Lock Date for All Users",
21-
help="No users, including Advisers, can edit accounts prior to and "
22-
"inclusive of this date. Use it for fiscal year locking for "
23-
"example.",
17+
string="Global Lock Date",
18+
help="Impossible to edit/create journal entries prior to and "
19+
"inclusive of this date. Subject to exceptions.",
2420
)
2521
tax_lock_date = fields.Date(
26-
help="No users can edit journal entries related to a tax prior and "
27-
"inclusive of this date.",
22+
string="Tax Return Lock Date",
23+
help="Impossible to edit/create journal entries related to a tax prior and "
24+
"inclusive of this date. Subject to exceptions.",
25+
)
26+
sale_lock_date = fields.Date(
27+
help="Impossible to edit/create sale journal entries prior to and "
28+
"inclusive of this date. Subject to exceptions.",
29+
)
30+
purchase_lock_date = fields.Date(
31+
help="Impossible to edit/create purchase journal entries prior to and "
32+
"inclusive of this date. Subject to exceptions.",
33+
)
34+
hard_lock_date = fields.Date(
35+
help="Impossible to edit/create journal entries prior to and "
36+
"inclusive of this date. This lock date is irreversible and "
37+
"does not allow any exception.",
2838
)
2939

3040
@api.model
3141
def default_get(self, field_list):
3242
res = super().default_get(field_list)
3343
company = self.env.company
34-
res.update(
35-
{
36-
"company_id": company.id,
37-
"period_lock_date": company.period_lock_date,
38-
"fiscalyear_lock_date": company.fiscalyear_lock_date,
39-
"tax_lock_date": company.tax_lock_date,
40-
}
41-
)
44+
for lock_field in LOCK_DATE_FIELDS:
45+
res[lock_field] = company[lock_field]
46+
res["company_id"] = company.id
4247
return res
4348

4449
def _check_execute_allowed(self):
@@ -50,10 +55,28 @@ def _check_execute_allowed(self):
5055
def execute(self):
5156
self.ensure_one()
5257
self._check_execute_allowed()
53-
self.company_id.sudo().write(
54-
{
55-
"period_lock_date": self.period_lock_date,
56-
"fiscalyear_lock_date": self.fiscalyear_lock_date,
57-
"tax_lock_date": self.tax_lock_date,
58-
}
58+
today = fields.Date.context_today(self)
59+
fields_sr = (
60+
self.env["ir.model.fields"]
61+
.sudo()
62+
.search_read(
63+
[("model", "=", self._name), ("name", "in", LOCK_DATE_FIELDS)],
64+
["field_description", "name"],
65+
)
66+
)
67+
field2string = dict(
68+
(field["name"], field["field_description"]) for field in fields_sr
5969
)
70+
vals = {}
71+
for lock_field in LOCK_DATE_FIELDS:
72+
if self[lock_field] and self[lock_field] > today:
73+
raise UserError(
74+
_(
75+
"You tried to set %(field)s to %(date)s, "
76+
"but it is in the future.",
77+
field=field2string[lock_field],
78+
date=format_date(self.env, self[lock_field]),
79+
)
80+
)
81+
vals[lock_field] = self[lock_field]
82+
self.company_id.sudo().write(vals)

account_lock_date_update/wizards/account_update_lock_date.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,45 @@
1010
<field name="arch" type="xml">
1111
<form>
1212
<sheet>
13-
<group id="main">
13+
<group id="soft_lock_dates" string="Reversible Lock Dates">
1414
<field name="company_id" invisible="1" />
15-
<field name="tax_lock_date" options="{'warn_future': true}" />
15+
<field name="sale_lock_date" options="{'warn_future': true}" />
1616
<field
17-
name="period_lock_date"
17+
name="purchase_lock_date"
1818
options="{'warn_future': true}"
1919
/>
20+
<field name="tax_lock_date" options="{'warn_future': true}" />
2021
<field
2122
name="fiscalyear_lock_date"
2223
options="{'warn_future': true}"
2324
/>
2425
</group>
26+
<group id="hard_lock_dates" string="Irreversible Lock Date">
27+
<field name="hard_lock_date" options="{'warn_future': true}" />
28+
</group>
2529
</sheet>
2630
<footer>
2731
<button
2832
string="Update"
2933
name="execute"
3034
type="object"
3135
class="btn-primary"
36+
groups="account.group_account_manager"
3237
/>
3338
<button string="Cancel" class="btn-default" special="cancel" />
3439
</footer>
3540
</form>
3641
</field>
3742
</record>
3843
<record id="account_update_lock_date_act_window" model="ir.actions.act_window">
39-
<field name="name">Update Lock Dates</field>
44+
<field name="name">Lock Dates</field>
4045
<field name="res_model">account.update.lock_date</field>
4146
<field name="view_mode">form</field>
4247
<field name="target">new</field>
4348
</record>
4449
<record id="account_update_lock_date_menu" model="ir.ui.menu">
45-
<field name="name">Update Lock Dates</field>
46-
<field name="parent_id" ref="account.menu_finance_entries_actions" />
50+
<field name="name">Lock Dates</field>
51+
<field name="parent_id" ref="account.menu_finance_entries" />
4752
<field name="action" ref="account_update_lock_date_act_window" />
4853
<field name="sequence" eval="70" />
4954
</record>

0 commit comments

Comments
 (0)