Using property (tryton 4.2) on domain field

64 views
Skip to first unread message

Maxime Richez

unread,
Jun 20, 2017, 9:31:59 AM6/20/17
to tryton-dev
Hi,

Here's my small problem in Tryton 4.2, i want to filter products on a specific product category. I define those category as a property in a configuration.

My code is here: https://pastebin.com/wDF8qGtX

So in my main class (PrinterModel), i define a function field on product category to get the default category stored in configuration... (printer_category).

This function field is used in my domain for the product to get only products from a specific category (and children too)  (printer_model field)

My code wasn't working until i define a default_printer_category... code is redundant but it's working.

My question: is it necessary to use a function field for the domain or can i evaluate a function in domain ? If not, how to avoid code redundancy for default_ method and get_ method for the function field ?
Is there a better way to implement this "filter" ? i'm looking for examples in code but unsuccessfully.

Thanks for help!


Cédric Krier

unread,
Jun 20, 2017, 10:25:06 AM6/20/17
to tryton-dev
On 2017-06-20 06:20, Maxime Richez wrote:
> Hi,
>
> Here's my small problem in Tryton 4.2, i want to filter products on a
> specific product category. I define those category as a property in a
> configuration.

Why using a Property field?

> My code is here: https://pastebin.com/wDF8qGtX
>
> So in my main class (PrinterModel), i define a function field on product
> category to get the default category stored in configuration...
> (printer_category).
>
> This function field is used in my domain for the product to get only
> products from a specific category (and children too) (printer_model field)
>
> My code wasn't working until i define a default_printer_category... code is
> redundant but it's working.
>
> My question: is it necessary to use a function field for the domain or can
> i evaluate a function in domain ?

Only field of a model can be evaluated by PYSON.
There is the PYSON.Id but it will require that you create the category
in XML.

> If not, how to avoid code redundancy for
> default_ method and get_ method for the function field ?

You can call the default_ method from the getter method.
But you need to have both because the getter will be called only once
the record is saved/created.

> Is there a better way to implement this "filter" ? i'm looking for examples
> in code but unsuccessfully.

I think the creation of categories from XML could be a good option.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Maxime Richez

unread,
Jun 20, 2017, 10:47:12 AM6/20/17
to tryton-dev


Why using a Property field?

The only way to store a value in configuration, no ? And it allows to choose an existing product category.
 
Only field of a model can be evaluated by PYSON.
There is the PYSON.Id but it will require that you create the category
in XML.
 
I'll try this. It seems easier and without property :-)
 

You can call the default_ method from the getter method.
But you need to have both because the getter will be called only once
the record is saved/created.

I didn't thought this way :-)


I think the creation of categories from XML could be a good option.

Indeed. Thanks for your help !

Sergi Almacellas Abellana

unread,
Jun 20, 2017, 10:50:31 AM6/20/17
to tryto...@googlegroups.com
I agree with Cedric here. Specially if you want to use it on a domain. Let me explain:

If you store it on the configuration, changing the value on the configuration may invalidate all the existing records domain. Creating a static category with xml records will prevent it.

--
Enviado desde mi dispositivo Android con K-9 Mail. Por favor, disculpa mi brevedad.

Cédric Krier

unread,
Jun 20, 2017, 10:55:07 AM6/20/17
to tryton-dev
On 2017-06-20 07:47, Maxime Richez wrote:
>
>
> >
> > Why using a Property field?
> >
> > The only way to store a value in configuration, no ? And it allows to
> choose an existing product category.

No, any field can be stored on configuration but usually it is a
Property/MultiValue because it depends on the company.

Maxime Richez

unread,
Jun 20, 2017, 11:01:24 AM6/20/17
to tryton-dev


I agree with Cedric here. Specially if you want to use it on a domain. Let me explain:

If you store it on the configuration, changing the value on the configuration may invalidate all the existing records domain. Creating a static category with xml records will prevent it.


But if i change the xml category on the product, problem will also be the same  (but with less impact, or i can prevent to change product category )?

Maxime Richez

unread,
Jun 20, 2017, 11:03:54 AM6/20/17
to tryton-dev

No, any field can be stored on configuration but usually it is a
Property/MultiValue because it depends on the company.

Ok, i didn't know , as you said, in the code, it's usually Property/Multivalue... 

Sergi Almacellas Abellana

unread,
Jun 20, 2017, 11:10:46 AM6/20/17
to tryto...@googlegroups.com
If you have a domain it can not be changed as the domain will ensure it.
Reply all
Reply to author
Forward
0 new messages