Created on 2021-04-20.23:39:17 by ced, last changed 9 months ago by ced.
The idea of the
Product.__setup__ is to create a function field for template field only if the field is not already defined on product.
The problem is the
Model.__setup__ makes a copy of the initial field from the first class in
So if a module define a field in Template (and so a Function field is added to Product), a sub-module can not redefine this field because it is always replaced by the first one. At least when
trytond is updating database otherwise the
__setup__ is called only once and so there is no time where
__setup__ is called between the first and second module.
A temporary solution is to add such code at the end of
__setup__ of the redefining field module:
@classmethod def __setup__(cls): super().__setup__() field = getattr(cls, 'myfield') if isinstance(field, TemplateFunction): setattr(cls, 'myfield', field._field)