Přejít na obsah
Menu
You need to be registered to interact with the community.
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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit

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)

Autor Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
pro 23
1477
3
říj 23
3835
1
bře 19
5400
1
led 24
1723
0
dub 23
2089