Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to trigger action depending on selection value ?

By
Azzedine
on 5/25/16, 5:19 AM 320 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  ?

 

0
Azzedine
On 5/25/16, 7:59 AM

@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 ?

0
Juan Vicente Pascual
On 5/25/16, 5:53 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/25/16, 5:19 AM
Seen: 320 times
Last updated: 5/25/16, 7:59 AM