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