0

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.

Tiocrash
  • 347
  • 5
  • 16
  • What is the problem exactly didn't understand this: 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 – Charif DZ Dec 04 '17 at 07:57
  • What is the value of orderLineItem ? – jo541 Dec 04 '17 at 13:10

2 Answers2

0

Solved this by making orderLineItem a resource of product.prodcut

Tiocrash
  • 347
  • 5
  • 16
-2
import java.util.Arrays;
import java.util.HashMap;

import parapremium.beans.Product;

public class CreateSaleOrder extends Service {

    private int userid;

    public CreateSaleOrder() throws Exception {
        super();
        userid=(new Authenticate()).getUserId();
    }

    public int createOrder() throws Exception
    {
        final int inv=(int) client.execute("execute_kw", Arrays.asList(
                  database, userid, password,
                  "sale.order", "create",
                  Arrays.asList(new HashMap<String, Object>() {{ 
                         put("partner_id", 1);
                         put("currency_id", 1);
                         //  put("date_order", dateTime);
                         put("picking_policy", "");
                         put("pricelist_id", 2);
                         //put("name", "Order");
                         // put("warehouse_id", 15);
                         put("access_token", "");
                    }})
                ));

        return inv;
    }

    public int createOrderLine(final int inv, int id, final double new_qty) throws Exception
    { 
        final int id_product=id;

         client.execute("execute_kw", Arrays.asList(
                  database, userid, password,
                  "sale.order.line", "create", Arrays.asList(new HashMap<String, Object>() {{ 
                      put("order_id", inv); 
                      //put("theoretical_qty", th_qty); 
                      put("product_id", id_product); 
                      put("product_qty", new_qty);
                      //  put("product_uom", 1);
                      put("discount", 10);
                 }})    ));       

          return 1;
    }


    public static void main(String arg[]) throws Exception
    {
        CreateSaleOrder createOrderLine = new CreateSaleOrder();
        int i = createOrderLine.createOrder();
        System.out.print( i );
        System.out.print( createOrderLine.createOrderLine(i,1001, 4) );
    }
}
Striezel
  • 3,693
  • 7
  • 23
  • 37