콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
6 답글
26353 화면

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?

관련 게시물 답글 화면 활동
0
8월 24
9076
1
12월 22
2649
1
9월 19
4434
0
3월 15
3655
7
3월 25
10874