openerp - 将自定义模块函数导入 hr_employee

openerp - import custom module function into hr_employee

我在将函数从我自己的模块导入到 hr_employee 模块时遇到问题。 文件夹结构:

 my_project
        sub_module(subfolder)
            my_module.py
            inherit_class.py
            __init__.py

inherit_class.py:

from openerp.osv import fields, osv
from .my_module import attendance_terminal   
class hr_employee(osv.osv):
    _name = "hr.employee"
    _description = "Employee"
    _inherit = "hr.employee"

    _columns = {
       'rfid': fields.integer('RFID')
    }


   def write(self, cr, uid, ids, vals, context=None):
       res = super(hr_employee, self).write(cr, uid, ids, vals, context=context)
       . . .
       error_code = attendance_terminal.terminal_setuser(a, b, c)
       . . .   
       return res

hr_employee()

my_module.py:

class attendance_terminal(osv.osv):
    _name = "attendance.terminal"
    _description = "Attendance Terminal Comunnication"

    . . .
    def terminal_setuser(self, a,b,c):
        . . .
        return
    . . . 
attendance_terminal()

使用此代码我得到以下错误:

TypeError: unbound method terminal_setuser() must be called with attendance_terminal instance as first argument (got unicode instance instead)

我真的被困在这里尝试了各种不同的方法来导入该功能,但没有成功。我猜继承会干扰导入。 非常欢迎任何帮助, 克里斯

老实说,我不太明白你为什么要那样做。 OpenERP 旨在用作 class 继承:

self.pool.get('attendace.terminal') 

将其存储在某个变量中并调用您的函数,例如:

attendance_obj = self.pool.get('attendace.terminal')
error_code = attendance_obj.terminal_setuser(a, b, c)

提示:'hr.employee'已经存在,不是你的对象,我建议你删除'_name'部分,只留下'_inherit'。

希望对您有所帮助:)