Search code examples
odooodoo-8odoo-9odoo-10

Adding products to a new sales quote through the Odoo API (Java)


I'm creating new sales quotes programatically through the Odoo API like so:

final Object orderLineItem = asList((Object[]) models.execute("execute_kw", asList(
    db, uid, password,
    "sale.order.line", "search",
    asList(asList()),
    new HashMap() {{
      put("limit", 10);
    }})
  )).get(0);

final Integer id = (Integer) models.execute("execute_kw", asList(
    db, uid, password,
    "sale.order", "create",
    asList(new HashMap() {{
      put("currency_id", resCurrency);
      put("date_order", dateTime);
      put("partner_id", resPartnerId);
      put("picking_policy", "");
      put("pricelist_id", productPricelistId);
      put("name", name);
      put("warehouse_id", stockWarehouseId);
      put("partner_invoice_id", resPartnerId);
      put("partner_shipping_id", resPartnerId);
      put("access_token", "");
      put("order_line", asList(
        asList(1, false, new HashMap<String, Object>() {{
          put("product_id", orderLineItem);
        }})));
    }})
  ));

However, I'm unable to list products in the quotation's order_line section. Order_line has a one to many relation, but I'm not sure if thats a relationship to products that can be sold to a customer, or something entirely different.

I know the the sale.order.line resources contains all of my 'order_lines' or products, but I'm not sure how to add these products to a new sales quote.

Any help in Java or a python equivalent would be greatly appreciated.


Solution

  • Solved this by making orderLineItem a resource of product.prodcut