Hi,
how could I modify the Product class such that I can set an arbitrary name without it getting named by its template?
Yes, you can! All product fields that are defined on the template are function fields.
You can override its getter and setter to use a diferent value than the one from the template.
Thanks. I tried the approach below, but I think I am still missing something, as it does not work.
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
@classmethod
def set_name(cls, instances, name, value):
for instance in instances:
setattr(instance, name, value)
For context: I want to be able to just fill in the name field from the client and do something like this with proteus:
product = Product(template=template)
product.name = "some_different_name"
product.save()
You can redefine any field from the template on the product but be aware of Not possible to redefine product field (#10322) · Issues · Tryton / Tryton · GitLab
But from your example, I do not understand what you try to achieve.
I basically just want to completely decouple the template name and the variant name, because of our internal naming schemes.
I tried the approach from the above link by extending the setup method with:
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
@classmethod
def __setup__(cls):
super(Product, cls).__setup__()
field = getattr(cls, 'name')
if isinstance(field, fields.Function):
field = deepcopy(field._field)
field.readonly = False
setattr(cls, 'name', field)
but now I get an error that the field is missing:
/database.py", line 71, in execute
cursor.execute(self, sql, args)
psycopg2.errors.UndefinedColumn: column a.name does not exist
LINE 1: SELECT “a”.“attributes” AS “attributes”, “a”.“name” AS "name…
As you add a new column to the table, you must update the database.
Thank you! Everything works now
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.