Reputation: 11
I am searching for a solution concerning the problem in the title. To be more specific: I can't use the provided "variants option" for products in ODOOv9. For me it is important that the product variants differ in specific fields. So this works already fine, but only with the relationship field (One2many)
Now I'd like to implement a user friendly button. When the user clicks this button he/she will get the "product.product" form to insert the variant fields. The problem is that the new "product.product" does not inherit the "product.template". Odoo creates always a new and empty "product.product" form.
I will provide you my code of XML and the .py
XML - in the product.template form:
<button string="Variante anlegen" type="object" name="insert_new_variant"
class="oe_highlight"/>
.py - in the inherited product.template class
@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
The button above calls this method. The right form is already displayed but not inherited with the "product.template" values.
It seems that the context attribute in the dict won't work. Can anybody please help me?
Thank you
Upvotes: 0
Views: 375
Reputation: 836
You should add default before the field name in the context:
'context': {'default_product_tmpl_id': id}
Upvotes: 0