Alternative solution deprecated onchange method in Odoo16

260 Views Asked by At

As the below code achieves the dynamic domain condition, this is what i want to achieve but this will get the Deprecation Warning in odoo v16, so if anybody knows the solutions that achieves similar functionality. Please comment it.

@api.onchange('customer', 'picking_type_code') 
def _onchange_customer(self):
    ​if self.picking_type_code == 'outgoing' and self.customer:
        return {'domain': {
            'move_ids.product_id': [
                ('picking_id.picking_type_code', '=', 'incoming'), 
                ('picking_id.customer', '=', self.customer)
            ]}
        }
    else: 
        ​return {'domain': {'move_ids.product_id': []}}

Actually i know this method is deprecated that's why i'm posting here to get the alternative methods that achieves similar solution

I have already tried web_domain_field but its not working since i need the dynamic domain inside the one2many field based on parent model fields value. I'm not able to achieve it through the compute field.

Mainly I'm not able to add the domain direct directly into the field since in the inventory module we use same Object relation in different Operation Types i.e., Incoming, outgoing,..

1

There are 1 best solutions below

6
On

The way I do it it's like it's described here in this comment of the PR that introduce the warning you are seeing:

https://github.com/odoo/odoo/pull/41918#issuecomment-824946980

But even if you see the warning the feature to return domains for onchange it's still there working.

The other thing that I have done to solve this it's to provide my own modified version of the onchange for some specific abstract models as mixin that needs some virtual fields based on the idea behind the new properties fields and make it work in Odoo 12.0 because I needed to load completely dynamic data according to dynamic rules and need to setup dynamic domains from this dynamic rules on the final loaded data records... pretty crazy thing that need crazy features