-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_odoo_external_api.py
More file actions
66 lines (58 loc) · 2.15 KB
/
test_odoo_external_api.py
File metadata and controls
66 lines (58 loc) · 2.15 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
import datetime
import xmlrpc.client
url = 'http://localhost:8069'
db = 'wh'
username = 'admin'
password = 'admin'
def authenticate(url, db, username, password):
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
if uid:
print('Authenticated as', username)
else:
raise Exception('Authentication failed')
return uid
def create_partner(url, db, uid, password):
print('aoikoawkowa')
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
partner_id = models.execute_kw(db, uid, password, 'res.partner', 'search_read', [[['email', '=', 'william@gmail.comd']]], {'fields': ['id', 'name','email'], 'limit': 1})
print(partner_id)
if partner_id:
id_partner = partner_id[0].get('id')
name_partner = partner_id[0].get('name')
email_partner = partner_id[0].get('email')
print(partner_id[0].get('id'))
elif not partner_id:
partner_id = models.execute_kw(db, uid, password, 'res.partner', 'search_read', [[['email', '=', 'william@gmail.comd']]], {'fields': ['id', 'name','email'], 'limit': 1})
print("awlowkoaw")
exit()
time_now = datetime.datetime.now()
partner_data = {
'partner_id':id_partner,
'name': "TEST APPS",
'user_id': uid,
'team_id':1,
'company_id':1,
'email_from': email_partner,
# 'priority':3,
'description':"TEST",
'type':"opportunity",
'active': True,
# 'date_open': time_now,
# 'date_last_stage_update': time_now,
# 'create_date': time_now,
# 'write_date': time_now,
}
partner_id = models.execute_kw(db, uid, password, 'crm.lead', 'create', [partner_data])
print('Created partner with ID:', partner_id)
return partner_id
# def create_contact(email):
# models.execute_kw(db, uid, password, 'crm.lead', 'create', [partner_data])
def main():
try:
uid = authenticate(url, db, username, password)
create_partner(url, db, uid, password)
except Exception as e:
print("Error:", e)
if __name__ == '__main__':
main()