Skip to content

Commit fc28b48

Browse files
committed
[FIX] l10n_br_account: Related fields inherited from the fiscal model
1 parent f4c1443 commit fc28b48

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

l10n_br_account/models/fiscal_decorator_mixin.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ class FiscalDecoratorMixin(models.AbstractModel):
2727
_fiscal_decorator_model = None
2828
_fiscal_decorator_compute_blacklist = [] # conflicting computes to skip
2929

30+
@api.model
31+
def _get_inheritable_fields(self):
32+
"""
33+
Return fields from base models (with and without '.mixin')
34+
for fiscal inheritance.
35+
"""
36+
fields = []
37+
base_models = [
38+
f"{self._fiscal_decorator_model}.mixin",
39+
self._fiscal_decorator_model,
40+
]
41+
for model in base_models:
42+
if model in self.env.registry:
43+
fields.extend(self.env.registry[model]._fields.items())
44+
return fields
45+
3046
@api.model
3147
def _add_inherited_fields(self):
3248
"""
@@ -38,28 +54,27 @@ def _add_inherited_fields(self):
3854
l10n_br_fiscal.document(.line).mixin.methods, we can preserve the compute
3955
attribute except for compute in the _fiscal_decorator_compute_blacklist.
4056
"""
41-
if self._fiscal_decorator_model is not None:
42-
for name, field in self.env.registry[
43-
f"{self._fiscal_decorator_model}.mixin"
44-
]._fields.items():
45-
field_cls = type(field)
46-
if (
47-
name in self._fields
48-
or field_cls in [fields.One2many, fields.Many2many]
49-
or not (field.compute or field.related)
50-
or (field.compute and field.store)
51-
or field.compute in self._fiscal_decorator_compute_blacklist
52-
):
53-
continue
54-
self._add_field(
55-
name,
56-
field_cls(
57-
related=field.related,
58-
compute=field.compute,
59-
inverse=field.inverse,
60-
comodel_name=field.comodel_name,
61-
),
62-
)
57+
if self._fiscal_decorator_model is None:
58+
return super()._add_inherited_fields()
59+
for name, field in self._get_inheritable_fields():
60+
field_cls = type(field)
61+
if (
62+
name in self._fields
63+
or field_cls in [fields.One2many, fields.Many2many]
64+
or not (field.compute or field.related)
65+
or (field.compute and field.store)
66+
or field.compute in self._fiscal_decorator_compute_blacklist
67+
):
68+
continue
69+
field_kwargs = {
70+
"related": field.related,
71+
"compute": field.compute,
72+
"inverse": field.inverse,
73+
"comodel_name": getattr(field, "comodel_name", None),
74+
}
75+
if isinstance(field, fields.Selection):
76+
field_kwargs["selection"] = field.selection
77+
self._add_field(name, field_cls(**field_kwargs))
6378
return super()._add_inherited_fields()
6479

6580
@api.model

0 commit comments

Comments
 (0)