OdooTech notes

Simpler way to call wizard or form from button in Odoo (No action in xml)

odoo personalizzazioni

Simpler way to call wizard or form from button in Odoo (No action in xml)

Define the wizard in py:

class ProductWizard(models.TransientModel):
   _name = 'product.wizard'

   range_start = fields.Integer('range_start')
   range_end = fields.Integer('range_end')
   range_dist = fields.Char('range_dist')

   @api.multi
   def create_set(self):
      context = dict(self._context or {})
      raise UserError(_("TEST REPORT"))

and in xml:

<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="range_start" string="Range start from:"/>
      <field name="range_end" string="Range end:"/>
      <field name="range_dist" string="Size distribution:" placeholder="Es.: 1-1-2-2-2-2"/>
      </group>
   </group>
   <footer>
      <button name="create_set" string="Print" type="object" class="oe_highlight" />
      or
      <button string="Cancel" class="oe_link" special="cancel"/>
   </footer>
</form>
</field>
</record>

Define call in .py

@api.multi
def open_wizard(self):
   return {
   'view_type': 'form',
   'view_mode': 'form',
   'res_model': 'product.wizard',
   'target': 'new',
   'type': 'ir.actions.act_window',
   'context': {'current_id': self.id}
   }

Call it from button this way:

&lt;button name="open_wizard" string="My wiz" type="object" class="oe_highlight"/>

 

Comment here