How to override fields declared before any method class?

Hello, there is a field of

TYPES = [
(‘goods’, ‘Goods’),
(‘assets’, ‘Assets’),
(‘service’, ‘Service’),
]

that is declared as a class field, which is not defined within any models. I would like to understand on how to override this field and to add new values in, thanks!

Hello @Lucas welcome to the Tryton community

Goods, Assets and Service are part of Tryton business logic for this reason adding or making changes to these names can alter the operation of modules such as Sale, Purchase, Account_Assets among others.
These are modeled in the “class Template” in modules/product: 69fefe381c8a product.py using Fields — trytond latest documentation.

What would be the changes in concrete for Types?

Hello @Alnus, thanks for the reply. I was considering to add a 4th field so as to allow for any additional filler needed in the future.

Would this mean that I have to add the 4th entry in the
type = fields.Selection(TYPES, “Type”, required=True) by overriding it?

Hi, @Lucas, try this:

class Template(metaclass=PoolMeta):
name = “product.template”

@classmethod
def __setup__(cls):
    super().__setup__()
    for new_type in [
            ('new_item', 'New Item')]:
        if new_type not in cls.type.selection:
            cls.type.selection.append(new_type)
1 Like

Hello, @joseagrc

Thanks! It works.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.