1
votes

I'm trying to create a complete order (with order lines) with openERP XMLRPC. I've got this:

order = [
   'shop_id': 1,
   'state': 'draft',
   'date_order': '2013-09-01',
   'user_id': 1,
   'partner_id': 7,
   'partner_invoice_id': 1,
   'partner_order_id': 1,
   'partner_shipping_id': 1,
   'picking_policy': 'direct',
   'order_policy': 'manual',
   'pricelist_id': 1,
   'note': 'note',
   'lines': [
            [
                'qty': 1,
                'product_id': 1,
            ]
        ],
]

order_id = openerp.execute(dbname, uid, pwd, 'sale.order', 'create', order)

it effectively creates a sales order, but without any order line... any advice for me? I'm looking for a solution for hours

2

2 Answers

4
votes

First, the one2many field of sale.order which references sale.order.line is order_lines, not lines.

Secondly, the field labelled "Quantity" on sale.order.line is product_uom_qty, not qty.

Thirdly, it is necessary to specify the function to be performed on the model referenced by the one2many field. You want to create records on sale.order.line. (You don't want to link existing sales order lines to the new order, for instance.)

I am unfamiliar with groovy syntax. In any case, the ORM method should receive a list of tuples for the value of the one2many field. Each tuple corresponds to an order line and the first item of the tuple identifies the function to be performed on sale.order.line. In the case of creation, the second item of the tuple is superfluous, and the third item defines the created record on the related table.

In python you would do this:

order = {
    'shop_id': 1,
    'state': 'draft',
    'date_order': '2013-09-01',
    'user_id': 1,
    'partner_id': 7,
    'partner_invoice_id': 1,
    'partner_order_id': 1,
    'partner_shipping_id': 1,
    'picking_policy': 'direct',
    'order_policy': 'manual',
    'pricelist_id': 1,
    'note': 'note',
    'order_line': [
        (0, 0, {
            'product_uom_qty': 1,
            'product_id': 1,
        }),
    ],
}
0
votes

This code is a basis for how you can get the number and names of database in odoo, just create the correct package to it. And you need to add the following libraries to your java development environment 1.xmlrpc-client 2.xmlrpc-common 3.xmlrpc-server 4.ws-commons-util 5.xmlrpc you will find them here once you understand this you will figure out how to do the rest

public class odooServices {
private Object[] params;
//private Object[] params;

public Vector<String> getDatabaseList(String host, int port){
Vector<String> res = null;
    try {
        XmlRpcClient xmlrpcDb = new XmlRpcClient();

        XmlRpcClientConfigImpl xmlrpcConfigDb = new XmlRpcClientConfigImpl();
        xmlrpcConfigDb.setEnabledForExtensions(true);
    try {       
        xmlrpcConfigDb.setServerURL(new URL("http",host,port,"/xmlrpc/db"));
    } catch (MalformedURLException ex) {
        Logger.getLogger(odooServices.class.getName()).log(Level.SEVERE, null, ex);
    }

        xmlrpcDb.setConfig(xmlrpcConfigDb);  
          //Retrieve databases
          Vector<Object> params = new Vector<Object>();
          Object result = xmlrpcDb.execute("list", params);
          Object[] a = (Object[]) result;

           res = new Vector<String>();
          for (int i = 0; i < a.length; i++) {
          if (a[i] instanceof String)
          {
            res.addElement((String)a[i]);
            System.out.println((String)a[i]);

          }
        }
    } catch (XmlRpcException ex) {
        Logger.getLogger(odooServices.class.getName()).log(Level.SEVERE, null, ex);
    }
    return res;


}

public int Connect(String host, int port, String tinydb, String login, String password){

try {
      XmlRpcClient xmlrpcLogin = new XmlRpcClient();

      XmlRpcClientConfigImpl xmlrpcConfigLogin = new   XmlRpcClientConfigImpl();
      xmlrpcConfigLogin.setEnabledForExtensions(true);
      xmlrpcConfigLogin.setServerURL(new   URL("http",host,port,"/xmlrpc/common"));

      xmlrpcLogin.setConfig(xmlrpcConfigLogin);


        //Connect
        params = new Object[] {tinydb,login,password};
        Object id = xmlrpcLogin.execute("login", params);
        System.out.println(id);
        if (id instanceof Integer)
          return (Integer)id;
        return -1;



    } catch (XmlRpcException ex) {
        Logger.getLogger(odooServices.class.getName()).log(Level.SEVERE,     null, ex);
    }
  catch (MalformedURLException ex)
  {
Logger.getLogger(odooServices.class.getName()).log(Level.SEVERE,        null, ex);
 }
    return 0;
}
}  

package odoo.webservice;




public class OdooWebservice extends javax.swing.JFrame{

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    odooServices odoo = new odooServices();
    odoo.getDatabaseList("127.0.0.1", 8069);
}
}