Odoo – Link to a Wizard from a Menu item

There is case you want to show a form for users to input before processing some logic. So we need to let user access this form from a menu item.

Let’s say we want to add a menu as child of Sales > Orders.

XML

<odoo>
    <data>

        <record model="ir.ui.view" id="sample_data_form_view">
            <field name="name">wizard.sample.data.form</field>
            <field name="model">wizard.sample.data</field>
            <field name="arch" type="xml">
                <form string="Sample Data">
                    <group>
                        <field name="title"/>
                        <field name="date_from"/>
                    </group>
                    <footer>
                        <button name="update_action" type="object" string="Update" class="oe_highlight"/>
                        or
                        <button special="cancel" string="Cancel"/>
                    </footer>
                </form>
            </field>
        </record>

        <record id="act_sample_data" model="ir.actions.act_window">
            <field name="name">Sample Data</field>
            <field name="res_model">wizard.sample.data</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="sample_data_form_view"/>
        </record>

        <menuitem id="menu_sample_data" parent="sale.sale_order_menu" name="Sample Data" sequence="100"
                  action="act_sample_data"/>


    </data>
</odoo>

Wizard

class SampleWizard(models.TransientModel):
	_name = "wizard.sample.data"
	_description = "Sample Data"

	title = fields.Char(string='Title', required=True)
	date_from = fields.Date(string='Start Date', required=True, help='Start Date')

	@api.multi
	def update_action(self):
		# do something

If you want to open the wizard in a popup, use this in place of the report element which hasid="act_sample_data":

<record id="act_sample_data" model="ir.actions.act_window">
    <field name="name">Sample Data</field>
    <field name="res_model">wizard.sample.data</field>
    <field name="view_mode">form</field>
    <field name="view_id" ref="sample_data_form_view"/>
    <field name="target">new</field>
</record>

Leave a Comment

Your email address will not be published.