updata loginUrl
This commit is contained in:
parent
a026a1350a
commit
aea912fa0c
|
|
@ -4,8 +4,7 @@ from datetime import datetime, timedelta
|
|||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from .helper import httpHelper, is_valid_port, employeeUrl, departmentsUrl, positionsUrl, is_valid_ip, areasUrl, \
|
||||
terminalsUrl, ParsedRequest, transctionsUrl
|
||||
from .helper import httpHelper, is_valid_port, is_valid_ip, ParsedRequest
|
||||
|
||||
|
||||
class SystemAttendance(models.Model):
|
||||
|
|
@ -30,7 +29,6 @@ class SystemAttendance(models.Model):
|
|||
|
||||
|
||||
class SystemTerminal(models.Model):
|
||||
|
||||
_name = 'finger.terminal'
|
||||
|
||||
name = fields.Char("Terminal name")
|
||||
|
|
@ -44,7 +42,6 @@ class SystemTerminal(models.Model):
|
|||
|
||||
|
||||
class SystemEmployee(models.Model):
|
||||
|
||||
_name = 'finger.employee.employee'
|
||||
|
||||
name = fields.Char("System Employee Name")
|
||||
|
|
@ -56,11 +53,8 @@ class SystemEmployee(models.Model):
|
|||
hr_employee = fields.Many2one('hr.employee', string='Empolyee Name')
|
||||
server_id = fields.Many2one('finger.biotime_api', string='Hr empolyee')
|
||||
|
||||
|
||||
|
||||
|
||||
class SystemEmployeePosition(models.Model):
|
||||
|
||||
_name = 'finger.employee.position'
|
||||
|
||||
name = fields.Char("Name")
|
||||
|
|
@ -70,7 +64,6 @@ class SystemEmployeePosition(models.Model):
|
|||
|
||||
|
||||
class SystemArea(models.Model):
|
||||
|
||||
_name = 'finger.area'
|
||||
|
||||
name = fields.Char("Name")
|
||||
|
|
@ -80,7 +73,6 @@ class SystemArea(models.Model):
|
|||
|
||||
|
||||
class SystemDepartments(models.Model):
|
||||
|
||||
_name = 'finger.employee.department'
|
||||
|
||||
name = fields.Char("Name")
|
||||
|
|
@ -122,6 +114,19 @@ class BiotimeAPI(models.Model):
|
|||
[('authentic', _('Authentic')),
|
||||
('unauthentic', _('Not authentic'))], default="unauthentic")
|
||||
|
||||
@api.model
|
||||
def _calc_urls(self):
|
||||
serverIP = self.serverUrl + ":" + self.port
|
||||
loginUrl = serverIP + "/jwt-api-token-auth/"
|
||||
refreshUrl = serverIP + "/jwt-api-token-refresh/"
|
||||
employeeUrl = serverIP + "/personnel/api/employee/"
|
||||
departmentsUrl = serverIP + "/personnel/api/departments/"
|
||||
terminalsUrl = serverIP + "/iclock/api/terminals/"
|
||||
areasUrl = serverIP + "/personnel/api/areas/"
|
||||
positionsUrl = serverIP + "/personnel/api/positions/"
|
||||
transctionsUrl = serverIP + "/iclock/api/transactions/"
|
||||
return loginUrl, refreshUrl, employeeUrl, departmentsUrl, positionsUrl, is_valid_ip, areasUrl, terminalsUrl, ParsedRequest, transctionsUrl
|
||||
|
||||
@api.depends('token')
|
||||
def depends_token(self):
|
||||
for srv in self:
|
||||
|
|
@ -147,9 +152,8 @@ class BiotimeAPI(models.Model):
|
|||
raise ValidationError(_("Invalid port number"))
|
||||
|
||||
def process_attendance_scheduler(self):
|
||||
for tx in self.attendance_ids :
|
||||
for tx in self.attendance_ids:
|
||||
print(tx)
|
||||
|
||||
|
||||
def login(self):
|
||||
res = httpHelper.login(self.username, self.password)
|
||||
|
|
@ -188,9 +192,9 @@ class BiotimeAPI(models.Model):
|
|||
def to_attendace(self):
|
||||
Attend = self.env['finger.system_attendance']
|
||||
attendance = self.env['attendance.attendance']
|
||||
HR = self.env['hr.employee']
|
||||
attens = Attend.search([('server_id', '=', self.id),('state', '=', 'draft')])
|
||||
for tx in attens :
|
||||
HR = self.env['hr.employee']
|
||||
attens = Attend.search([('server_id', '=', self.id), ('state', '=', 'draft')])
|
||||
for tx in attens:
|
||||
if tx.emp_code and tx.emp_code.hr_employee:
|
||||
attendance.create({
|
||||
'employee_id': tx.emp_code.hr_employee.id,
|
||||
|
|
@ -199,22 +203,21 @@ class BiotimeAPI(models.Model):
|
|||
'action_date': tx.punch_time,
|
||||
})
|
||||
tx.write({
|
||||
'state':'confirmed'
|
||||
'state': 'confirmed'
|
||||
})
|
||||
|
||||
|
||||
def sync_employees(self):
|
||||
if not self.token :
|
||||
if not self.token:
|
||||
self.refresh()
|
||||
res = httpHelper.fetch_employees({}, self.token)
|
||||
|
||||
_, _, employeeUrl, _, _, _, _, _, _, _ = self._calc_urls()
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
self.create_employee(da.data)
|
||||
next = 2
|
||||
while da.next:
|
||||
r = httpHelper.fetch_employees(
|
||||
{},self.token,employeeUrl + "?page=" + str(next))
|
||||
{}, self.token, employeeUrl + "?page=" + str(next))
|
||||
if r.status_code == 200:
|
||||
da = ParsedRequest(r.content)
|
||||
self.create_employee(da.data)
|
||||
|
|
@ -226,27 +229,27 @@ class BiotimeAPI(models.Model):
|
|||
self.errorHandler(res)
|
||||
|
||||
def errorHandler(self, res):
|
||||
if res.status_code == 401 :
|
||||
if res.status_code == 401:
|
||||
self.logout()
|
||||
else :
|
||||
else:
|
||||
data = res.json()
|
||||
err = ""
|
||||
for key in data:
|
||||
err += ' '.join(data[key])
|
||||
raise ValidationError(err)
|
||||
|
||||
|
||||
def sync_terminals(self):
|
||||
if not self.token :
|
||||
if not self.token:
|
||||
self.refresh()
|
||||
res = httpHelper.fetch_terminals({}, self.token)
|
||||
|
||||
_, _, _, _, _, _, _, terminalsUrl, _, _ = self._calc_urls()
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
self.create_termainl(da.data)
|
||||
next = 2
|
||||
while da.next:
|
||||
r = httpHelper.fetch_terminals(
|
||||
{},self.token, terminalsUrl + "?page=" + str(next))
|
||||
{}, self.token, terminalsUrl + "?page=" + str(next))
|
||||
if r.status_code == 200:
|
||||
da = ParsedRequest(r.content)
|
||||
self.create_termainl(da.data)
|
||||
|
|
@ -257,9 +260,10 @@ class BiotimeAPI(models.Model):
|
|||
self.errorHandler(res)
|
||||
|
||||
def sync_departments(self):
|
||||
if not self.token :
|
||||
if not self.token:
|
||||
self.refresh()
|
||||
res = httpHelper.fetch_departments({}, self.token)
|
||||
_, _, _, departmentsUrl, _, _, _, _, _, _ = self._calc_urls()
|
||||
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
|
|
@ -267,7 +271,7 @@ class BiotimeAPI(models.Model):
|
|||
next = 2
|
||||
while da.next:
|
||||
r = httpHelper.fetch_departments(
|
||||
{},self.token, departmentsUrl + "?page=" + str(next))
|
||||
{}, self.token, departmentsUrl + "?page=" + str(next))
|
||||
if r.status_code == 200:
|
||||
da = ParsedRequest(r.content)
|
||||
self.create_department(da.data)
|
||||
|
|
@ -278,9 +282,10 @@ class BiotimeAPI(models.Model):
|
|||
self.errorHandler(res)
|
||||
|
||||
def sync_areas(self):
|
||||
if not self.token :
|
||||
if not self.token:
|
||||
self.refresh()
|
||||
res = httpHelper.fetch_areas({}, self.token)
|
||||
_, _, _, _, _, _, areasUrl, _, _, _ = self._calc_urls()
|
||||
try:
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
|
|
@ -301,9 +306,11 @@ class BiotimeAPI(models.Model):
|
|||
ValidationError(str(e))
|
||||
|
||||
def sync_positions(self):
|
||||
if not self.token :
|
||||
self.refresh()
|
||||
if not self.token:
|
||||
self.refresh()
|
||||
res = httpHelper.fetch_positions({}, self.token)
|
||||
_, _, _, _, positionsUrl, _, _, _, _, _ = self._calc_urls()
|
||||
|
||||
try:
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
|
|
@ -324,42 +331,43 @@ class BiotimeAPI(models.Model):
|
|||
ValidationError(str(e))
|
||||
|
||||
def sync_employee_attenence(self, url):
|
||||
if not self.token :
|
||||
if not self.token:
|
||||
self.refresh()
|
||||
res = httpHelper.fetch_empl_transctions({}, self.token,url)
|
||||
res = httpHelper.fetch_empl_transctions({}, self.token, url)
|
||||
|
||||
try:
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
next = 2
|
||||
self.create_attendance(da.data)
|
||||
while da.next:
|
||||
#res = httpHelper.fetch_empl_transctions(
|
||||
#{}, self.token, url=transctionsUrl + "?page=" + str(next))
|
||||
res = httpHelper.fetch_empl_transctions({}, self.token,da.next)
|
||||
# res = httpHelper.fetch_empl_transctions(
|
||||
# {}, self.token, url=transctionsUrl + "?page=" + str(next))
|
||||
res = httpHelper.fetch_empl_transctions({}, self.token, da.next)
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
self.create_attendance(da.data)
|
||||
else:
|
||||
da.next = None
|
||||
next = next + 1
|
||||
#print('&&&&&&&&&&&&&&&&&&&&& pages &&&&&&&&&&&&&&&&&&&',da.next)
|
||||
# print('&&&&&&&&&&&&&&&&&&&&& pages &&&&&&&&&&&&&&&&&&&',da.next)
|
||||
else:
|
||||
self.errorHandler(res)
|
||||
if res.status_code == 401:
|
||||
self.refresh()
|
||||
if self.token :
|
||||
if self.token:
|
||||
self.sync_employee_attenence(url)
|
||||
except Exception as e:
|
||||
ValidationError(str(e))
|
||||
|
||||
|
||||
def sync_attenence(self):
|
||||
self.login()
|
||||
if not self.token :
|
||||
if not self.token:
|
||||
self.refresh()
|
||||
res = httpHelper.fetch_empl_transctions({}, self.token)
|
||||
if not self.loaded_employees :
|
||||
if not self.loaded_employees:
|
||||
self.sync_employees()
|
||||
_, _, _, _, _, _, _, _, _, transctionsUrl = self._calc_urls()
|
||||
try:
|
||||
if res.status_code == 200:
|
||||
da = ParsedRequest(res.content)
|
||||
|
|
@ -374,7 +382,7 @@ class BiotimeAPI(models.Model):
|
|||
else:
|
||||
da.next = None
|
||||
next = next + 1
|
||||
#print('&&&&&&&&&&&&&&&&&&&&& pages 222 &&&&&&&&&&&&&&&&&&&',next)
|
||||
# print('&&&&&&&&&&&&&&&&&&&&& pages 222 &&&&&&&&&&&&&&&&&&&',next)
|
||||
else:
|
||||
self.errorHandler(res)
|
||||
except Exception as e:
|
||||
|
|
@ -385,15 +393,15 @@ class BiotimeAPI(models.Model):
|
|||
for tx in termainls:
|
||||
tirm = TerminalsModel.search([('terminal_id', '=', tx['id'])])
|
||||
data = {
|
||||
'terminal_id': tx['id'],
|
||||
'name': tx['terminal_name'],
|
||||
'sn': tx['sn'],
|
||||
'area_name': tx['area_name'],
|
||||
'last_activity': tx['last_activity'],
|
||||
'ip_address': tx['ip_address'],
|
||||
'alias': tx['alias'],
|
||||
'server_id': self.id
|
||||
}
|
||||
'terminal_id': tx['id'],
|
||||
'name': tx['terminal_name'],
|
||||
'sn': tx['sn'],
|
||||
'area_name': tx['area_name'],
|
||||
'last_activity': tx['last_activity'],
|
||||
'ip_address': tx['ip_address'],
|
||||
'alias': tx['alias'],
|
||||
'server_id': self.id
|
||||
}
|
||||
if not tirm:
|
||||
TerminalsModel.create(data)
|
||||
else:
|
||||
|
|
@ -404,11 +412,11 @@ class BiotimeAPI(models.Model):
|
|||
for tx in areas:
|
||||
tirm = TerminalsModel.search([('area_id', '=', tx['id'])])
|
||||
data = {
|
||||
'area_id': tx['id'],
|
||||
'name': tx['area_name'],
|
||||
'code': tx['area_code'],
|
||||
'server_id': self.id
|
||||
}
|
||||
'area_id': tx['id'],
|
||||
'name': tx['area_name'],
|
||||
'code': tx['area_code'],
|
||||
'server_id': self.id
|
||||
}
|
||||
if not tirm:
|
||||
TerminalsModel.create(data)
|
||||
else:
|
||||
|
|
@ -419,64 +427,62 @@ class BiotimeAPI(models.Model):
|
|||
for tx in departments:
|
||||
tirm = TerminalsModel.search([('department_id', '=', tx['id'])])
|
||||
data = {
|
||||
'department_id': tx['id'],
|
||||
'name': tx['dept_name'],
|
||||
'code': tx['dept_code'],
|
||||
'server_id': self.id
|
||||
}
|
||||
'department_id': tx['id'],
|
||||
'name': tx['dept_name'],
|
||||
'code': tx['dept_code'],
|
||||
'server_id': self.id
|
||||
}
|
||||
if not tirm:
|
||||
TerminalsModel.create(data)
|
||||
else:
|
||||
tirm.update(data)
|
||||
|
||||
|
||||
def create_position(self, positions):
|
||||
PostionModel = self.env['finger.employee.position']
|
||||
for tx in positions:
|
||||
tirm = PostionModel.search([('position_id', '=', tx['id'])])
|
||||
data = {
|
||||
'position_id': tx['id'],
|
||||
'name': tx['position_name'],
|
||||
'code': tx['position_code'],
|
||||
'server_id': self.id
|
||||
}
|
||||
'position_id': tx['id'],
|
||||
'name': tx['position_name'],
|
||||
'code': tx['position_code'],
|
||||
'server_id': self.id
|
||||
}
|
||||
if not tirm:
|
||||
PostionModel.create(data)
|
||||
else:
|
||||
tirm.update(data)
|
||||
|
||||
|
||||
def create_employee(self, employees):
|
||||
EmployeeModel = self.env['finger.employee.employee']
|
||||
DepartmentModel = self.env['finger.employee.department']
|
||||
PositionModel = self.env['finger.employee.position']
|
||||
HR = self.env['hr.employee']
|
||||
|
||||
HR = self.env['hr.employee']
|
||||
|
||||
for tx in employees:
|
||||
tirm = EmployeeModel.search([('emp_system_id', '=', tx['id'])])
|
||||
dep = None
|
||||
pos = None
|
||||
hrEmp = None
|
||||
if tx['position'] :
|
||||
if tx['position']:
|
||||
pos = PositionModel.search([('position_id', '=', tx['position'])], limit=1)
|
||||
|
||||
if tx['department'] :
|
||||
if tx['department']:
|
||||
dep = DepartmentModel.search([('department_id', '=', tx['department'])], limit=1)
|
||||
|
||||
if tx['emp_code'] :
|
||||
if tx['emp_code']:
|
||||
hrEmp = HR.search([('emp_no', '=', tx['emp_code'])])
|
||||
|
||||
data = {
|
||||
'emp_system_id': tx['id'],
|
||||
'name': tx['first_name'],
|
||||
'code': tx['emp_code'],
|
||||
'department_id':dep.id if dep else False,
|
||||
'position_id':pos.id if pos else False,
|
||||
'hr_employee':hrEmp.id if hrEmp else False,
|
||||
'server_id': self.id,
|
||||
}
|
||||
'emp_system_id': tx['id'],
|
||||
'name': tx['first_name'],
|
||||
'code': tx['emp_code'],
|
||||
'department_id': dep.id if dep else False,
|
||||
'position_id': pos.id if pos else False,
|
||||
'hr_employee': hrEmp.id if hrEmp else False,
|
||||
'server_id': self.id,
|
||||
}
|
||||
|
||||
if not tirm and hrEmp :
|
||||
if not tirm and hrEmp:
|
||||
EmployeeModel.create(data)
|
||||
elif hrEmp and tirm:
|
||||
tirm.update(data)
|
||||
|
|
@ -490,47 +496,47 @@ class BiotimeAPI(models.Model):
|
|||
empe = None
|
||||
pos = None
|
||||
# "2020-08-09 10:23:20"
|
||||
new_punch_time= datetime.strptime(tx['punch_time'],"%Y-%m-%d %H:%M:%S") + timedelta(hours=-3)
|
||||
new_upload_time= datetime.strptime(tx['upload_time'],"%Y-%m-%d %H:%M:%S") + timedelta(hours=-3)
|
||||
#datetime_format = "%Y-%m-%d %H:%M:%S"
|
||||
new_punch_time = datetime.strptime(tx['punch_time'], "%Y-%m-%d %H:%M:%S") + timedelta(hours=-3)
|
||||
new_upload_time = datetime.strptime(tx['upload_time'], "%Y-%m-%d %H:%M:%S") + timedelta(hours=-3)
|
||||
# datetime_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
if tx['emp_code'] :
|
||||
if tx['emp_code']:
|
||||
empe = EmployeeModel.search([('code', '=', tx['emp_code'])], limit=1)
|
||||
|
||||
if tx['terminal_alias'] :
|
||||
|
||||
if tx['terminal_alias']:
|
||||
dep = TerminalModel.search([('sn', '=', tx['terminal_sn'])], limit=1)
|
||||
data = {
|
||||
'attendance_id': tx['id'],
|
||||
'punch_state': tx['punch_state'],
|
||||
'area_alias': tx['area_alias'],
|
||||
#'crc': tx['crc'],
|
||||
# 'crc': tx['crc'],
|
||||
'crc': tx['emp'],
|
||||
'verify_type': tx['verify_type'],
|
||||
#'is_attendance': tx['is_attendance'],
|
||||
'upload_time': new_upload_time,
|
||||
'punch_time': new_punch_time,
|
||||
'emp_code':empe.id if empe else None,
|
||||
'terminal_id':dep.id if dep else None,
|
||||
# 'is_attendance': tx['is_attendance'],
|
||||
'upload_time': new_upload_time,
|
||||
'punch_time': new_punch_time,
|
||||
'emp_code': empe.id if empe else None,
|
||||
'terminal_id': dep.id if dep else None,
|
||||
'server_id': self.id,
|
||||
'hr_comployee_id': empe.hr_employee.id if empe and empe.hr_employee else None,
|
||||
'emp': empe.code if empe else None
|
||||
}
|
||||
|
||||
|
||||
if not tirm and empe:
|
||||
#print('9999999999999999999999999999999999999999999999999',tirm)
|
||||
# print('9999999999999999999999999999999999999999999999999',tirm)
|
||||
AttendanceModel.create(data)
|
||||
elif empe and tirm:
|
||||
tirm.update(data)
|
||||
|
||||
|
||||
def action_attendance_download(self):
|
||||
now = datetime.now()
|
||||
yesterday = datetime.now() - timedelta(hours=48)
|
||||
now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
yesterday = yesterday.strftime("%Y-%m-%d %H:%M:%S")
|
||||
yesterday = yesterday.strftime("%Y-%m-%d %H:%M:%S")
|
||||
_, _, _, _, _, _, _, _, _, transctionsUrl = self._calc_urls()
|
||||
for r in self:
|
||||
for xm in r.employee_ids :
|
||||
#url = "{}?start_time={}&end_time={}&emp_code={}".format(transctionsUrl,yesterday,now, xm.code )
|
||||
url = "{}?punch_time={}&punch_time={}&emp_code={}".format(transctionsUrl,yesterday,now, xm.code )
|
||||
#print('################################# New Employee',url)
|
||||
r.sync_employee_attenence(url)
|
||||
for xm in r.employee_ids:
|
||||
# url = "{}?start_time={}&end_time={}&emp_code={}".format(transctionsUrl,yesterday,now, xm.code )
|
||||
url = "{}?punch_time={}&punch_time={}&emp_code={}".format(transctionsUrl, yesterday, now, xm.code)
|
||||
# print('################################# New Employee',url)
|
||||
r.sync_employee_attenence(url)
|
||||
Loading…
Reference in New Issue