通过Odoo API(Java)将产品添加到新的销售报价中

时间:2017-12-02 21:06:05

标签: openerp odoo-8 odoo-9 odoo-10

我正在通过Odoo API以编程方式创建新的销售报价,如下所示:

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);
        }})));
    }})
  ));

但是,我无法在报价单的order_line部分列出产品。 Order_line有一对多的关系,但我不确定这是与可以出售给客户的产品的关系,还是完全不同的产品。

我知道sale.order.line资源包含我的所有'order_lines'或产品,但我不确定如何将这些产品添加到新的销售报价中。

非常感谢Java或python等效的任何帮助。

2 个答案:

答案 0 :(得分:0)

通过使orderLineItem成为product.prodcut

的资源解决了这个问题

答案 1 :(得分:-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) );
    }
}