-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathupdate_partners_uy.py
executable file
·43 lines (35 loc) · 1.11 KB
/
update_partners_uy.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
#!/usr/bin/python
import sys
import xmlrpclib
import ssl
import csv
username = 'admin' #the user
pwd = 'demo_uy' #the user
dbname = 'demo_uy' #the database
gcontext = ssl._create_unverified_context()
# Get the uid
sock_common = xmlrpclib.ServerProxy ('http://capacitacion:8069/xmlrpc/common',context=gcontext)
uid = sock_common.login(dbname, username, pwd)
#replace localhost with the address of the server
sock = xmlrpclib.ServerProxy('http://capacitacion:8069/xmlrpc/object',context=gcontext)
f = open('jugadores.csv','rt')
reader = csv.DictReader(f,delimiter='|')
for row in reader:
print row
ref = row['ref']
name = row['name']
partner_id = sock.execute(dbname,uid,pwd,'res.partner','search',[('ref','=',ref)])
if not partner_id:
vals = {
'ref': ref,
'name': name,
}
partner_id = sock.execute(dbname,uid,pwd,'res.partner','create',vals)
else:
uruguay_id = sock.execute(dbname,uid,pwd,'res.country','search',[('name','=','Uruguay')])
if uruguay_id:
vals = {
'country_id': uruguay_id[0]
}
return_id = sock.execute(dbname,uid,pwd,'res.partner','write',partner_id,vals)
print return_id