0
votes

After installing RFID Terminal module successfully on a fresh database of OpenERP 7 to pull attendance logs from a ZKTeco DS100 machine, I tried to add a user in the module (to link IDs on the machine with Employee IDs in OpenERP). I get the error:

    File "C:\Program Files (x86)\OpenERP 7.0-20130610-231029\Server\server\openerp\addons\hr_attendance_terminal\hr_attendance_terminal.py", line 230, in create_terminal_users
    UnboundLocalError: local variable 's' referenced before assignment

The code block:

def create_terminal_users(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
            if context is None:
            context = {}

        terminal_ids = self.pool.get('hr.attendance.terminal').search(cr, uid, [])

        for t_id in terminal_ids:
            terminal = self.pool.get('hr.attendance.terminal').browse(cr, uid, t_id, context=context)
            #print "CREATE USER ON Terminal: %s | %s" % (terminal.tnr, terminal.ip)

            TerminalNr = terminal.tnr # zweistelling in Hex         
            host = terminal.ip # Terminaladresse

            port = 8000 # Terminaldatenport
            STX = '\x02' # Startbit
            ETX = '\x03' # Stopbit

            emp_ids = self.pool.get('hr.employee').search(cr, uid, [('rfid_key', '!=', '')])
            if emp_ids:

                #Verbindung herstellen
                s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                try:
                    s.connect((host,port))
                except socket.error, msg:
                    print 'Socket Error: %s' % msg
                    break

                for emp_id in emp_ids:
                    employee = self.pool.get('hr.employee').browse(cr, uid, emp_id, context=context)

                    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                    rfid_key = employee.rfid_key
                    employee_name = employee.name
                    pin = '0000'
                    pinabfrage = '0' # bei 1 wird pin abgefragt
                    infotext1 = '                ' # 16 Zeichen Infotext
                    infotext2 = employee_name.center(16) # 16 Zeichen Infotext
                    infotext3 = '                ' # 16 Zeichen Infotext
                    infotext4 = '                ' # 16 Zeichen Infotext

                    #Paket / Telegram erstellen
                    #Schema: <STX>SS<Kommando><Daten><BCC><ETX>

                    bccstring = self.create_bcc(TerminalNr + 'SPSTA' + rfid_key + pin + pinabfrage + infotext1 + infotext2 + infotext3 + infotext4)
                    message = STX + TerminalNr + 'SPSTA' + rfid_key + pin + pinabfrage + infotext1 + infotext2 + infotext3 + infotext4 + bccstring + ETX
                    #print "Employee: %s" % employee.name
                    #Paket / Telegram senden
                    try:
                        s.sendall(message)
                    except socket.error, msg:
                        print 'Socket Error: %s' % msg
                        break
                    while 1:
                        reply = s.recv(8192)
                        if str(reply) != '':
                            r_message = re.sub(r'\x02|\x03','',str(reply))
                            r_terminal = r_message[0:2]
                            if r_message[2:7] == 'SPSTA':
                                #print "Stammsatz gespeichert!"
                                break

        s.close()
        return True

Notes:

  • The module installed normally eventhough it was built for OERP 6.
  • Made minor changes to match OERP 7 import functions.
  • Python 2.7
2

2 Answers

0
votes

s.close() should come inside the for loop.

0
votes

I would like to add my comment to this, because we are the Creators of the Module. The Module you've installed will only work with this specific Device: Officetimer II from ADC GmbH, not with any other RFID Attendance Device!

Beware, the Module that is publicly available is only a first release from mid 2011 for OpenERP Version 6.0, actually you could call it a draft, bugfixes and enhancements have not been applied on the launchpad branch! This Module should really not be used with Version 6.1 or 7.0 of OpenERP due to the handling of the terminal communication and timezone management!

Of course we have ported the Module to 6.1 and 7.0, but we have not made those modules publicly available due to several reasons.