public static void Main(string[] args) { // Datos de conexión String Url = "http://localhost:8069"; String Dbname = "test_db"; String Login = "******"; String Password = "******"; // Login OpenERPConnect connection = new OpenERPConnect(Url, Dbname, Login, Password); connection.Login(); Console.WriteLine(connection.UserId); Object[] domain = new Object[3]; // Albaranes de salida ya asignados y sin incidencias domain[0] = new Object[3] { "picking_type_id.code", "=", "outgoing" }; domain[1] = new Object[3] { "state", "=", "assigned" }; domain[2] = new Object[3] { "with_incidences", "=", false }; long[] picking_ids = connection.Search("stock.picking", domain); Console.WriteLine("Albaranes encontrados: {0}", picking_ids.Length); //Los recorremos y les escribimos a todos la misma incidencia foreach (long picking_id in picking_ids) { XmlRpcStruct vals = new XmlRpcStruct(); vals.Add("with_incidences", true); //Lo marcamos como bajo incidencia connection.Write("stock.picking", new long[] { picking_id }, vals); //Escribimos el motivo de la incidencia connection.MessagePost("stock.picking", new long[] { picking_id }, "Stock Incorrecto"); } Console.ReadLine(); }
public static void Main(string[] args) { // Datos de conexión String Url = "http://localhost:8069"; String Dbname = "visiotech_devel"; String Login = "******"; String Password = "******"; // Login OpenERPConnect connection = new OpenERPConnect(Url, Dbname, Login, Password); connection.Login(); Console.WriteLine(connection.UserId); Object[] domain = new Object[3]; domain[0] = "|"; //OR domain[1] = new Object[3] { "state", "=", "confirmed" }; //Esperando materias primas domain[2] = new Object[3] { "state", "=", "ready" }; //Lista para producir long[] production_ids = connection.Search("mrp.production", domain); var prods_data = connection.Read("mrp.production", production_ids, new string[] { "state", "move_lines", "move_created_ids", "name", "product_id" }); foreach (var prod in prods_data) { Console.WriteLine("Procesando: {0}", prod ["name"]); if ((string)prod ["state"] == "confirmed") { connection.Execute("mrp.production", "force_production", new long[] { Convert.ToInt64(((int)prod["id"])) }); //Confirmado -> Listo para producir } // Recorremos las lineas a consumir y les ponemos nº serie int[] moves = (int[])prod["move_lines"]; foreach (long move in moves) { XmlRpcStruct[] move_data = connection.Read("stock.move", new long[] { (long)move }, new string[] { "product_id" }); //buscamos si hay un lote ya creado con el código 0001 para el producto del movimiento Object[] lot_domain = new Object[2]; lot_domain[0] = new Object[3] { "product_id", "=", Convert.ToInt64(((object[])move_data[0]["product_id"])[0]) }; lot_domain[1] = new Object[3] { "name", "=", "0001" }; long[] lot_ids = connection.Search("stock.production.lot", lot_domain); long lot_id = 0; if (lot_ids.Length > 0) { lot_id = lot_ids [0]; } else { XmlRpcStruct vals = new XmlRpcStruct(); vals.Add("name", "0001"); vals.Add("product_id", Convert.ToInt64(((object[])move_data[0]["product_id"])[0])); lot_id = connection.Create("stock.production.lot", vals); } XmlRpcStruct w_vals = new XmlRpcStruct(); w_vals.Add("restrict_lot_id", lot_id); connection.Write("stock.move", new long[] { (long)move }, w_vals); } // Recorremos los productos finales y les ponemos nº serie int[] final_moves = (int[])prod["move_created_ids"]; foreach (long fmove in final_moves) { XmlRpcStruct[] fmove_data = connection.Read("stock.move", new long[] { (long)fmove }, new string[] { "product_id" }); //buscamos si hay un lote ya creado con el código 0001 para el producto del movimiento Object[] flot_domain = new Object[2]; flot_domain[0] = new Object[3] { "product_id", "=", Convert.ToInt64(((object[])fmove_data[0]["product_id"])[0]) }; flot_domain[1] = new Object[3] { "name", "=", "0001" }; long[] flot_ids = connection.Search("stock.production.lot", flot_domain); long flot_id = 0; if (flot_ids.Length > 0) { flot_id = flot_ids [0]; } else { XmlRpcStruct fvals = new XmlRpcStruct(); fvals.Add("name", "0001"); fvals.Add("product_id", Convert.ToInt64(((object[])fmove_data[0]["product_id"])[0])); flot_id = connection.Create("stock.production.lot", fvals); } XmlRpcStruct wf_vals = new XmlRpcStruct(); wf_vals.Add("restrict_lot_id", flot_id); connection.Write("stock.move", new long[] { (long)fmove }, wf_vals); } connection.Execute("mrp.production", "action_production_end", new long[] { Convert.ToInt64(((int)prod["id"])) }); } }
public static void Main(string[] args) { // Datos de conexión String Url = "http://localhost:8069"; String Dbname = "demo_db"; String Login = "******"; String Password = "******"; // Login OpenERPConnect connection = new OpenERPConnect(Url, Dbname, Login, Password); connection.Login(); Console.WriteLine(connection.UserId); // Tengo un albarán en estado asignado, en concreto el id 280, sobre el que voy a hacer el ejemplo ArrayList fields = new ArrayList(); fields.Add("name"); // Núm. albaran fields.Add("partner_id"); // Empresa asociada al albarán fields.Add("state"); // Estado del albarán fields.Add("internal_notes"); // Notas internas fields.Add("move_lines"); // Lineas del albarán long[] picking_ids = new long[] { 280 }; XmlRpcStruct[] pickings_data = connection.Read("stock.picking", picking_ids, (string[])fields.ToArray(typeof(string))); XmlRpcStruct context = new XmlRpcStruct(); context.Add("lang", "es_ES"); foreach (var picking in pickings_data) { Console.WriteLine("Albaran {0} en estado {1}", picking["name"], picking["state"]); if (!picking["partner_id"].Equals(false)) // Si tiene una empresa asociada, obtenemos los datos que nos interesan { Console.WriteLine("- Dirección de envío:"); XmlRpcStruct[] partner_data = connection.Read("res.partner", new long[] { Convert.ToInt64(((object[])picking["partner_id"])[0]) }, new string[] { "name", "street", "zip", "city", "state_id", "country_id" }); //Pedimos que nos devuelva los campos que nos interesan Console.WriteLine("Nombre cliente: {0}", partner_data[0]["name"]); Console.WriteLine("Dirección: {0}", partner_data[0]["street"]); Console.WriteLine("Población: {0}", partner_data[0]["city"]); Console.WriteLine("Cód. Postal: {0}", partner_data[0]["zip"]); if (!partner_data[0]["state_id"].Equals(false)) // Si tiene provincia { XmlRpcStruct[] state_data = connection.Read("res.country.state", new long[] { Convert.ToInt64(((object[])partner_data[0]["state_id"])[0]) }, new string[] { "name" }, context); Console.WriteLine("Provincia: {0}", state_data[0]["name"]); } if (!partner_data[0]["country_id"].Equals(false)) // Si tiene país { XmlRpcStruct[] country_data = connection.Read("res.country", new long[] { Convert.ToInt64(((object[])partner_data[0]["country_id"])[0]) }, new string[] { "name" }, context); Console.WriteLine("País: {0}", country_data[0]["name"]); } } if (!picking["internal_notes"].Equals(false)) { Console.WriteLine("Observaciones: {0}", picking["name"]); } Console.WriteLine("###########################"); // Separación Console.WriteLine("###########################"); // Separación int[] moves = (int[])picking["move_lines"]; foreach (var move in moves) { XmlRpcStruct[] move_data = connection.Read("stock.move", new long[] { (long)move }, new string[] { "product_id", "product_uom_qty", "availability" }); XmlRpcStruct[] product_data = connection.Read("product.product", new long[] { Convert.ToInt64(((object[])move_data[0]["product_id"])[0]) }, new string[] { "default_code", "name", "track_outgoing" }); Console.WriteLine("[{0}] {1}, {2} Unidades pedidas. {3} unidades disponibles. Seriable; {4}", product_data[0]["default_code"], product_data[0]["name"], move_data[0]["product_uom_qty"], move_data[0]["availability"], product_data[0]["track_outgoing"]); // Si es seriable hay que crearle numeros de serie if (!product_data[0]["track_outgoing"].Equals(false)) { // Nº de número de serie a crear int serialNo = Convert.ToInt32(move_data[0]["product_uom_qty"]); XmlRpcStruct move_vals = new XmlRpcStruct(); string lots = ""; int cont = 1; // While hasta que no haya que crear ninguno más while (serialNo > 0) { string serial = cont.ToString("000000"); if (lots.Equals("")) { lots = serial; } else { lots += "," + serial; // Separamos por comas los números de serie } serialNo--; cont++; } move_vals.Add("lots_text", lots); //Informamos de los número de serie del movimiento a Odoo connection.Write("stock.move", new long[] { (long)move }, move_vals); } } } // Procesamos el albarán como siempre pero el sistema debió de separarlo en tantas peraciones como números de serie. connection.Execute("stock.picking", "action_done", new long[] { 280 }); }
public static void Main(string[] args) { // Datos de conexión String Url = "http://localhost:8069"; String Dbname = "test_db"; String Login = "******"; String Password = "******"; // Login OpenERPConnect connection = new OpenERPConnect(Url, Dbname, Login, Password); connection.Login(); Console.WriteLine(connection.UserId); // Nos devuelve todos los ids de empresas ArrayList filters = new ArrayList(); long[] partner_ids = connection.Search("res.partner", filters.ToArray()); ArrayList fields = new ArrayList(); fields.Add("name"); // Leemos para todos los ids de empresas obtenidos arriba el campo nombre. Read siempre nos devuelve el id y los campos pedidos. var partner_data = connection.Read("res.partner", partner_ids, (string[])fields.ToArray(typeof(string))); foreach (var partner in partner_data) { Console.WriteLine("Partner {0} with Id {1}", partner["name"], partner["id"]); } //Comprobarmos que no existe un partner con nombre Prueba Object[] domain = new Object[1]; domain[0] = new Object[3] { "name", "=like", "Prueba%" }; long[] prueba_partner_ids = connection.Search("res.partner", domain); if (prueba_partner_ids.Length > 0) { // El partner ya existe lo borramos Console.WriteLine("Partnes exists"); bool deleted = connection.Unlink("res.partner", prueba_partner_ids); Console.WriteLine("Deleted: {0}", deleted); } else { // El partner no existe lo creamos Console.WriteLine("Partnes not exists"); XmlRpcStruct vals = new XmlRpcStruct(); vals.Add("name", "Prueba"); vals.Add("is_company", true); vals.Add("vat", "ES33552390J"); long new_partner_id = connection.Create("res.partner", vals); Console.WriteLine("New Partner created {0}", new_partner_id); // Le cambiamos el nombre XmlRpcStruct vals2 = new XmlRpcStruct(); vals2.Add("name", "Prueba2"); long[] ids_to_update = new long[1]; ids_to_update[0] = new_partner_id; bool updated = connection.Write("res.partner", ids_to_update, vals2); Console.WriteLine("Updated: {0}", updated); //Mostramos el nuevo nombre var new_partner_data = connection.Read("res.partner", ids_to_update, new string[] { "name" }); foreach (var partner in new_partner_data) { Console.WriteLine("Partner {0} with Id {1}", partner["name"], partner["id"]); } // Como ejemplo del método execute comprobamos si el cif es válido var result = connection.Execute("res.partner", "button_check_vat", ids_to_update); Console.WriteLine("VAT valid: {0}", Convert.ToBoolean(result)); } Console.ReadLine(); }