0
votes

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

1
Hello, can you try to put in the context this?: 'context': {'default_product_tmpl_id': id}dccdany
Thank you dccdany, that was the trick :) So there is one problem remaining: When ODOO opens the form, there is no "save" button. How can I implement this? When I am using the standard way to create a Variant there is a "save" buttonP. F. Brandl
Okay, ill add is as the answer then!dccdany
Thank you :) I also already found my other problem, mentioned in the comment 'flags': {'form': {'action_buttons': True}} will do the trickP. F. Brandl
Want me to add this somewhere?, be sure to put the answer as valid !dccdany

1 Answers

0
votes

You should add default before the field name in the context:

    'context': {'default_product_tmpl_id': id}