Odoo中文网|Odoo实施培训

标题: 怎么在 domain 中使用函数字段 [打印本页]

作者: 非常感觉    时间: 2015-9-28 14:53
标题: 怎么在 domain 中使用函数字段
本帖最后由 非常感觉 于 2015-9-28 15:00 编辑

我想实现,只有HR 经理才可以看到这些记录,我已经创建了函数字段:
  1. def list_HRM(self, cr, uid, ids, field_name, arg, context):
  2.          attribute = {}
  3.         hr_managers = self.pool.get('hr.employee').search(cr, uid, ['&', ('department_id.name', '=', 'Human Resources'), ('manager', '=', True)], context=context)
  4.         hr_managers_uid = []
  5.         for record in hr_managers:
  6.             hr_managers_uid.append(self.pool.get('hr.employee').browse(cr, uid, record, context=context).user_id.id)
  7.         record = self.browse(cr, uid, ids)[0]
  8.         attribute[record.id] = str(uid in hr_managers_uid or uid==1)
  9.         return attribute

  10.     _columns={
  11.     'hr_managers_func' : fields.function(list_HRM, type='char', method=True, string='List of HR Managers'),
  12.     'always_true':fields.boolean()
  13.      }
  14.    _defaults={
  15.       'always_true':True
  16.       }
复制代码


In .xml file:
  1. <field name="always_true" invisible="1"/>
  2. <field name="hr_managers_func" invisible="1"/>
复制代码

In Record Rule:
  1. ['&','|',('state','=','hod_depart'),('state','=','hr_review'),('always_true','=',eval(hr_managers_func))]
复制代码


运行的时候报错:

NameError: name 'eval' is not defined
作者: 非常感觉    时间: 2015-9-28 15:01
坐等大神帮忙。
作者: 美丽的大脚    时间: 2015-9-29 09:04
根据我的经验,函数字段 domain 和普通字段 domain 没有区别




欢迎光临 Odoo中文网|Odoo实施培训 (http://www.chinaodoo.net/) Powered by Discuz! X3.2