This question has been flagged
2 Replies
11956 Views

Hi,

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.

Avatar
Discard
Best Answer

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 ),
   }
Avatar
Discard
Author

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

Finally I updated my answer based on your code.

Author

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

Best Answer

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.

Avatar
Discard
Author

thank you..this information was very helpful.