简体   繁体   中英

dynamic view with on_change in OpenERP

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

Python Code :

_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),
          }

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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM