Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
3594 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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)

Tác giả Câu trả lời hay nhất

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..

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 23
1604
3
thg 10 23
4025
1
thg 3 19
5471
1
thg 1 24
1840
0
thg 4 23
2215