Skip to content

Commit cd301d0

Browse files
[MIG] account_journal_lock_date: Migration to 18.0
1 parent ca3af48 commit cd301d0

File tree

3 files changed

+28
-45
lines changed

3 files changed

+28
-45
lines changed

account_journal_lock_date/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Account Journal Lock Date",
66
"summary": "Lock each journal independently",
7-
"version": "17.0.1.0.0",
7+
"version": "18.0.1.0.0",
88
"license": "AGPL-3",
99
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
1010
"website": "https://github.com/OCA/account-financial-tools",

account_journal_lock_date/models/account_move.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
class AccountMove(models.Model):
1010
_inherit = "account.move"
1111

12-
def _check_fiscalyear_lock_date(self):
13-
res = super()._check_fiscalyear_lock_date()
12+
def _check_fiscal_lock_dates(self):
13+
res = super()._check_fiscal_lock_dates()
1414
if self.env.context.get("bypass_journal_lock_date"):
1515
return res
1616

1717
date_min = fields.date.min
1818
for move in self:
19-
if self.user_has_groups("account.group_account_manager"):
19+
if self.env.user.has_group("account.group_account_manager"):
2020
lock_date = move.journal_id.fiscalyear_lock_date or date_min
2121
else:
2222
lock_date = max(
@@ -25,7 +25,7 @@ def _check_fiscalyear_lock_date(self):
2525
)
2626
if move.date <= lock_date:
2727
lock_date = format_date(self.env, lock_date)
28-
if self.user_has_groups("account.group_account_manager"):
28+
if self.env.user.has_group("account.group_account_manager"):
2929
message = _(
3030
"You cannot add/modify entries for the journal '%(journal)s' "
3131
"prior to and inclusive of the lock date %(journal_date)s"

account_journal_lock_date/tests/test_journal_lock_date.py

+23-40
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,49 @@
44
from datetime import date, timedelta
55

66
from odoo.exceptions import UserError
7+
from odoo.fields import Command
78
from odoo.tests import tagged
89

910
from odoo.addons.account.tests import common
1011

1112

1213
@tagged("post_install", "-at_install")
1314
class TestJournalLockDate(common.AccountTestInvoicingCommon):
14-
def setUp(self):
15-
super().setUp()
16-
self.account_move_obj = self.env["account.move"]
17-
self.account_move_line_obj = self.env["account.move.line"]
18-
self.company_id = self.ref("base.main_company")
19-
self.partner = self.browse_ref("base.res_partner_12")
20-
21-
self.account = self.company_data["default_account_revenue"]
22-
self.account2 = self.company_data["default_account_expense"]
23-
self.journal = self.company_data["default_journal_bank"]
15+
@classmethod
16+
def setUpClass(cls):
17+
super().setUpClass()
18+
cls.account_move_obj = cls.env["account.move"]
19+
cls.account_move_line_obj = cls.env["account.move.line"]
20+
cls.account = cls.company_data["default_account_revenue"]
21+
cls.account2 = cls.company_data["default_account_expense"]
22+
cls.journal = cls.company_data["default_journal_bank"]
2423

2524
# create a move and post it
26-
self.move = self.account_move_obj.create(
25+
cls.move = cls.account_move_obj.create(
2726
{
2827
"date": date.today(),
29-
"journal_id": self.journal.id,
28+
"journal_id": cls.journal.id,
3029
"line_ids": [
31-
(
32-
0,
33-
0,
30+
Command.create(
3431
{
35-
"account_id": self.account.id,
32+
"account_id": cls.account.id,
3633
"credit": 1000.0,
3734
"name": "Credit line",
3835
},
3936
),
40-
(
41-
0,
42-
0,
37+
Command.create(
4338
{
44-
"account_id": self.account2.id,
39+
"account_id": cls.account2.id,
4540
"debit": 1000.0,
4641
"name": "Debit line",
4742
},
4843
),
4944
],
5045
}
5146
)
52-
self.move.action_post()
47+
cls.move.action_post()
5348
# lock journal, set 'Lock Date for Non-Advisers'
54-
self.journal.period_lock_date = date.today() + timedelta(days=2)
49+
cls.journal.period_lock_date = date.today() + timedelta(days=2)
5550

5651
def test_journal_lock_date(self):
5752
self.env.user.write({"groups_id": [(3, self.ref("base.group_system"))]})
@@ -77,18 +72,14 @@ def test_journal_lock_date(self):
7772
"date": self.journal.period_lock_date + timedelta(days=3),
7873
"journal_id": self.journal.id,
7974
"line_ids": [
80-
(
81-
0,
82-
0,
75+
Command.create(
8376
{
8477
"account_id": self.account.id,
8578
"credit": 1000.0,
8679
"name": "Credit line",
8780
},
8881
),
89-
(
90-
0,
91-
0,
82+
Command.create(
9283
{
9384
"account_id": self.account2.id,
9485
"debit": 1000.0,
@@ -108,18 +99,14 @@ def test_journal_lock_date(self):
10899
"date": self.journal.period_lock_date,
109100
"journal_id": self.journal.id,
110101
"line_ids": [
111-
(
112-
0,
113-
0,
102+
Command.create(
114103
{
115104
"account_id": self.account.id,
116105
"credit": 1000.0,
117106
"name": "Credit line",
118107
},
119108
),
120-
(
121-
0,
122-
0,
109+
Command.create(
123110
{
124111
"account_id": self.account2.id,
125112
"debit": 1000.0,
@@ -166,18 +153,14 @@ def test_journal_lock_date_adviser(self):
166153
"date": self.journal.period_lock_date,
167154
"journal_id": self.journal.id,
168155
"line_ids": [
169-
(
170-
0,
171-
0,
156+
Command.create(
172157
{
173158
"account_id": self.account.id,
174159
"credit": 1000.0,
175160
"name": "Credit line",
176161
},
177162
),
178-
(
179-
0,
180-
0,
163+
Command.create(
181164
{
182165
"account_id": self.account2.id,
183166
"debit": 1000.0,

0 commit comments

Comments
 (0)