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. Required fields are marked *

We care about your privacy and data security. Google serves cookies to analyse traffic and show ads on this site. By using this site you agree to these cookies being set. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close