【发布时间】:2017-11-10 11:05:02
【问题描述】:
我创建了一个名为product.service.type 的新模型。然后,在product.product模型中,我还创建了一个Many2many字段(命名为service_type,指向product.service.type模型)。
现在我有了模型test,它有product_id 和service_type_id 字段,Many2one 分别指向product.product 和product.service.type。
我想要的是,如果您选择产品,服务类型域会更改为仅显示所选产品的服务类型。我通过onchange 管理了这个:
def onchange_product_id(self, cr, uid, ids, product_id, context=None):
if product_id:
product = self.pool.get('product.product').browse(
cr, uid, [product_id], context=context)
service_type_ids = product.service_type.mapped('id')
return {
'domain': {
'service_type_id': [('id', 'in', service_type_ids)],
},
}
这很好用,问题出在您正在编辑记录(而不是创建新记录)时,因为在这种情况下,onchange 没有被执行,因此域显示所有服务类型。
您可以在合作伙伴表单中看到相同的问题,字段为title。创建一个新的合作伙伴,它是一家公司,title 字段的域更改为只允许您选择像 Corp.、Ltd. 等记录,但如果您设置合作伙伴为联系人,您可以在Doctor、女士、Miss等记录中进行选择。现在,将合作伙伴与您想要的数据,然后转到顶部栏的其他菜单。返回合作伙伴表单并打开创建的合作伙伴进行编辑。检查title 字段而不更改is_company 字段。现在,尽管您的合作伙伴属于特定类别(公司或联系人),但您拥有所有可用的头衔。
我该如何解决这个问题?
【问题讨论】:
标签: python python-2.7 odoo-8 odoo