Reputation: 25
I'm having some troubles coming up with a "on_change" method to create a dynamic view.
I want to adapt the fields that the user has to fill depending on "selection field".
if the user choses "Personne Morale", the view has to contain only the fields: "raison social","dossier",adresse","tel" and not show the other fields.
if the user choses "Personne Physique", the the view will have to contain the following fields : "nom", "prenom", "cin", "dossier",adress", "tel".
Note that the fields "dossier","adresse","tel","adresse" are not meant to change, they're commun.
PS: don't mind the identitation
_columns = {
'statut': fields.selection((('p','Personne Physique'), ('m','Personne Morale')),'Statut'),
'nom': fields.char('Nom', size=100, required=True),
'prenom': fields.char('Prenom', size=100, required=True),
'cin': fields.char('N° CIN', size=100, required=True),
'raison_social':fields.char('Raison Social', size=100, required=True),
'dossier': fields.one2many('sayoo.dossier','id_dossier','demande d\'autorisation' ),
'adresse': fields.char('Adresse', size=100, required=True),
'description': fields.text('Description'),
'tel': fields.char('Numéro de Téléphone', size=20),
}
Upvotes: 0
Views: 451
Reputation: 14768
you don't need an on_change behaviour for that. just use attrs
attribute in your xml views like:
<field name="raison_social" attrs="{'invisible':[('statut','=','p')],'required':[('statut','=','m')]}" />
<field name="nome" attrs="{'invisible':[('statut','=','m')],'required':[('statut','=','p')]}" />
ofcourse you don't need the required part, but i wanted to show you the idea in my example. you can set invisible
, readonly
and required
through attrs
.
i hope that's helping :-)
Upvotes: 2