-
Notifications
You must be signed in to change notification settings - Fork 0
/
flectraclient_rpc.py
46 lines (37 loc) · 1.68 KB
/
flectraclient_rpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from xmlrpc.client import ServerProxy
import json
with open('config.json') as json_data_file:
cfg = json.load(json_data_file)
class FlectraClient:
def __init__(self, username, password):
self.url = cfg["flectra"]["url"]
self.db = cfg["flectra"]["db"]
self.username = username
self.password = password
self.uid = self.getUid()
def getUid(self):
common = ServerProxy('{}/xmlrpc/2/common'.format(self.url))
common.version()
return common.authenticate(self.db, self.username, self.password, {})
def attendance_manual(self, attendance_id):
models = ServerProxy('{}/xmlrpc/2/object'.format(self.url))
return models.execute_kw(self.db, self.uid, self.password,
'hr.employee', 'attendance_manual',
[attendance_id,'hr_attendance.hr_attendance_action_my_attendances'], {})
def attendance_check(self):
models = ServerProxy('{}/xmlrpc/2/object'.format(self.url))
return models.execute_kw(self.db, self.uid, self.password,
'hr.employee', 'search_read',
[[["user_id", "=", self.uid]], ["attendance_state", "name"]], {})
def attendance_checkout(self):
status = self.attendance_check()
if status[0]["attendance_state"] != "checked_out":
return self.attendance_manual(status[0]["id"])
else:
return {'status': 1, 'text': 'already checked out'}
def attendance_checkin(self):
status = self.attendance_check()
if status[0]["attendance_state"] != "checked_in":
return self.attendance_manual(status[0]["id"])
else:
return {'status': 1, 'text': 'already checked in'}