Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5035 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jul 24
29523
1
dic 22
3227
1
dic 21
5127
3
dic 19
5701
3
nov 23
32064