我正在寻找有关 Headers 中问题的解决方案 . 更具体一点:我不能在ODOOv9中为产品使用提供的“变体选项” . 对我来说,重要的是产品变体在特定领域有所不同 . 所以这个工作已经很好了,但只有关系领域(One2many)
现在我想实现一个用户友好的按钮 . 当用户单击此按钮时,他/她将获得"product.product"表单以插入变体字段 . 问题是新的"product.product"没有继承"product.template" . Odoo总是创造一个新的空的"product.product"形式 .
我将为您提供XML和.py的代码
XML - 以product.template形式:
<button string="Variante anlegen" type="object" name="insert_new_variant"
class="oe_highlight"/>
.py - 在继承的product.template类中
@api.multi
def insert_new_variant(self):
id = self.id
view_ref = self.env['ir.model.data'].get_object_reference('product', 'product_normal_form_view')
view_id = view_ref[1] if view_ref else False
res = {
'type': 'ir.actions.act_window',
'name': ('product.product.form'),
'res_model': 'product.product',
'view_type': 'form',
'view_mode': 'form',
'view_id': view_id,
'target': 'new',
'context': {'product_tmpl_id': id}
}
return res
上面的按钮调用此方法 . 右侧表单已显示但未使用"product.template"值继承 .
似乎dict中的context属性不起作用 . 有人可以帮帮我吗?
谢谢
1 回答
您应该在上下文中的字段名称前添加默认值: