Io mi trovo bene con uno script tipo così, con cui aggiorno l'IVA di tutti i prodotti e quella standard:
import xmlrpclib
import pickle
class connector(object):
def __init__(self, username, pwd, dbname, host, port):
self.pwd = pwd
self.dbname = dbname
sock_common = xmlrpclib.ServerProxy('http://' + host + ':' + port + '/xmlrpc/common')
self.uid = sock_common.login(self.dbname, username, self.pwd)
self.sock = xmlrpclib.ServerProxy('http://' + host + ':' + port + '/xmlrpc/object')
def sock_search(self, obj, arg):
res = self.sock.execute(self.dbname, self.uid, self.pwd, obj, 'search', arg)
return res
def sock_write(self, obj, arg, values):
self.sock.execute(self.dbname, self.uid, self.pwd, obj, 'write', arg, values)
def update_sale_vat(self):
ids = self.sock_search('ir.values', [('name','=','taxes_id')])
vat_values = self.sock_search('account.tax', [('description','=','22v')])
for id in ids:
self.sock_write('ir.values', id, {'value': pickle.dumps(vat_values)})
def update_purchase_vat(self):
ids = self.sock_search('ir.values', [('name','=','supplier_taxes_id')])
vat_values = self.sock_search('account.tax', [('description','=','22a')])
for id in ids:
self.sock_write('ir.values', id, {'value': pickle.dumps(vat_values)})
def update_all_product(self):
ids = self.sock_search('product.product', [])
#update purchase vat
supp_vat_id = self.sock_search('account.tax', [('description','=','22a')])
for id in ids:
self.sock_write('product.product', id, {'supplier_taxes_id': [(6,0,supp_vat_id)]})
#update sale vat
vat_id = self.sock_search('account.tax', [('description','=','22v')])
for id in ids:
self.sock_write('product.product', id, {'taxes_id': [(6,0,vat_id)]})