Friday 1 September 2023

How to open wizard from action in Odoo

 In Odoo, to open a wizard from an action, you need to define and configure the action correctly.

Follow the steps:

1) Create Wizard Model

class MyCustomWizard(models.TransientModel): _name = 'my.custom.wizard' _description = 'My Custom Wizard Description'

# Define fields for your wizard here product_id = fields.Many2many('product.product', string='Product') product_old_price = fields.Float(string='Product Old Price') internal_ref = fields.Char(string='Product')

2) Create Wizard View

<record id="wizard_id" model="ir.ui.view">
<field name="name">confirm.wizard.form</field>
<field name="model">my.custom.wizard</field>
<field name="arch" type="xml">
<form>
               # Define fields for your wizard here
        </form>
</field>
</record>

3) Create Server action from where you need to define action


<record id="custom_product_action_server" model="ir.actions.server">
<field name="name">Open Wizard</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="product.model_product_product"/>
<field name="binding_model_id" ref="product.model_product_product"/>
<field name="state">code</field>
<field name="code">
action = model.action_open_wizard()
</field>
</record>

4) Now Define server action function in Model
def action_open_wizard(self):
product_product_ids = self.env['product.product'].browse(self._context.get('active_ids', False))
lines = []
    # This is sample code you may change your code as per your requirements
    #You need to add one2many field like line_ids in your wizard and then when you select multiple product
    #from product.product and open wizard then you may see all selected lines display in your wizard one2many
for product in product_product_ids:
vals = (0, 0, {
'product_id': product.id,
'product_old_price': product.lst_price,
'internal_ref': product.default_code,
})
lines.append(vals)
return {'type': 'ir.actions.act_window',
'name': _('Product Wizard'),
'res_model': 'my.confirm.wizard',
'target': 'new',
'view_id': self.env.ref('module_name.wizard_id').id,
'view_mode': 'form',
'context': {'default_line_ids': lines}
}

Odoo 17 New Features

  Odoo 17 new Features 1) Duplicate  multiple records from List view. Please have look below screenshots first you need to select records th...