PARSER.add_option("-p", "--protocoles", dest="protocoles", default='http', help="protocole http/https source") PARSER.add_option("-D", "--dbc", dest="dbc", default='testmulti', help="Nom de la base cible ") PARSER.add_option("-U", "--userc", dest="userc", default='terp', help="User Openerp cible") PARSER.add_option("-W", "--passwdc", dest="passwdc", default='terp', help="mot de passe Openerp cible ") PARSER.add_option("-S", "--serveurc", dest="hostc", default='127.0.0.1', help="Adresse Serveur cible") PARSER.add_option("-O", "--portc", dest="portc", default='8090', help="port du serveur cible") PARSER.add_option("-P", "--protocolec", dest="protocolec", default='http', help="protocole http/https cible") (OPTIONS, ARGUMENTS) = PARSER.parse_args() BASECIBLE = OPTIONS.dbc BASESOURCE = OPTIONS.dbs CONNECTION_CIBLE = openerp_connection.openerp(OPTIONS.protocolec + '://', OPTIONS.hostc, OPTIONS.portc, BASECIBLE, OPTIONS.userc, OPTIONS.passwdc) CONNECTION_SOURCE = openerp_connection.openerp(OPTIONS.protocoles + '://', OPTIONS.hosts, OPTIONS.ports, BASESOURCE, OPTIONS.users, OPTIONS.passwds) print "CONNECTION_SOURCE ", CONNECTION_SOURCE print "CONNECTION_CIBLE ", CONNECTION_CIBLE invoice_ids = CONNECTION_SOURCE.search('account.invoice', [('date_invoice', '>=', '2013-03-18')], 0, 100000) invoice_fields_type = CONNECTION_CIBLE.exec_act('account.invoice', 'fields_get') invoice_line_fields_type = CONNECTION_CIBLE.exec_act('account.invoice.line', 'fields_get') for invoice_id in invoice_ids: invoice = CONNECTION_SOURCE.read('account.invoice', invoice_id) invoice.pop('invoice_line')
parser.add_option("-d", "--db", dest="db", default="terp", help="Nom de la base ") parser.add_option("-U", "--user", dest="user", default="admin", help="User Openerp") parser.add_option("-W", "--passwd", dest="passwd", default="admin", help="mot de passe OpenERP") parser.add_option("-u", "--userdb", dest="userdb", default="postgres", help="User de la base") parser.add_option("-w", "--passwddb", dest="passwddb", default="admin", help="mot de passe du user de la base") parser.add_option("-H", "--host", dest="host", default="192.168.12.252", help="Adresse Serveur") parser.add_option("-p", "--port", dest="port", default="8069", help="port du serveur") parser.add_option("-P", "--protocole", dest="protocole", default="http", help="protocole http/https") parser.add_option("-m", "--module", dest="module", default="None", help="module a supprimer") (options, args) = parser.parse_args() try: connect_db = openerp_db(options.protocole + "://", options.host, options.port) connection = openerp( options.protocole + "://", options.host, options.port, options.db, options.user, options.passwd ) module_exec = module_object(connection) except Exception, e: print "Erreur de connection ", e sys.exit(1) module_exec.update_list() module_exec.clean_all() module_ids = connection.search("ir.module.module", [("state", "in", ("uninstallable",))]) res = None if options.module != "None": module_id = connection.search("ir.module.module", [("name", "=", options.module)]) if module_id: module_ids.append(module_id[0])
# -*- encoding: utf-8 -*- import openerp_connection connection=openerp_connection.openerp('http://','127.0.0.1','8069','terp','admin','admin') for id in connection.search('account.account'): print connection.read('account.account',id)
parser.add_option("-d", "--db", dest="db", default='terp', help="Nom de la base ") parser.add_option("-U", "--user", dest="user", default='terp', help="User Openerp") parser.add_option("-W", "--passwd", dest="passwd", default='terp', help="mot de passe Openerp ") parser.add_option("-H", "--host", dest="host", default='127.0.0.1', help="Adresse Serveur") parser.add_option("-p", "--port", dest="port", default='8069', help="port du serveur") parser.add_option("-P", "--protocole", dest="protocole", default='https', help="protocole http/https") (options, args) = parser.parse_args() user = options.user pwd = options.passwd base = options.db host = options.host port = options.port prot = options.protocole connection = openerp(prot + '://', serveur, port, base, user, pwd) compte_de_banque = connection.search('account.account', [('code', 'like', '51%')], 0, 80000, 'code') compte_partenaire = connection.search('account.account', [('code', 'like', '4%'), ('type', 'in', ('payable', 'receivable'))], 0, 80000, 'code') tva_ids = connection.search('account.account', [('code', 'like', '445%')], 0, 80000, 'code') compte_retenue = connection.search('account.account', [('code', 'like', '341200%')], 0, 80000, 'code') class Memoize: def __init__(self, fonction): self.fonction = fonction self.memoized = {} def __call__(self, *args): try:
def migration(OPTIONS): BASECIBLE = OPTIONS.dbc BASESOURCE = OPTIONS.dbs if OPTIONS.userc == 'terp': OPTIONS.userc = "admin" OPTIONS.passwdc = "admin" if OPTIONS.dbc == 'terp': OPTIONS.dbc = OPTIONS.dbs print print "-" * 80 print X = 1 START = datetime.now() if OPTIONS.createdb: try: os.remove("/media/mint/migration-%s.sqlite" % BASESOURCE) except: pass fname = "/tmp/%s_model.sql" % BASECIBLE if os.path.exists(fname): os.system('dropdb %s ' % BASECIBLE) os.system("createdb --encoding='unicode' %s " % BASECIBLE) load_cmd = 'psql -f %s %s >/tmp/load.log' % (fname, BASECIBLE) retval = os.system(load_cmd) if retval != 0: sys.exit(1) CONNECTION_CIBLE = openerp_connectionv7.openerp(OPTIONS.protocolec + '://', OPTIONS.hostc, OPTIONS.portc, BASECIBLE, 'admin', OPTIONS.passwdadmin) connectionsource = openerp_connection.openerp(OPTIONS.protocoles + '://', OPTIONS.hosts, OPTIONS.ports, OPTIONS.dbs, OPTIONS.users, OPTIONS.passwds) migration = MigrationLib(connectionsource, CONNECTION_CIBLE, X, OPTIONS) migration.connect_pg() migration.passwordsource = OPTIONS.passwds migration.controle_data() migration.clean_source_db() else: recree_db(OPTIONS) CONNECTION_CIBLE = openerp_connectionv7.openerp(OPTIONS.protocolec + '://', OPTIONS.hostc, OPTIONS.portc, BASECIBLE, 'admin', OPTIONS.passwdadmin) connectionsource = openerp_connection.openerp(OPTIONS.protocoles + '://', OPTIONS.hosts, OPTIONS.ports, OPTIONS.dbs, OPTIONS.users, OPTIONS.passwds) migration = MigrationLib(connectionsource, CONNECTION_CIBLE, X, OPTIONS) migration.passwordsource = OPTIONS.passwds migration.connect_pg() migration.controle_data() migration.clean_source_db() print u"base créé ", datetime.now() - START CONNECTION_CIBLE.object.execute(CONNECTION_CIBLE.dbname, CONNECTION_CIBLE.uid, CONNECTION_CIBLE.pwd, 'base.module.update', 'create', {}) CONNECTION_CIBLE.object.execute(CONNECTION_CIBLE.dbname, CONNECTION_CIBLE.uid, CONNECTION_CIBLE.pwd, 'base.module.update', 'update_module', [1]) DB_MODULE = openerp_connectionv7.module(CONNECTION_CIBLE) DB_MODULE.install('multi_company') DB_MODULE.install('auth_crypt') DB_MODULE.install('uni_otp') DB_MODULE.install('uni_account') DB_MODULE.install('base_vat') DB_MODULE.install('uni_features') source_module_ids = connectionsource.search('ir.module.module', [('state', '=', 'installed')]) cible_module_ids = CONNECTION_CIBLE.search('ir.module.module', []) cible_modules = {} for cible_module_id in cible_module_ids: cible_module = CONNECTION_CIBLE.read('ir.module.module', cible_module_id) cible_modules[cible_module['name']] = cible_module_id source_modules = {} for source_module_id in source_module_ids: source_module = connectionsource.read('ir.module.module', source_module_id) if "hr_timesheet_invoice" in source_module['name']: migration.hr = True print "HR OK" if source_module['name'] == 'school': source_module['name'] = 'uni_school' source_modules[source_module['name']] = source_module_id for source_module in source_modules: if source_module in cible_modules: cible_module_id = cible_modules[source_module] cible_module = CONNECTION_CIBLE.read('ir.module.module', cible_module_id) if cible_module['state'] != 'installed': DB_MODULE.install(module_id=[cible_module_id]) print "Fin installation modules" actserver_ids = CONNECTION_CIBLE.search('ir.actions.server', [], 0, 1000) CONNECTION_CIBLE.unlink('ir.actions.server', actserver_ids) else: CONNECTION_CIBLE = openerp_connectionv7.openerp(OPTIONS.protocolec + '://', OPTIONS.hostc, OPTIONS.portc, BASECIBLE, 'admin', OPTIONS.passwdadmin) connectionsource = openerp_connection.openerp(OPTIONS.protocoles + '://', OPTIONS.hosts, OPTIONS.ports, OPTIONS.dbs, OPTIONS.users, OPTIONS.passwds) migration = MigrationLib(connectionsource, CONNECTION_CIBLE, X, OPTIONS) migration.connect_pg() migration.controle_data() migration.clean_source_db() BASESOURCE = OPTIONS.dbs try: print print "-" * 80 print print "Migration %s" % BASESOURCE print try: migration.pass_admin_new_base = 'uniforme' migration.load_fields() #if OPTIONS.createdb == 'true': vals = migration.get_values(1, 'res.company', ['name']) if 'account_id' in vals: vals['account_id'] = 1 vals['name'] = BASESOURCE if X == 1: if 'partner_id' in vals: vals['partner_id'] = 1 CONNECTION_CIBLE.write('res.company', 1, vals) company_id = 1 elif not CONNECTION_CIBLE.search('res.company', [('name', '=', BASESOURCE)]): vals['partner_id'] = CONNECTION_CIBLE.create('res.partner', {'name': BASESOURCE}) company_id = CONNECTION_CIBLE.create('res.company', vals) except BaseException, e: EXC_TYPE, EXC_VALUE, EXC_TRACEBACK = sys.exc_info() print "*** print_exception:" traceback.print_exception(EXC_TYPE, EXC_VALUE, EXC_TRACEBACK, limit=2, file=sys.stdout) sys.exit() if OPTIONS.module == 'all' or OPTIONS.module == 'base': migration.migre_base_data() if OPTIONS.module == 'all' or OPTIONS.module == 'partner': migration.migre_partner() if OPTIONS.module == 'all' or OPTIONS.module == 'product': migration.migre_product() if OPTIONS.module == 'all' or OPTIONS.module == 'compta': migration.init() migration.migre_compta() migration.controle_tables() migration.deconnect_pg() END = datetime.now() print "Fin Migration %s en %s" % (BASESOURCE, END - START) mailmsg = "Fin Migration %s en %s" % (BASESOURCE, END - START) mail_envoye = MIMEText(str(mailmsg)) mail_envoye['From'] = "*****@*****.**" mail_envoye['Subject'] = "Migration %s " % BASESOURCE mail_envoye['To'] = '*****@*****.**' #envoi = SMTP('192.168.12.15') envoi = SMTP('smtp.free.fr') envoi.sendmail(mail_envoye['From'], ['*****@*****.**'], mail_envoye.as_string()) X += 1
parser.add_option("-U", "--user", dest="user", default="terp", help="User Openerp") parser.add_option("-W", "--passwd", dest="passwd", default="terp", help="mot de passe Openerp ") parser.add_option("-H", "--host", dest="host", default="127.0.0.1", help="Adresse Serveur") parser.add_option("-p", "--port", dest="port", default="8069", help="port du serveur") parser.add_option("-P", "--protocole", dest="protocole", default="https", help="protocole http/https") (options, args) = parser.parse_args() user = options.user pwd = options.passwd base = options.db host = options.host port = options.port prot = options.protocole connection = openerp_connection.openerp(prot + "://", host, port, base, user, pwd) move_ids = connection.search("account.move", [], 0, 8000000) def date_periode(period_id): periode = connection.read("account.period", period_id, ["date_start", "date_stop"]) return [periode["date_start"], periode["date_stop"]] date_dif_periode = 0 date_dif_move_periode = 0 ligne_dif_move = 0 len_move = len(move_ids) x = 0 for move_id in move_ids: x += 1