~anna-g/micronaet/anna

« back to all changes in this revision

Viewing changes to base_syncro_ecologia/etl/analisi.py

  • Committer: Anna Micronaet
  • Date: 2013-07-18 09:08:36 UTC
  • Revision ID: anna@micronaet.it-20130718090836-ssmst48rrnvcd69w
Tolti tutti i moduli

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
# List field and first 5 element of table in argv
3
 
import xmlrpclib,ConfigParser,sys
4
 
 
5
 
# Set up parameters (for connection to Open ERP Database) ********************************************
6
 
# Set up parameters (for connection to Open ERP Database) ********************************************
7
 
config = ConfigParser.ConfigParser()
8
 
config.read(['openerp.cfg']) # if file is in home dir add also: , os.path.expanduser('~/.openerp.cfg')])
9
 
dbname=config.get('dbaccess','dbname')
10
 
user=config.get('dbaccess','user')
11
 
pwd=config.get('dbaccess','pwd')
12
 
server=config.get('dbaccess','server')
13
 
port=config.get('dbaccess','port')   # verify if it's necessary: getint
14
 
 
15
 
# For final user: Do not modify nothing below this line (Python Code) ********************************
16
 
sock = xmlrpclib.ServerProxy('http://' + server + ':' + port + '/xmlrpc/common')
17
 
uid = sock.login(dbname ,user ,pwd)
18
 
sock = xmlrpclib.ServerProxy('http://' + server + ':' + port + '/xmlrpc/object')
19
 
 
20
 
tabella='res.partner'
21
 
 
22
 
tabella_id = sock.execute(dbname, uid, pwd, tabella, 'search', []) 
23
 
tabella_campi=sock.execute(dbname,uid,pwd,tabella,'read',tabella_id)
24
 
tot={'partner':0, 'customer':0, 'supplier':0, 'both': 0, 'address': 0, 'address_extra': 0}
25
 
 
26
 
for elemento in tabella_campi:
27
 
   tot['partner'] += 1
28
 
   if elemento['customer']:
29
 
      tot['customer'] += 1
30
 
   if elemento['supplier']:
31
 
      tot['supplier'] += 1
32
 
   if elemento['supplier'] and elemento['customer']:
33
 
      tot['both'] += 1
34
 
   if elemento['address']:
35
 
      tot['address'] += len(elemento['address']) 
36
 
tot['address_extra'] += tot['address'] - tot['partner']
37
 
 
38
 
print "Totale:       \t%s" % (tot['partner'],)
39
 
print "Customer:     \t%s" % (tot['customer'],)
40
 
print "Supplier:     \t%s" % (tot['supplier'],)
41
 
print "C + S:        \t%s" % (tot['both'],)
42
 
print "Address:      \t%s" % (tot['address'],)
43
 
print "Address extra:\t%s" % (tot['address_extra'],)
44