get a one2many fields value of an object

Asked by ange bouabre on 2012-05-02

hi i'm new user open erp and i try to develop my own module. i've an issue to get a field value: i've 2 class:

class client_class(osv.osv):
    _name = 'client.class'
    _sql_contraints = [('name_uniq','unique(name)','unique'),]
    _columns = {
         'nom': fields.char("Nom et Prenom",size=128),

class vigne_class(osv.osv):
    _name = 'vigne.class'
    _columns = {
  'name': fields.many2one('client.class',"id_client", select=True),
                'nom': fields.many2one('client.class',"Nom de vigne"),

And i would like to get in 'nom': fields.many2one('client.class',"Nom de vigne") the value of 'nom': fields.char("Nom et Prenom",size=128) in the view form. Please tell me how can i do that??

Question information

English Edit question
Odoo Addons (MOVED TO GITHUB) Edit question
No assignee Edit question
Solved by:
Kalpana Hemnani(SerpentCS)
Last query:
Last reply:
ange bouabre (angebouabre) said : #1

i change the code now like this:

class client_class(osv.osv):
    _name = 'client.class'
    _sql_contraints = [('name_uniq','unique(name)','unique'),]
    _inherit = 'res.partner'
    _columns = {
  'client_id':fields.one2many('vigne.class','vigne_ids',"Vignes"), #'vigne'
     'nom': fields.char("Nom et Prenom",size=128),
     'phone': fields.char("Téléphone",size=64),

class vigne_class(osv.osv):
    _name = 'vigne.class'

    _columns = {
  'vigne_ids': fields.many2one('client.class',"Propriétaire", select=True), #Associe object Vigne à l'objet Client cia ce champ #'proprietaire'
        'nom': fields.char("Nom de vigne",size=64),
  'lieu': fields.char("Lieu",size=64),
  'nbr_treill': fields.integer("Nombre de treilles"),

and i would like to get value of field 'nom' of client_class in a field of vigne_class. Help me how to do that please!!

Hello Ange Bouabre (angebouabre),

For getting value of field "nom" of "client_class" in the field of "nom" of "vigne_class", you can use "related field", using this you will get the value of "nom" of "client_class" in "nom" of "vigne_class".

You should define this related field in "vigne_class" as follow:
 'nom': fields.related('vigne_id','nom',string="Nom et Prenom",type='char')
 where 'vigne_id' is your many2one field(associate object of "client_class") and 'nom' is your related field name of "client_class".

I want to give you some suggestions:
1. While defining one2many field, the field name should be name_ids as you will get one or more ids.
2. While defining many2one field, the field name should be name_id as you will get only one id in that field.

Thank you,
Kalpana Hemnani,
Serpent Consulting Services.

ange bouabre (angebouabre) said : #3

Thanks Kalpana Hemnani(SerpentCS), that solved my question.