Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


many2one field not showing field values

on 4/21/14, 6:34 AM 2,378 views


Im having a problem linking a many2one field to another many2one field. Im getting numbers like 1,2,3(i think its the record number) instead of the field value in the drop down list.

Below, I have 3 classes Activity code, Activity data, and Activity summary.

Activity summary has a many2one field called 'activity_code' that relates to Activity data and activity data has a many2one field that relates to activity code. I am able to view the field values in the drop down list in activity data form, it works fine, but im not able to view it in Activity summary form. I get numbers

Can anyone tell me why this is happening and how i may fix it to show the intended value instead of the numbers? Below is my code.

Activity code

class activity_yearcode(osv.osv):
 _name = "budget.activity_code"
 _description = "Activity Year Code"
 _rec_name = "activity_code"
 _columns = {
    'activity_code' : fields.char("Activity Code", size=64, required=True),
    'activity_name' : fields.char("Activity Name", size=128),
    'act_status' : fields.selection([
                ('1', 'All'),
                ('2', 'Active'),
                ('3', 'Inactive'),
                ], 'Status'),
_sql_constraints = [
    ('activity_code_unique', 'UNIQUE(activity_code)', 'Each activity code is unique.'),

Activity Data - working fine

class activity_data(osv.osv):

_name = "management.activity_data"
_description = "Activity Data"
_rec_name = "activity_data_num"
_columns = {
    'activity_data_num' : fields.char('activity_data_num', size=16),
    'activity_code' : fields.many2one( "budget.activity_code","Activity Code",required=True),
    'management_unit_code' : fields.many2one("budget.org_table","Management Unit Code", required=True),
_defaults = {
    'activity_data_num': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'management.activity_data'),
_sql_constraints = [
    ('activity_data_num', 'UNIQUE(activity_data_num)', 'Each activity_data_num is unique.'),

Activity Summary - In this model, im getting a single digit number instead of the the field value in 'activity_code' field.

class activity_summary(osv.osv):
_name = "work.activity_summary"
_description = "Activity Summary"
_columns = {
    'activity_code' : fields.many2one("management.activity_data", "Activity Code", ondelete= "no action", required=True ),
    'management_code' : fields.related("activity_code", "activity_data_num", "management_unit_code", type = "char", string = "Management code"),
'region_id' : fields.char("Region ID", size=64, required=True),
    'daily_prod' : fields.integer("Daily Prod"),
    'deviation' : fields.integer("Deviation Level"),


Please help..Thank you in advance.



| 5 4 7
Bikaner, India

OpenERP Devloper at SunARC Technology

On 4/21/14, 6:52 AM

Based on your code rec_name field value shows in many2one 1) management.activity_data table many2one relation budget.activity_code table used for the column (List it shows activity_code)

2) work.activity_summary table activity_code many2one relation management.activity_data table used (Lits it shows activity_data_num)

In work.activity_summary table If you want shows activity_code from budget.activity_code table then change the many2one relation into below code:

class activity_summary(osv.osv):
_name = "work.activity_summary"
_description = "Activity Summary"
_columns = {
    'activity_code' : fields.many2one("budget.activity_code", "Activity Code", ondelete= "no action", required=True ),

hi, sorry, but still there's no change...

on 4/21/14, 6:57 AM

Finally I updated my answer based on your code.

on 4/21/14, 7:23 AM

hi, This works fine, so, it relates to the budget.activity code model right. Thank you so much.!

on 4/22/14, 12:27 AM

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 4/21/14, 7:13 AM

Hi, By default priority will be given for name field if rec_name is not present. Define your required field in rec_name. If you want more than one field value to be displayed means use name_get orm method.

thank you..this information was very helpful.

on 4/22/14, 12:28 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


Asked: 4/21/14, 6:34 AM
Seen: 2378 times
Last updated: 3/16/15, 8:10 AM