get a one2many fields value of an object

Asked by ange bouabre

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 = {
  'name':fields.one2many('vigne.class','name',"Vignes"),
         '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

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Kalpana Hemnani(SerpentCS)
Solved:
Last query:
Last reply:
Revision history for this message
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!!

Revision history for this message
Best Kalpana Hemnani(SerpentCS) (khemnani-serpentcs) said :
#2

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,
Regards,
Kalpana Hemnani,
Serpent Consulting Services.

Revision history for this message
ange bouabre (angebouabre) said :
#3

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