user3153567
user3153567

Reputation: 157

Many2one value display in OpenERP

I tried to create a simple Many2one field but the values are showing in this format: new.base,1 and new.base,2 and so on. Please let me know the fix so as to display value for the same.

class latest_base(osv.osv):
       _inherit = ['mail.thread']
       _name='latest.base'
       _columns={
                'name':fields.char('Name',required=True),

                'image': fields.binary("Image", help="Select image here"),


                'email':fields.char('Email'),
                'code':fields.many2one('new.base','code'),
               }

  latest_base()



 class new_base(osv.osv):

       _name='new.base'
       _columns={
               'code':fields.char('Department'),

               'hod':fields.char("Head of the Department"),
               }
 new_base()

Upvotes: 0

Views: 1085

Answers (2)

StackUP
StackUP

Reputation: 1303

because you have not declared name field in your model, openerp returns name field value by default, if you want set other field as just define _rec_name='field_name' you will get value of that field.

Upvotes: 0

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

try this, name is a Special fields in OpenERP and unique name used by default for labels in forms, lists, etc. If we don't use a name in table than we use _rec_name to specify another field to use.

class latest_base(osv.osv):
   _inherit = ['mail.thread']
   _name='latest.base'
   _columns={
            'name':fields.char('Name',required=True),
            'image': fields.binary("Image", help="Select image here"),
            'email':fields.char('Email'),
            'code':fields.many2one('new.base','code'),
           }

latest_base()

class new_base(osv.osv):
   _name='new.base'
   _rec_name = 'code'
   _columns={
           'code':fields.char('Department'),
           'hod':fields.char("Head of the Department"),
           }
new_base()

Hope this will solve your problem.

Upvotes: 7

Related Questions