@@ -27,6 +27,22 @@ class FiscalDecoratorMixin(models.AbstractModel):
27
27
_fiscal_decorator_model = None
28
28
_fiscal_decorator_compute_blacklist = [] # conflicting computes to skip
29
29
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
+
30
46
@api .model
31
47
def _add_inherited_fields (self ):
32
48
"""
@@ -38,28 +54,27 @@ def _add_inherited_fields(self):
38
54
l10n_br_fiscal.document(.line).mixin.methods, we can preserve the compute
39
55
attribute except for compute in the _fiscal_decorator_compute_blacklist.
40
56
"""
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 ))
63
78
return super ()._add_inherited_fields ()
64
79
65
80
@api .model
0 commit comments