Search code examples
pythonopenerp-7

openerp - import custom module function into hr_employee


I have a problem with importing a function from my own module into the hr_employee module. Folder structure:

 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()

with this code I get the following error:

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

I am realy stuck here tried al kinds of different ways to import that function but did not manage. I gues inherit interferes with import. Any help is very much welcomed, Chris


Solution

  • To be honest I don't quite understand why are you doing this that way. OpenERP is meant to be used as class inheritance:

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

    Store it in some variable and call your functions, eg:

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

    Just a hint: 'hr.employee' already exists and it is not your object, I suggest you remove '_name' part and just leave '_inherit'.

    Hope it helps :)