Skip to Content
Menu
This question has been flagged
1 Reply
5032 Views

Hi everyone,

I have created a wizard (called bom_import_process), which shows the user some products (saved as a Many2many field) from which they can choose and, if the desired product does not exist, create a new one. The new product should be pre-filled with some defaults, that I wanted to pass in the context.

Therefore I have created a simple button in the wizard:

<button name="create_new_product" type="object"
            string="Create new product" class="oe_highlight" />

And wrote the corresponding create_new_product function in bom_import_process:

class bom_import_process(models.TransientModel):
    products = fields.Many2many('product.template', string="products")
    @api.multi
    def create_new_product(self):
        self.ensure_one()

        product_view = self.env.ref(
            'product.product_template_only_form_view',
            False
        )
        return {
            'name': _('Create a product'),
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'product.template',
            'view_id': product_view.id,
            'target': 'new',
            'context': # calculated context
        }

To complicate things a bit, bom_import_process is only created by a second wizard (bom_product_import_wizard) by returning a dict in the following way:

class bom_product_import_wizard(models.TransientModel):
    # fields omitted
    @api.multi
    def import_BOM(self):
    # some logic here, especially obtaining new_record & wizard_view
    return {
            'name': _('Import line'),
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'bom_import_process',
            'res_id': new_record.id,
            'view_id': wizard_view.id,
            'target': 'new',
            'nodestroy': True,
        }

Anyway, my problem is, that as soon as I press the button create_new_product, the correct view opens in a pop-up. But as soon as I click save on the product, the product creation window does not close. If I manually close it with the close button (in the top right corner) then I can no longer return to the wizard (which is bad, as it is a multi-step wizard).

Then I thought, maybe I should simply use the product creation form from the many2many field. I.e. I would pass a context with the defaults in the import_BOM function. But I was unable to make it propagate into the product creation dialog. Does anyone know which steps would be necessary for that?

Thanks in advance,

Dan
Avatar
Discard
Best Answer

Hi Dan,

I hope you solved this question at this point.

My suggestion here would be to create a function and pass it through the wizard, I did it on one level and it worked fine for me on V13.

Regards.

Avatar
Discard
Related Posts Replies Views Activity
3
Jul 24
29515
1
Dec 22
3219
1
Dec 21
5123
3
Dec 19
5697
3
Nov 23
32043