Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
26262 มุมมอง

Hi how can i use onchange to change the domain of an already existing field. For example, if i want to make it so that when i select a vendor to create a purchase order the list of products i can choose is restricted to those that share a value with the vendor

@api.onchange('partner_id')
def onchange_product_list(self):
return {'domain': {'product_id': [('partner_id.supplier_code', '=', 'self.sup_product_code')]}}

This is what i have so far

Using Odoo v11

อวตาร
ละทิ้ง

I'm facing the same issue but I couldn't understand the solution

How do you solve it?

คำตอบที่ดีที่สุด

Hello Leke,

Please try the following code in xml for product_id field 

inherit and update the existing domain

domain_new = old_domain + [('sup_product_code','=',parent.supplier_code)]

<field name="product_id' domain="domain_new"/>


before this add new field on Purchase Order supplier_code and update this field on partner onchange function.

อวตาร
ละทิ้ง

I couldn't understand,

In where we add this: domain_new = old_domain + [('sup_product_code','=',parent.supplier_code)]

Could you please explain more

Thanks in advance

คำตอบที่ดีที่สุด

Apply a domain to the field which is in the purchase.order.line as follows:

return {'domain': {'product_id': [('partner_id.supplier_code''='self.order_id.sup_product_code)]}}

* here order_id is just an example . You have to mention many2one field in purchase.order.line containing object purchace.order . 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Try this: 

return {'domain': {'product_id': [('partner_id.supplier_code', '=', self.sup_product_code)]}}

without quotes. I think everything else is correct

อวตาร
ละทิ้ง
ผู้เขียน

Hi Denis. My onchange method is in the purchase.order object however the field im trying to apply the domain to is in the purchase.order.line object how would i do this?

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ส.ค. 24
9017
1
ธ.ค. 22
2635
1
ก.ย. 19
4402
0
มี.ค. 15
3598
7
มี.ค. 25
10590