Skip to Content
Menu
This question has been flagged
2 Replies
17618 Views

Hi

I'm stuck, I tried every example I found, but somehow it still doesn't work. I'd like to open a new view from a button in the statusbar. Here are my two approaches.

I'm extending sale_order, file: sale_order.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record
model="ir.ui.view" id="view_sale_order_form_wizard">
<field
name="name">sale.order.form</field>
<field
name="model">sale.order</field>
<field
name="inherit_id" ref="sale.view_order_form" />
<field
name="arch" type="xml">
<header>
<button
type='action' name='%(custom_wizard_ext_view)d' string="Button A" />
<button
type='object' name='open_wizard' string="Button B" />
</header>
</field>
</record>
</data>
</openerp>


The two buttons appear, so everything fine to this point.


Button A:
Should open a new, customize view (just a dummy view at this moment). This view will create products later.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record
id="custom_wizard_ext_view" model="ir.ui.view">
<field
name="name">product.product.form</field>
<field
name="model">product.product</field>
<field
name="type">form</field>
<field
name="arch" type="xml">
<data>
<field
name="name" colspan="4" />
<group
col="4" colspan="4">
<button
name="save" string="Save" type="object" colspan="1" />

</group>
</data>
</field>
</record>
</data>
</openerp>

Shouldn't %(custom_wizard_ext_view)d open this view?


Button B:

Call of a function which is in my file sale_order.py:

from openerp import models, fields


class sale_order(models.Model):
_inherit = 'sale.order'

def open_wizard(self, cr, uid, ids, context=None):
return {
'type': 'ir.actions.act_window',
'res_model': 'product.product',
'view_type': 'form',
'view_mode': 'form',
'res_id': 'custom_wizard_ext_view',
'target': 'new',
}

When I click "Button B" I get this error:

TypeError: open_wizard() takes exactly 1 argument (5 given) 


Which one is the right approach to open a view from a button in the status bar?









Avatar
Discard
Best Answer

In new api try this:

@api.multi 
def open_wizard(self):
....

Avatar
Discard
Best Answer

Hi,

You can return a view from a python function in many ways, see:

Method 1:

def action_search_appointment_m3(self):
return {
'type': 'ir.actions.act_window',
'name': 'Appointments',
'res_model': 'hospital.appointment',
'view_type': 'form',
'domain': [('patient_id', '=', self.patient_id.id)],
'view_mode': 'tree,form',
'target': 'current',
}
Method 2:

def action_search_appointment_m1(self):
action = self.env.ref('om_hospital.action_hospital_appointment').read()[0]
action['domain'] = [('patient_id', '=', self.patient_id.id)]
return action

Method 3:

def action_search_appointment_m2(self):
action = self.env['ir.actions.actions']._for_xml_id("om_hospital.action_hospital_appointment")
action['domain'] = [('patient_id', '=', self.patient_id.id)]
return action

For more: Return Action and View From Python Code

Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 17
3772
3
Jun 21
8813
1
Dec 18
5165
2
Nov 18
7524
1
Jun 17
7075