我需要创建 many2one 字段。但它应该需要根据我在函数中的逻辑过滤数据。那么如何在 OpenERP 版本 7 中实现呢?
我尝试使用以下代码。但它没有给出列表。只是作为只读字段加载:
def _get_users(self, cr, uid, ids, field_name, arg, context=None):
res = {}
users_list=[]
officer_ids = self.search(cr, uid , 'bpl.officer', [('is_user', '=', True)])
officer_obj = self.browse(cr, uid, officer_ids, context=context)
for record in officer_obj:
users_list.append(record.user_id.id)
user_obj = self.pool.get('res.users')
for data in self.browse(cr, uid, ids, context=context):
res[data.id] = users_list
return res
_name = "bpl.officer"
_description = "Officer registration details"
_columns = {
'bpl_company_id':fields.many2one('res.company', 'Company', help='Company'),
'bpl_estate_id':fields.many2one('bpl.estate.n.registration', 'Estate', help='Estate', domain="[('company_id', '=', bpl_company_id)]"),
'bpl_division_id':fields.many2one('bpl.division.n.registration', 'Division', help='Division', domain="[('estate_id','=',bpl_estate_id)]"),
'name': fields.char('Name', size=128, required=True),
'is_user': fields.boolean('Is User', help="Is System user or not"),
'user_id': fields.function(_get_users, type="many2one",relation="res.users"),