Creating and opening a wizard from button in odoo
Define wizard in .py:
class ProductWizard(models.TransientModel):
_name = 'product.wizard'
date_from = fields.Date(string='From')
date_to = fields.Date(string='To')
@api.multi
def test_report(self):
context = dict(self._context or {})
raise UserError(_("TEST REPORT"))
Define action e view in .xml:
<record id="action_open_wizard" model="ir.actions.act_window">
<field name="name">View Product Wizard</field>
<field name="res_model">product.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_test_report_wizard"/>
<field name="target">new</field>
</record>
<record id="view_test_report_wizard" model="ir.ui.view">
<field name="name">Product Wizard</field>
<field name="model">product.wizard</field>
<field name="arch" type="xml">
<form string="Choose The Details">
<group>
<group>
<field name="date_from" />
<field name="date_to"/>
</group>
</group>
<footer>
<button name="test_report" string="Print" type="object" class="oe_highlight" />
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
Call for action in XML: