[英]How to filter one Many2one field based on value of another in odoo
我的模型中包含以下字段:
seller = fields.Many2one('res.partner', string="Select Seller",domain="[('supplier','=',True)]")
products= fields.Many2one('product.template', string="Select Product" )
現在,我需要在用戶選擇賣方時過濾第二個字段(第一個字段)如何設置域名變更。
我正在嘗試做類似的事情,
@api.onchange('seller')
def onchange_field_seller(self):
res = {}
if self.seller:
# return {'domain':{'product':[//what do i add here//]}}
return res
我正在使用many2many字段在賣方創建表單中創建產品。
product_details = fields.Many2many('product.template',string="Products")
(請注意,此字段的表單與上面問題中的表單不同)。 我只想獲取創建賣方條目時創建的產品條目。我真的很困惑,我該如何做到這一點?
在您的情況下,您不能使用“動態”域,而可以在產品ID上使用更多的預定義域。
@api.onchange('seller')
def onchange_field_seller(self):
if self.seller:
# filter products by seller
product_ids = self.seller.product_details.ids
return {'domain': {'product': [('id', 'in', product_ids)]}}
else:
# filter all products -> remove domain
return {'domain': {'product': []}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.