oddo不能适应类型' hr.employee'

时间:2016-08-27 10:04:05

标签: python openerp

我希望在我的班级中获得一个字段的值,即one2many到hr_employee:

class cashadvance(osv.osv):
    def get_employeeid(self, cr, uid, context=None):
        idemployee = ""
        employee_id = ""
        ids = self.search(cr, uid, [], context=context) # you probably want to search for all the records
        for adv in self.browse(cr, uid, ids, context=context):
            employee_id = adv.id_employee
        if (employee_id is None):
            idemployee = 0
        else:
            idemployee = employee_id
        return idemployee
    _name = 'comben.cashadvance'
    _columns = {
        'id_employee'               : fields.many2one('hr.employee', string='Employee', required=True, readonly=True),
    }

它引发了错误:无法适应类型' hr.employee'

但是当我改变时:

class cashadvance(osv.osv):
    def get_employeeid(self, cr, uid, context=None):
        idemployee = ""
        employee_id = ""
        ids = self.search(cr, uid, [], context=context) # you probably want to search for all the records
        for adv in self.browse(cr, uid, ids, context=context):
            employee_id = adv.id_employee
        if (employee_id is None):
            idemployee = 0
        else:
            **idemployee = 1348  #employee_id**
        return idemployee
    _name = 'comben.cashadvance'
    _columns = {
        'id_employee'               : fields.many2one('hr.employee', string='Employee', required=True, readonly=True),
    }

我工作得很好,我对此做错了,请帮忙

1 个答案:

答案 0 :(得分:3)

   for adv in self.browse(cr, uid, ids, context=context):
        employee_id = adv.id_employee

在这部分代码中,您正在浏览自我模型。 Browse方法返回一个记录集,这意味着它返回表示浏览所运行模型的类的实例。如果你想获得任何记录的id:

        employee_id = adv.id_employee.id