Skip to Content
Menu
This question has been flagged

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': []}}

Avatar
Discard
Best Answer

Hi,

Returning a domain using onchange method has been deprecated from Odoo 14.The standard solution is to use fields domain parameter.You can also use the custom module from OCA https://odoo-community.org/shop/web-domain-field-4368#attr=22677



Avatar
Discard
Best Answer

Hi Srushti


Instead of using Ochange method and returning domain in the return of the method, you should use _search() method of odoo base.


As you want the domain on move_ids which means the comodel ins "stock.move" so in that model you inherit the _search() method and this method contains serveral parameters and you should pass your domain in check below example : 

Please find code example in comment. 

I hope this will help you. 

Thanks & Regards,
Email:   odoo@aktivsoftware.com      

Skype: kalpeshmaheshwari

Avatar
Discard

Please find code example here :-

@api.model
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
if self.picking_type_code == 'outgoing' and self.customer:
args = [(Your if condition domain)]
else:
args = [(Your else condition domain)]

return super(SaleOrder, self)._search(args, offset=0, limit=None, order=None, count=False,
access_rights_uid=None)

Author Best Answer

Thanks Kiran for the answer.

I solved that using the compute method , Actually I have tried copute method before also but i was getting some issues, I troubleshoot it. Just with same logic just change method to compute and use @api.depends. Asssigned the values which i'm returning here using domain to a many2many field and then added that fields inside the domain attribute for product_id and lot_number field definition. This will work..

Avatar
Discard
Best Answer

Hi  Srushti,

Returning the domain using the onchange method is deprecated.

Check this method,

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

Hope it helps,
Kiran K

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
1452
3
Oct 23
3806
1
Mar 19
5371
1
Jan 24
1689
0
Apr 23
2066