我有一个相关字段' region_id'从另一个类中的many2one字段中获取值,如此
class activity_summary(osv.osv):
_name = "budget.activity_summary"
_rec_name = "activity_summarycode"
_columns = {
'activity_summarycode' : fields.many2one("budget.activity_year", "Activity Summary Code", ondelete= "no action", required=True ),
'region_id' : fields.related("activity_summarycode", "mgmt_code", type="char", string = "Management Code", size=64, store = True),
}
但它没有给出正确的价值,相反,当我保存时,它给了我这个:browse_record(budget.org_table,12)。为什么不返回价值?我该怎么办呢?
活动年级
class activity_year(osv.osv):
_name = "budget.activity_year"
_description = "Activity year"
_rec_name = "activity_yearcode"
_columns = {
'activity_yearcode' : fields.char("Activity Code", size=64, required=True),
'activity_name' : fields.char("Activity Name", size=128),
'mgmt_code' : fields.many2one("budget.org_table","Management Unit Code"),
}
_sql_constraints = [
('activity_yearcode_unique', 'UNIQUE(activity_yearcode)', 'Each activity code is unique.'),
]
budget.org-table class
class org_table(osv.osv):
_name = "budget.org_table"
_rec_name = "org_code"
_columns = {
'org_code' : fields.char("Code", size=64),
'org_name' : fields.char("Name"),
}
_sql_constraints = [
('org_code_unique', 'UNIQUE(org_code)', 'Each org_table ID is unique.'),
]
答案 0 :(得分:4)
在OpenERP中,当您使用related
字段时,它会根据它type.
提供值或输出,例如type='char'
,See other fields type
在您的情况下,您需要使用type='many2one'
获取欲望输出。
试试这个,
class activity_summary(osv.osv):
_name = "budget.activity_summary"
_rec_name = "activity_summarycode"
_columns = {
'activity_summarycode' : fields.many2one("budget.activity_year", "Activity Summary Code", ondelete= "no action", required=True ),
'region_id' : fields.related("activity_summarycode", "mgmt_code", type="many2one", string = "Management Code", relation="budget.activity_year", size=64, store = True),
}