How to overide the field property

48 views
Skip to first unread message

Markus Bala

unread,
Feb 2, 2016, 4:16:54 AM2/2/16
to tryton-dev
Hi All,

I had inherit 'stock.location', and add a new boolean field  called 'staging'.

I try to change the original 'storage.location' field as below:
    storage_location = fields.Many2One(
        "stock.location", "Storage", states={
            'invisible': Eval('type') != 'warehouse',
            'readonly': ~Eval('active'),
            'required': Eval('type') == 'warehouse',
        },
        domain=[
            ('type', 'in', ['storage', 'view']),('staging','=', False),
            ['OR',
                ('parent', 'child_of', [Eval('id')]),
                ('parent', '=', None)]],
        depends=['type', 'active', 'id'])

At the domain, I add ('staging','=',False). 
When I checked the result, seem like it do not override the field?

Please advice

Sergi Almacellas Abellana

unread,
Feb 2, 2016, 4:23:28 AM2/2/16
to tryto...@googlegroups.com
El 02/02/16 a les 10:16, Markus Bala ha escrit:
> Hi All,
>
> I had inherit 'stock.location', and add a new boolean field called
> 'staging'.
>
> I try to change the original 'storage.location' field as below:
> storage_location = fields.Many2One(
> "stock.location", "Storage", states={
> 'invisible': Eval('type') != 'warehouse',
> 'readonly': ~Eval('active'),
> 'required': Eval('type') == 'warehouse',
> },
> domain=[
> ('type', 'in', ['storage', 'view']),*('staging','=', False),*
> ['OR',
> ('parent', 'child_of', [Eval('id')]),
> ('parent', '=', None)]],
> depends=['type', 'active', 'id'])
>
> At the domain, I add ('staging','=',False).
> When I checked the result, seem like it do not override the field?

You should override the domain in the __setup__ method of your function.
Something like:

@classmethod
def __setup__(cls)
super(Class, cls).__setup__()
clause = ('staging', '=', False)
if clause not in cls.storage_location.domain:
cls.storage_location.domain.append(clause)

So this will modify the field when you module is loaded.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Markus Bala

unread,
Feb 2, 2016, 5:22:22 AM2/2/16
to tryton-dev
Hi Sergi,

You are really a savior. Thank you 

Cédric Krier

unread,
Feb 2, 2016, 5:30:03 AM2/2/16
to tryton-dev
On 2016-02-02 01:16, Markus Bala wrote:
> Hi All,
>
> I had inherit 'stock.location', and add a new boolean field called
> 'staging'.
>
> I try to change the original 'storage.location' field as below:
> storage_location = fields.Many2One(
> "stock.location", "Storage", states={
> 'invisible': Eval('type') != 'warehouse',
> 'readonly': ~Eval('active'),
> 'required': Eval('type') == 'warehouse',
> },
> domain=[
> ('type', 'in', ['storage', 'view']),*('staging','=', False),*
> ['OR',
> ('parent', 'child_of', [Eval('id')]),
> ('parent', '=', None)]],
> depends=['type', 'active', 'id'])
>
> At the domain, I add ('staging','=',False).
> When I checked the result, seem like it do not override the field?

It breaks compatibility to completely replace a field. You have to
customize the field in the __setup__ method.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages