我需要根据父表(purchase.order)中的值过滤采购订单行中的产品。
Purchase_order.py
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
product_variety_type = fields.Selection([('raw_material','Raw Material'),('stationary','Stationary')],string='Product Variety')
我已经在purchase.order.line
。py中定义了一个域名过滤器,需要再添加一个条件('variety','=',self._context.get('variety')
class PurchaseOrderLines(models.Model):
_inherit = 'purchase.order.line'
@api.onchange('product_id')
@api.depends('order_id')
def onchange_product_id2(self):
product_variety_type = self._context.get('variety') // Value is None
result = super(PurchaseOrderLines,self).onchange_product_id()
supplier_infos = self.env['product.supplierinfo'].search([('name', '=', self.partner_id.id)])
product_ids = self.env['product.product']
if not supplier_infos:
product_ids = product_ids.search([])
for supplier_info in supplier_infos:
product_ids += supplier_info.product_tmpl_id.product_variant_ids
result.update({'domain': {'product_id': [('id', 'in', product_ids.ids)]}})
return result
我尝试从父视图传递上下文值,但没有运气。
*。XML
<field name="partner_id" position="after">
<field name="product_variety_type" required="1" context="
{'variety':product_variety_type}"/>
</field>
我该怎么做?
答案 0 :(得分:1)
您不必使用context
。只需使用self.order_id
即可获得该值。
@api.onchange('product_id')
def onchange_product_id2(self):
product_variety_type = self.order_id.product_variety_type
# and so on