我要基于“选择”字段填充“客户/供应商Many2one”字段,该字段具有两个选择:“销售订单”,“ 2。购买订单”。如果是“销售订单”,则Many2one字段应具有“ sale.order”模型中的“客户”;如果是“采购订单”,则Many2one字段应具有“ purchase.order”模型中的“供应商”。
从odoo导入模型,字段,api,_
ProductRejection(models.Model)类:
_name = 'product.rejection'
pr_type_of_order = fields.Selection([('SO', 'Sale Order'), ('PO', 'Purchase Order')], string="Order Type")
pr_customer_name = fields.Many2one('sale.order',string="Vendor/Customer")
pr_order_no = fields.Many2one('sale.order',string="PO/SO No.")
pr_rejection_date = fields.Date("Date Of Rejection")
pr_product_name = fields.Many2one('product.product',string='Product Name')
pr_presentation = fields.Char("Presentation")
pr_reason = fields.Text("Reason Of Rejection")
pr_notes = fields.Text("Receiving Notes")
pr_status = fields.Selection([('new','New'),('confirm','Confirmed')],string="Status")
@api.onchange('pr_type_of_order')
def update_customer(self):
result = {}
if self.pr_type_of_order == 'SO':
sale_customer_obj = self.env['sale.order']
sale_customer_ids = sale_customer_obj.search(['partner_id'])
for record in sale_customer_ids:
cust_name = []
cust_name.append(record.id)
result = {'domain': {'pr_customer_name': [('id', 'in', cust_name)]}}
return result
else:
if self.pr_type_of_order == 'PO':
sale_customer_obj = self.env['purchase.order']
sale_customer_ids = sale_customer_obj.search(['partner_id'])
for record in sale_customer_ids:
cust_name1 = []
cust_name1.append(record.id)
result = {'domain': {'pr_customer_name': [('id', 'in', cust_name1)]}}
return result
答案 0 :(得分:0)
您获取purchase.order
和sale.order
的m2o现在在选择字段中,在.xml文件中提供attrs
。在其中尝试隐藏/取消隐藏其他字段。现在,从该m2o中,您可以轻松地从客户/供应商处获取过滤器。现在除此以外,如果您没有其他sale.order
用法,只需要m2o'res.partner'并根据选择字段值在该字段上设置域即可。