python - 我想根据选择字段填充 Many2one 字段
问题描述
我想根据选择字段填充客户/供应商 Many2one 字段,该字段有两个选择 1.Sale Order,2.Purchase Order。如果是销售订单,那么 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
解决方案
您从选择字段中获取 m2opurchase.order
和Now,交出 .xml 文件。在其中尝试隐藏/取消隐藏其他字段。现在从那个 m2o,您可以轻松地从客户/供应商那里获得过滤器。现在除此之外,如果您没有任何其他用途,只需使用“res.partner”的 m2o 并根据选择字段值在此字段上设置域。sale.order
attrs
sale.order
推荐阅读
- matlab - matlab中的MFCC代码
- reactjs - React, Apollo - 更新和移除突变问题
- python - get a value from another column if condition for this column is met
- javascript - JSON.parse() 从数组中排除点和小数
- mongodb - 如何在 MongoDB 中对嵌套日期范围内的值求和
- java - 如何在另一个类中使用静态类中的变量?
- node.js - docker compose networking with axios (node) error ENOTFOUND
- php - htaccess - 我更改 rewritebase 但仍需要 url 中的公用文件夹
- python - How to restart my game with user input of 'y'? Created a user defined function for after-game
- c++ - 用C++在txt文件中查找最长的单词