Repository navigation
Expand file tree
/
Copy pathtinylib.py
More file actions
executable file
·82 lines (59 loc) · 3.87 KB
/
Copy pathtinylib.py
File metadata and controls
executable file
·82 lines (59 loc) · 3.87 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import os
import ssl
from xmlrpclib import ServerProxy, Error
class TinyXMLRPC:
def __init__(self, username, password, database, base_url):
self.username = username
self.password = password
self.database = database
self.base_url = base_url
self._connect()
self._login()
def _connect(self):
# Since python 2.7.9 ssl check ca-cetificates thus we need to give
# system's trusted certificates
ssl_context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
self._common_server = ServerProxy(os.path.join(self.base_url, "common"),
context=ssl_context)
self._object_server = ServerProxy(os.path.join(self.base_url, "object"),
context=ssl_context)
self._wizard_server = ServerProxy(os.path.join(self.base_url, "wizard"),
context=ssl_context)
def _login(self):
self.user_id = self._common_server.login(self.database, self.username, self.password)
def execute(self, *params):
return self._object_server.execute(self.database, self.user_id, self.password, *params)
def wizard(self, *params):
return self._wizard_server.execute(self.database, self.user_id, self.password, *params)
class TinyServer (TinyXMLRPC):
# return a list of analytical accounts matching the search
# each account is a list [ account_id, account_name ]
def search_account(self, search):
return self.execute("account.analytic.account", "name_search", search)
def search_project(self, search, timesheetable_only):
if timesheetable_only:
conds = [["state", "=", "open"], ["use_timesheets", "=", "1"]]
else:
conds = []
return self.execute("project.project", "name_search", search, conds, "ilike", {"lang": "fr_FR", "name_search": search})
def search_task(self, account_id, search):
return self.execute("project.task", "name_search", search, [["state", "=", "open"]], "ilike", {"lang": "fr_FR", "name_search": search, "account_id": account_id})
def search_timesheet(self, date):
return self.execute("hr_timesheet_sheet.sheet", "search", [["user_id", "=", self.user_id], ["state", "=", "draft"], ["date_from", "<=", date]], 0.0, 80.0, 0, {"lang": "fr_FR", "active_ids": [], "active_id": 480})
def timesheet_defaults(self):
return self.execute("hr.analytic.timesheet", "default_get", ["user_id", "account_id", "general_account_id", "product_uom_id", "journal_id", "name", "to_invoice", "amount", "unit_amount", "activity", "date", "product_id"], {"lang": "fr_FR", "user_id": self.user_id})
def attendance_defaults(self):
return self.execute("hr.attendance", "default_get", ["action", "employee_id"], {"lang": "fr_FR", "user_id": self.user_id})
def current_timesheet_wiz(self):
return self.wizard(208, {"form": {}, "ids": [], "report_type": "pdf", "model": "ir.ui.menu", "id": 481}, "init", {"lang": "fr_FR"})
def invoice_factor(self, something):
return self.execute("hr_timesheet_invoice.factor", "name_get", [something], {"lang": "fr_FR"})
def on_change_unit_amount(self, product_id, amount, product_uom_id):
return self.execute("hr.analytic.timesheet", "on_change_unit_amount", [], product_id, amount, product_uom_id)
def on_change_account_id(self, account_id):
return self.execute("hr.analytic.timesheet", "on_change_account_id", [], account_id)
def timesheet_create(self, ts_lines, att_lines):
return self.execute("hr_timesheet_sheet.sheet", "create", {"timesheet_ids": ts_lines, "user_id": self.user_id, "name": "2011 Semaine 4", "date_from": date_from, "attendances_ids": att_lines, "date_current": date_current, "date_to": date_to}, {"lang": "fr_FR", "active_ids": active_ids, "active_id": active_id})
def timesheet_write(self, ts_id, ts_lines, att_lines=[]):
return self.execute("hr_timesheet_sheet.sheet", "write", [ts_id], {"timesheet_ids": ts_lines, "attendances_ids": att_lines}, {"lang": "fr_FR", "active_ids": [], "read_delta": 0.0, "active_id": 0})