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

Hello everyone,

suppose i have my model_main, model_1 and model_2 with their correponding view_main, view_1 and view_2. I have a selection field in my model_main and i want to display a form (trigger action_1 or action_2) depending on my selection value, how can i do that  ?

 

Avatar
Discard
Author Best Answer

@Juan Thank you for your answer, but it doesn't work. Here is my try :

py file :

class T_Component(models.Model):
_name = 't.component'
wtg_id = fields.One2many('t.wtg','component_id')
other_id = fields.One2many('t.other','component_id')
t_substation_id = fields.Many2one('t.substation','Substation')
component_type = fields.Selection(string="Type du composant",selection=[('wtg','Turbine'),('nop','Not implemented')])
#@api.onchange('component_type')
def onchange_type(self) :
if self.component_type :
if self.component_type == "Turbine" :
return {
'type': 'ir.actions.act_window',
'name': 'Turbine',
'view_type': 'form',
'view_mode': 'form',
'view_id': 'view_wtg_form',
'res_model': 't.wtg',
'nodestroy': True,
'target': 'current',
'res_id': self.component_type,
}
if self.component_type == "Not implemented" :
return {
'type': 'ir.actions.act_window',
'name': 'Autre',
'view_type': 'form',
'view_mode': 'form',
'view_id': 'view_other_form',
'res_model': 't.other',
'nodestroy': True,
'target': 'current',
'res_id':self.component_type,
}


xml file :

<?xml version="1.0" encoding ="utf-8"?>
<openerp>
<data>
<!-- FORM -->
<record id="view_component_form" model="ir.ui.view">
<field name="model">t.component</field>
<field name="name">t.component.form.view</field>
<field name="arch" type="xml">
<form string="Fiche Composants" version="7.0">
<sheet>
<group string="Informations generales">
<field name="t_substation_id" options="{'no_create_edit': True}"/>
<field name="component_type"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="view_wtg_form" model="ir.ui.view">
<field name="model">t.wtg</field>
<field name="name">t.wtg.form.view</field>
<field name="arch" type="xml">
<form string="Turbine form" version="7.0">
<sheet>
<group string="Turbines and turbiners informations">
<field name="rec_turbine"/>
<field name="itt_nserie"/>
<field name="iwp_invt_wp"/>
<field name="itt_type_turbine"/>
<field name="itt_dim_rotor"/>
<field name="itt_haut_mat"/>
<field name="itt_lat_turbine"/>
<field name="itt_lon_turbine"/>
<field name="itt_proc_givre"/>
<field name="itt_brid_perm"/>
<field name="iat_marque_cel"/>
<field name="hse_sys_anti_intr"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="view_other_form" model="ir.ui.view">
<field name="model">t.other</field>
<field name="name">t.other.form.view</field>
<field name="arch" type="xml">
<form string="Other form" version="7.0">
<sheet>
<group string="Component Informations">
<field name="component_id"/>
<field name = "value" />
</group>
</sheet>
</form>
</field>
</record>

I've also tried to compare with the value in self.component_id but it doesn't work neither, Did I miss something ?

Avatar
Discard
Best Answer

Hello,

Create a function in model_main  onchange_selection_field (see examples searching for onchange in odoo code)

then make if statement of selected value and show form like,

return {

'type': 'ir.actions.act_window',

'name': 'your_form_name',

'view_type': 'form',

'view_mode': 'form',

'view_id': <-- the id of the view,

'res_model': 'your model',

'nodestroy': True,

'target': 'current',

'res_id': <-- ids of values selected or False,

}


Kind Regards,

Juanvi

Avatar
Discard
Related Posts Replies Views Activity
4
Dec 21
29876
0
Mar 15
3143
0
Apr 17
2197
0
Jul 16
5005
2
Oct 15
16436