Filling a selection field based on value of another instance field.

24 views
Skip to first unread message

Steven Lightfoot

unread,
Mar 5, 2018, 9:05:09 AM3/5/18
to tryton
Hi

What is the easiest way of filling a selection field dynamically? I need to fill it based on a custom product class that has a description and up to 8 can sizes (different products will have different available can sizes)

Using a classmethod function does not give me the access to the instance values so I assume that a function field is the way to go but the only examples I can see using a function field is to set a value from a predefined list.

Should I be going down the route of using One2Many, Many2one fields?

No idea if this makes sense or not :-)

If not then I will go forth back to the shadows from whence I came!!!!

Cédric Krier

unread,
Mar 5, 2018, 9:30:06 AM3/5/18
to tryton
On 2018-03-05 05:51, Steven Lightfoot wrote:
> What is the easiest way of filling a selection field dynamically? I need to fill it based on a custom product class that has a description and up to 8 can sizes (different products will have different available can sizes)
>
> Using a classmethod function does not give me the access to the instance values

So use an instance method decorated with fields.depends:
http://doc.tryton.org/4.6/trytond/doc/ref/models/fields.html#trytond.model.fields.Selection.selection


> so I assume that a function field is the way to go but the only examples I can see using a function field is to set a value from a predefined list.

Function field works the same way as standard field.

> Should I be going down the route of using One2Many, Many2one fields?

It is also an option, it depends of the schema.


But did you considered to use the product_attribute ? It seems to be
exactly the solution to your "product class".
--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Steven Lightfoot

unread,
Mar 5, 2018, 11:20:07 AM3/5/18
to tryton
Thank you cedric, I had not considered the product_attribute. I will have another look.

Much appreciated.
Reply all
Reply to author
Forward
0 new messages