Odoo 10 获取 many2one 的选定值的 id
Odoo 10 getting the id of the selected value of many2one
我有这个 many2one 字段,我想获取所选值的 ID
service = fields.Many2one('mainservices.mtvehlog', string='Select Service(s)')
所以onchange我想知道id,知道后做点什么(我想让其他字段不可见)
many2one多选怎么办?如何获取已选择的 ID?
@api.depends('service')
def _compute_hide(self):
source_obj=self.pool.get('mainservices.mtvehlog').browse(self.service)
if source_obj == '1':
self.services_selected = source_obj
self.hide = True
else:
self.services_selected = source_obj
self.hide = False
请帮忙
在使用 depends 装饰器的计算方法中,总是先循环 self。
for rec in self:
# and this is how you get the id value
#you don't have to browse you have direct acces to properties of the selected value
if rec.service.id == somthing :
# and you will not get except singlton error
你的问题不清楚你想用 id 值做什么。
我有这个 many2one 字段,我想获取所选值的 ID
service = fields.Many2one('mainservices.mtvehlog', string='Select Service(s)')
所以onchange我想知道id,知道后做点什么(我想让其他字段不可见)
many2one多选怎么办?如何获取已选择的 ID?
@api.depends('service')
def _compute_hide(self):
source_obj=self.pool.get('mainservices.mtvehlog').browse(self.service)
if source_obj == '1':
self.services_selected = source_obj
self.hide = True
else:
self.services_selected = source_obj
self.hide = False
请帮忙
在使用 depends 装饰器的计算方法中,总是先循环 self。
for rec in self:
# and this is how you get the id value
#you don't have to browse you have direct acces to properties of the selected value
if rec.service.id == somthing :
# and you will not get except singlton error
你的问题不清楚你想用 id 值做什么。