from odoo import Odoo import json from variables import * def transform(records): equiv_company_ids = [(3,2),(4,1),(1,3)] for record in records: if record.get("company_id"): record["company_id"] = [eq[1] for eq in equiv_company_ids if record.get("company_id") == eq[0]][0] return records #Descargar datos en Json conn1 = Odoo(origin_db,origin_user,origin_pass,origin_host) conn1.authenticate() fields = ["id","name","type","code","company_id","sequence_number_next"] file_name = conn1.download_json("account.journal",fields,transform=transform,limit=0) conn2 = Odoo(url=destination_host,session=destination_session) conn2.load_json("account.journal",file_name,dup=True,field_code=True,field_name=True,field_company=True)
record["discount"] = round(record["discount"], 2) return records #Descargar datos en Jsons conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = [ "id", "name", "product_id", "product_uom_qty", "product_uom", "price_unit", "tax_id", "purchase_price", "order_id", "discount", "customer_lead" ] file_name = conn1.download_json( "sale.order.line", fields, domain=[["order_id", "!=", False], ["order_id.partner_id", "not in", [1, 2, 3, 4, 5, 6]]], transform=transform, order="id ASC", limit=0) conn2 = Odoo(url=destination_host, session=destination_session) #conn2.authenticate() #Eliminar existentes recs = conn2.call_kw("sale.order.line", "search_read", kwargs={"fields": ["id"]}) rec_ids = [rec["id"] for rec in recs] conn2.call_kw("sale.order.line", "unlink", args=[rec_ids]) #Cargar nuevos conn2.load_json("sale.order.line", file_name, threads=30)
][0] return records #Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = [ "id", "name", "login", "email", "mobile", "phone", "employee", "tz_offset", "signature", "street", "active", "customer", "employee", "share", "company_ids", "company_id", "lang", "state" ] file_name = conn1.download_json( "res.users", fields, limit=0, domain=['|', ["active", "=", True], ["active", "=", False]], transform=transform_extract) #conn2 = Odoo(destination_db,destination_user,destination_pass,destination_host) conn2 = Odoo(url=destination_host, session=destination_session) #conn2.authenticate() conn2.load_json("res.users", file_name, dup=True, field_login=True, field_active=True, field_company=True)
boms_dict = json.loads(boms.read()) products = open("product.product_load_20200121.json", "r") products_dict = json.loads(products.read()) uoms = open("product.uom_load_20200121.json", "r") uoms_dict = json.loads(uoms.read()) def transform(record, records): record["bom_id"] = boms_dict[str(record["bom_id"])]["id"] record["product_id"] = products_dict[str(record["product_id"])]["id"] record["product_uom_id"] = uoms_dict[str(record["product_uom_id"])]["id"] return record #Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = ["id", "product_qty", "product_id", "product_uom_id", "bom_id"] file_name = conn1.download_json("mrp.bom.line", fields, limit=0, domain=[]) conn2 = Odoo(destination_db, destination_user, destination_pass, destination_host) conn2.authenticate() #Eliminar Productos #recs = conn2.call_kw("product.product","search_read",kwargs={"fields":["id"]}) #conn2.call_kw("product.product","unlink",args=[[rec["id"] for rec in recs]]) #Cargar Nuevos conn2.load_json("mrp.bom.line", file_name, transform=transform, threads=20)
return records #Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = [ "id", "name", "origin", "invoice_id", "account_id", "quantity", "uom_id", "discount", "price_unit", "invoice_line_tax_ids", "sequence", "product_id", "currency_id" ] file_name = conn1.download_json("account.invoice.line", fields, domain=[["invoice_id", "!=", False]], transform=transform, order="id ASC", limit=0) conn2 = Odoo(url=destination_host, session=destination_session) #Eliminar existentes recs = conn2.call_kw("account.invoice.line", "search_read", kwargs={"fields": ["id"]}) rec_ids = [rec["id"] for rec in recs] conn2.call_kw("account.invoice.line", "unlink", args=[rec_ids]) #Cargar nuevos conn2.load_json("account.invoice.line", file_name, threads=35)
import time import csv from variables import * uoms = open("product.uom_load_20200121.json","r") uoms_dict = json.loads(uoms.read()) def transform(record,records): record["uom_id"] = uoms_dict[str(record["uom_id"])]["id"] record["uom_po_id"] = uoms_dict[str(record["uom_po_id"])]["id"] return record #Descargar datos en Json conn1 = Odoo(origin_db,origin_user,origin_pass,origin_host) conn1.authenticate() fields = ["id","name","sale_ok","purchase_ok","type","default_code","lst_price", "standard_price","uom_id","uom_po_id","active", "description_sale","image"] file_name = conn1.download_json("product.product",fields, limit=0, domain=['|',["active","=",0],["active","=",1]]) conn2 = Odoo(destination_db,destination_user,destination_pass,destination_host) conn2.authenticate() #Eliminar Productos #recs = conn2.call_kw("product.product","search_read",kwargs={"fields":["id"]}) #conn2.call_kw("product.product","unlink",args=[[rec["id"] for rec in recs]]) #Cargar Nuevos conn2.load_json("product.product",file_name,transform=transform,dup=True,field_name=True,threads=10)
def transform(records): equiv_company_ids = [(3, 2), (4, 1), (1, 3)] for record in records: if record.get("company_id"): record["company_id"] = [ eq[1] for eq in equiv_company_ids if record.get("company_id") == eq[0] ][0] return records #Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = [ "id", "name", "sequence", "company_id", "methodo_pago", "note", "active", "display_name" ] file_name = conn1.download_json("account.payment.term", fields, transform=transform, limit=0) conn2 = Odoo(url=destination_host, session=destination_session) conn2.load_json("account.payment.term", file_name, dup=True, field_name=True, field_company=True, field_active=True)
if len(record["user_ids"][0][2]) == 1: old_user_id = record["user_ids"][0][2][0] new_user_id = users_dict[str(old_user_id)]["id"] rec = conn2.call_kw("res.users","search_read",kwargs={"fields":["id","partner_id"], "domain":[["id","=",int(new_user_id)]] }) del record["user_ids"] record["write"] = True record["new_id"] = rec[0]["partner_id"][0] #record.update({"company_id":}) records_final.append(record) return records_final #Descargar datos en Json conn1 = Odoo(origin_db,origin_user,origin_pass,origin_host) conn1.authenticate() fields = ["id","type","name","vat","company_type","city","rfc","x_descuento","trust", "street2","street","mobile","email","zip","customer","active","user_id","company_id","over_credit", "supplier","employee","parent_id","function","phone","ref","create_uid","credit_limit","zip", "uso_cfdi","residencia_fiscal","registro_tributario","x_metodo_pago","x_forma_pago","comment","user_ids"] file_name = conn1.download_json("res.partner",fields,order="parent_id DESC", limit=0, transform=transform_extract, domain=['|','&',["active","=",0],["active","=",1],["id","not in",[4,5,6]]]) conn2 = Odoo(url=destination_host,session=destination_session) #conn2.authenticate() conn2.load_json("res.partner",file_name,dup=True,field_name=True,field_company=True,field_active=True)
eq[1] for eq in equiv_company_ids if record.get("company_id") == eq[0] ][0] return records #Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = [ "id", "company_id", "name", "type_tax_use", "account_type", "amount", "description", "account_id", "tax_exigibility", "cash_basis_account_id", "cash_basis_base_account_id", "tag_ids", "tax_group_id", "price_include", "incluse_base_amount", "impuesta", "tipo_factor", "active" ] file_name = conn1.download_json( "account.tax", fields, transform=transform, limit=0, domain=['|', ["active", "=", 0], ["active", "=", 1]]) conn2 = Odoo(url=destination_host, session=destination_session) conn2.load_json("account.tax", file_name, dup=True, field_name=True, field_active=True, field_company=True)
import json from variables import * def transform(records): equiv_company_ids = [(3, 2), (4, 1), (1, 3)] for record in records: if record.get("company_id"): record["company_id"] = [ eq[1] for eq in equiv_company_ids if record.get("company_id") == eq[0] ][0] return records #Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = ["id", "name", "code", "company_id"] file_name = conn1.download_json("stock.warehouse", fields, transform=transform, limit=0) conn2 = Odoo(url=destination_host, session=destination_session) conn2.load_json("stock.warehouse", file_name, dup=True, field_company=True, field_code=True)
"user_id","tipo_comprobante","uso_cfdi","forma_pago","methodo_pago", "currency_id","origin","folio_fiscal","tipo_relacion", "reference","type","uuid_relacionado","fecha_factura", "refund_invoice_id","estado_factura","confirmacion", "date_due","date_invoice","state","company_id","account_id","discount_rate", "uuid_relacionado","confirmacion","discount","monto","precio_unitario", "monto_impuesto","decimales","desc","qr_value","invoice_datetime", "fecha_factura","rfc_emisor","name_emisor","serie_emisor","tipo_relacion", "numero_cetificado","cetificaso_sat","folio_fiscal","fecha_certificacion", "cadena_origenal","selo_digital_cdfi","selo_sat","moneda","tipocambio", "folio","version","number_folio","amount_to_text","pdf_cdfi_invoice", "qrcode_image","regimen_fiscal","xml_invoice_link","estado_factura", "factura_cfdi","tipo_comprobante","forma_pago"] file_name = conn1.download_json("account.invoice",fields,transform=transform_extract, order="refund_invoice_id ASC", limit=0) conn2 = Odoo(url=destination_host,session=destination_session) #conn2.authenticate() #conn2.call_kw("account.invoice","write",args=[[1455],{"move_name":"","name":"","state":"draft"}]) #conn2.call_kw("account.invoice","unlink",args=[[1455]]) #Eliminar existentes """""" recs = conn2.call_kw("account.invoice","search_read",kwargs={"fields":["id"]}) rec_ids = [int(rec["id"]) for rec in recs] print(rec_ids)
uoms = open("product.uom_load_20200121.json", "r") uoms_dict = json.loads(uoms.read()) def transform(record, records): record["product_tmpl_id"] = product_templates_dict[str( record["product_tmpl_id"])]["id"] record["product_uom_id"] = uoms_dict[str(record["product_uom_id"])]["id"] return record #Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = ["id", "name", "product_qty", "product_tmpl_id", "product_uom_id"] file_name = conn1.download_json( "mrp.bom", fields, limit=0, domain=['|', ["active", "=", 0], ["active", "=", 1]]) conn2 = Odoo(destination_db, destination_user, destination_pass, destination_host) conn2.authenticate() #Eliminar Productos #recs = conn2.call_kw("product.product","search_read",kwargs={"fields":["id"]}) #conn2.call_kw("product.product","unlink",args=[[rec["id"] for rec in recs]]) #Cargar Nuevos conn2.load_json("mrp.bom", file_name, transform=transform, threads=10)
#Descargar datos en Json conn1 = Odoo(origin_db, origin_user, origin_pass, origin_host) conn1.authenticate() fields = [ "id", "name", "partner_id", "confirmation_date", "tipo_documento", "state", "date_order", "company_id", "validity_date", "user_id", "uso_cfdi", "forma_pago", "methodo_pago", "discount_rate", "invoice_status", "origin", "warehouse_id", "payment_term_id" ] file_name = conn1.download_json( "sale.order", fields, transform=transform_extract, order="id ASC", limit=0, domain=[["partner_id", "not in", [1, 2, 3, 4, 5, 6]]]) #Conexión a Nueva Instancia conn2 = Odoo(url=destination_host, session=destination_session) #conn2.authenticate() #Eliminar existentes recs = conn2.call_kw("sale.order", "search_read", kwargs={"fields": ["id"]}) rec_ids = [int(rec["id"]) for rec in recs] print(rec_ids) if conn2.call_kw("sale.order", "write", args=[rec_ids, {"state": "draft"}]): print("Actualización a borrador") else: print("No se puedo actualziar")