def transform_extract(records):
    equiv_company_ids = [(3,2),(4,1),(1,3)]
    conn2 = Odoo(url=destination_host,session=destination_session)
    records_final = []
    for record in records:
        if record["user_ids"]:
            if record["user_id"]:
                if users_dict.get(str(record["user_id"]),False):
                    record["user_id"] = users_dict[str(record["user_id"])]["id"]

            if record["create_uid"]:
                if users_dict.get(str(record["create_uid"]),False):
                    record["create_uid"] = users_dict[str(record["create_uid"])]["id"]

            if record.get("company_id"):
                record["company_id"] = [eq[1] for eq in equiv_company_ids
                                                if record.get("company_id") == eq[0]][0]
                                                
            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
        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)
    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)
            "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)


for rec in [rec_ids[x:x+20] for x in range(0,len(rec_ids),20)]:
    print(rec)
    print(conn2.call_kw("account.invoice","write",args=[rec,{"move_name":"","name":"","state":"draft"}]))

for rec in [rec_ids[x:x+20] for x in range(0,len(rec_ids),20)]:
    print(rec)
    print(conn2.call_kw("account.invoice","unlink",args=[rec]))

#conn2.load_json("account.invoice",file_name,dup=True,transform=transform_load,field_name=True,field_company=True)
conn2.load_json("account.invoice",file_name,transform=transform_load,field_company=True)
products = conn1.call_kw("product.template","search_read",kwargs={"fields":fields})

for x in products:
    print(x)

company = conn1.call_kw("res.company","search_read",kwargs={"fields":["name","currency_id"]})
print(company)
"""
#conn1 = Odoo("highlanddb_oct_final_migra","admin","admin","localhost:8827")
#conn1 = Odoo("5WI1q4kLj2_db","admin","admin","htc.facturacion.vip")

conn1 = Odoo("naomis_db_13_nov", "yeyson5", "Elbaronrojo5", "localhost:8827")
conn1.authenticate()

productos = conn1.call_kw(
    "product.product",
    "search_read",
    kwargs={"fields": ["id", "name", "categ_id", "standard_price"]})
productos_dict = {}
for product in productos:
    productos_dict.update({
        product["id"]:
        [product["name"], product["categ_id"][1], product["standard_price"]]
    })

pos_orders = conn1.call_kw("pos.order",
                           "search_read",
                           kwargs={
                               "fields": [
                                   "id", "partner_id", "invoice_id",
                                   "date_order", "amount_total", "lines"
                               ]
Exemple #6
0
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")

if conn2.call_kw("sale.order", "unlink", args=[rec_ids]):
    print("eliminacion de Ventas")

conn2.load_json("sale.order", file_name, threads=35)
Exemple #7
0
            province_id = str(partner["province_id"][1] if partner["province_id"] else "")
            district_id = str(partner["district_id"][1] if partner["district_id"] else "")
            customer = str(partner["customer"])
            supplier = str(partner["supplier"])
            linea_credito = str(partner["linea_credito"])
            employee = str(partner["employee"])
            parent_id = partner["parent_id"][1] if partner["parent_id"] else ""
            function = str(partner["function"])
            phone = str(partner["phone"])
            
            row = [idx,tipo,name,catalog_06_id,vat,company_type,estado_contribuyente,
                    registration_name,street,mobile,email,ubigeo,country_id,
                    state_id,province_id,district_id,customer,supplier,linea_credito,
                    employee,parent_id,function,phone]

            partner_writer.writerow(row)
"""

conn = Odoo("IW94Do1PeS_db", "admin", "adm1n*2019-11", "erp.highlandtc.com",
            True)
conn.authenticate()

lista = conn.call_kw("res.partner",
                     "search_read",
                     kwargs={
                         "domain":
                         ['|', ["active", "=", 0], ["active", "=", 1]],
                         "fields": ["name", "active"]
                     })

print([x for x in lista if x["active"]])
Exemple #8
0
from odoo import Odoo
conn = Odoo("santaclara_db_1","admin","admin","localhost:8827",False)
conn.authenticate()

l  =conn.call_kw("product.product","search_read",
                    kwargs={'fields':['name','product_tmpl_id',"list_price"],'limit':10,'domain':[['name','ilike','3XXX MARACUYA 1.8LT']]})

print(l)
l  =conn.call_kw("product.product","read",[[5494],["name",'display_name']],kwargs={"context":{"bin_size":True,"params":{"action":119}}})
                          
print(l)
conn.call_kw("product.template","write",[[5495],{"name":"3XXX MARACUYA 1.8LT *XYZ123*****","list_price":2003.33}])
#l  =conn.call_kw("product.template","read",args=[[5495],['name']])
#print(l)
#DOWNLOAD PARTNERS
"""
fields = ["id","type","name","catalog_06_id","vat","company_type","estado_contribuyente",
            "registration_name","street","mobile","email","zip","customer",
            "supplier","linea_credito","employee","parent_id","function","phone"]
"""
#conn.download_json("res.partner",fields,order="parent_id DESC",limit=0)



#DOWNLOAD LÍNEA DE COMPROBANTES
fields = []
#conn.download_json("account.invoice.line",fields)

#DOWNLOAD COMPROBANTES
"""
fields = ["id","number","move_name","date_order","partner_id","journal_id","tipo_operacion",
from odoo import Odoo
import json
from variables import *

conn2 = Odoo(url=destination_host,session=destination_session)
#conn2 = Odoo(origin_db,origin_user,origin_pass,origin_host)
#conn2.authenticate()

recs = conn2.call_kw("account.invoice","search_read",kwargs={"fields":["id"]})
rec_ids = [rec["id"] for rec in recs]
print(rec_ids)
#print(conn2.call_kw("account.invoice","write",args=[rec,{"move_name":"","name":"","state":"draft"}]))
salto = 30
for rec in [rec_ids[x:x+salto] for x in range(0,len(rec_ids),salto)]:
    print(rec)
    conn2.call_kw("account.invoice","compute_taxes",args=[rec])