Skip to content

Commit 7a31fa5

Browse files
committed
[IMP] account_ux: field is_monetary computed
- Convert is_monetary from a regular boolean field to a computed stored field - Automatically compute value based on account_type instead of setting it manually - Remove unnecessary post-installation hook as the computation is now automatic - Clean up unused code in chart template loading
1 parent 3f80456 commit 7a31fa5

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

account_ux/models/account_account.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
class AccountAccount(models.Model):
99
_inherit = "account.account"
1010

11-
is_monetary = fields.Boolean(default=True)
11+
is_monetary = fields.Boolean(
12+
store=True,
13+
compute="_compute_is_monetary",
14+
readonly=False,
15+
)
1216

13-
@api.model
14-
def set_non_monetary(self, company):
17+
@api.depends("account_type")
18+
def _compute_is_monetary(self):
1519
"""Set is_monetary in False to the corresponding accounts taking into account the account type"""
1620
account_types = [
1721
"asset_non_current",
@@ -26,8 +30,8 @@ def set_non_monetary(self, company):
2630
"expense_direct_cost",
2731
"off_balance",
2832
]
29-
if accounts := self.search(
30-
[("account_type", "in", account_types), *self.env["account.account"]._check_company_domain(company)]
31-
).filtered(lambda x: x.company_fiscal_country_code == "AR"):
32-
accounts.write({"is_monetary": False})
33-
_logger.info("Is Monetary is False on %s accounts ." % (company.name))
33+
for rec in self:
34+
if rec.account_type in account_types:
35+
rec.is_monetary = False
36+
else:
37+
rec.is_monetary = True

account_ux/models/account_chart_template.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
class AccountChartTemplate(models.AbstractModel):
55
_inherit = "account.chart.template"
66

7-
def _load(self, template_code, company, install_demo, force_create=True):
8-
res = super()._load(template_code, company, install_demo, force_create)
9-
return res
10-
11-
def _load_data(self, data, ignore_duplicates=False):
12-
res = super()._load_data(data, ignore_duplicates=ignore_duplicates)
13-
if res.get("res.company"):
14-
self.env["account.account"].set_non_monetary(res["res.company"])
15-
return res
16-
177
def _post_load_data(self, template_code, company, template_data):
188
super()._post_load_data(template_code, company, template_data)
199

0 commit comments

Comments
 (0)