Message 66777

Author
ced
Date
2021-04-20.23:39:17
Message id
66777

Content

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:

@classmethod
def __setup__(cls):
        super().__setup__()
        field = getattr(cls, 'myfield')
        if isinstance(field, TemplateFunction):
            setattr(cls, 'myfield', field._field)
History
Date User Action Args
2021-04-20 23:39:18cedsetmessageid: <1618954757.997955.5ZDV6IOR5VNATCTG.issue10322@tryton.org>
2021-04-20 23:39:17cedlinkissue10322 messages
2021-04-20 23:39:17cedcreate

Showing 10 items. Show all history (warning: this could be VERY long)