Not possible to redefine product field
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 __mro__
.
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:
from copy import deepcopy
@classmethod
def __setup__(cls):
super().__setup__()
field = getattr(cls, 'myfield')
if isinstance(field, TemplateFunction):
field = deepcopy(field._field)
field.readonly = False
setattr(cls, 'myfield', field)