forked from OCA/account-financial-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount_journal.py
45 lines (39 loc) · 1.53 KB
/
account_journal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo.tools import config
class AccountJournal(models.Model):
_inherit = "account.journal"
restrict_mode_hash_table = fields.Boolean(
compute="_compute_restrict_mode_hash_table", store=True, readonly=True
)
@api.constrains("restrict_mode_hash_table", "type")
def _check_journal_restrict_mode(self):
test_condition = not config["test_enable"] or (
config["test_enable"]
and self.env.context.get("test_account_journal_restrict_mode")
)
if not test_condition:
return
for rec in self:
if not rec.restrict_mode_hash_table and rec.type in [
"sale",
"purchase",
"general",
]:
raise UserError(
self.env._("Journal %s must have Lock Posted Entries enabled.")
% rec.name
)
@api.depends("type")
def _compute_restrict_mode_hash_table(self):
test_condition = not config["test_enable"] or (
config["test_enable"]
and self.env.context.get("test_account_journal_restrict_mode")
)
for rec in self:
if not test_condition:
rec.restrict_mode_hash_table = False
continue
rec.restrict_mode_hash_table = rec.type in ["sale", "purchase", "general"]