콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
13771 화면

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.

아바타
취소
베스트 답변

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...

Finally I updated my answer based on your code.

작성자

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

베스트 답변

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.

관련 게시물 답글 화면 활동
1
9월 21
21247
2
3월 15
6810
1
1월 22
3526
0
10월 20
3124
0
5월 20
6521