Closed donghd closed 7 years ago
product onchange method call
private class OnProductChange extends AsyncTask<HashMap<String, Float>, Void, List<ODataRow>> {
private ProgressDialog progressDialog;
private String warning = null;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(SalesDetail.this);
progressDialog.setCancelable(false);
progressDialog.setTitle(R.string.title_please_wait_mn);
progressDialog.setMessage(OResource.string(SalesDetail.this, R.string.title_working_mn));
progressDialog.show();
}
@Override
protected List<ODataRow> doInBackground(HashMap<String, Float>... params) {
List<ODataRow> items = new ArrayList<>();
try {
ProductProduct productProduct = new ProductProduct(SalesDetail.this, sale.getUser());
SalesOrderLine saleLine = new SalesOrderLine(SalesDetail.this, sale.getUser());
ODataRow getSaleCategory = salecategory.browse(mForm.getValues().getInt("sale_category_id"));
ResPartner partner = new ResPartner(SalesDetail.this, sale.getUser());
ODataRow customer = partner.browse(mForm.getValues().getInt("partner_id"));
ServerDataHelper helper = saleLine.getServerDataHelper();
for (String key : params[0].keySet()) {
ODataRow product = productProduct.browse(productProduct.selectRowId(Integer.parseInt(key)));
Float qty = params[0].get(key);
OArguments arguments = new OArguments();
arguments.add(new JSONArray());
int pricelist = customer.getInt("property_product_pricelist");
JSONObject jsonData = new JSONObject();
jsonData.put("qty_to_invoice", 0);
jsonData.put("analytic_tag_ids", new JSONArray());
jsonData.put("price_unit", 0);
jsonData.put("product_uom_qty", qty);
jsonData.put("qty_invoiced", 0);
jsonData.put("procurement_ids", new JSONArray());
jsonData.put("id", false);
jsonData.put("qty_delivered", 0);
jsonData.put("product_uom", product.getInt("uom_id"));
jsonData.put("qty_delivered_updateable", false);
jsonData.put("customer_lead", false);
jsonData.put("product_tmpl_id", product.getInt("id"));
jsonData.put("state", "draft");
jsonData.put("product_packaging", false);
jsonData.put("tax_id", new JSONArray());
JSONObject order = new JSONObject();
order.put("origin", false);
order.put("picking_policy", "direct");
order.put("compaign_id", false);
order.put("currency_id", currency.getInt("id"));
order.put("tasks_count", 0);
order.put("client_order_ref", false);
order.put("date_order", mForm.getValues().getString("date_order"));
order.put("partner_id", customer.getInt("id"));
if (record == null) {
order.put("id", false);
} else {
order.put("id", record.getInt("id"));
}
order.put("note", false);
order.put("delivery_count", 0);
order.put("amount_untaxed", 0);
order.put("invoice_status", "no");
order.put("sale_category_id", getSaleCategory.getInt("id"));
order.put("tag_ids", new JSONArray());
order.put("company_id", mUser.getCompanyId());
order.put("pricelist_id", pricelist);
order.put("amount_tax", 0);
order.put("state", "draft");
order.put("warhouse_id", 3);
order.put("payment_term_id", mForm.getValues().get("payment_term"));
order.put("name", "New");
order.put("partner_invoice_id", customer.get("id"));
order.put("picking_ids", new JSONArray());
order.put("amount_total", 0);
order.put("partner_shipping_id", customer.getInt("id"));
order.put("user_id", mUser.getUserId());
order.put("fiscal_position_id", false);
order.put("source_id", false);
jsonData.put("order_id", order);
jsonData.put("price_subtotal", 0);
jsonData.put("discount", 0);
jsonData.put("layout_category_id", false);
jsonData.put("name", false);
jsonData.put("invoice_status", "no");
jsonData.put("product_id", product.getInt("id"));
jsonData.put("invoice_lines", new JSONArray());
jsonData.put("route_id", false);
arguments.add(jsonData);
arguments.add("product_id");
JSONObject jsonParam = new JSONObject();
jsonParam.put("qty_to_invoice", "1");
jsonParam.put("analytic_tag_ids", "");
jsonParam.put("price_unit", "1");
jsonParam.put("product_uom_qty", "1");
jsonParam.put("qty_invoiced", "1");
jsonParam.put("procurement_ids", "");
jsonParam.put("qty_delivered", "1");
jsonParam.put("product_uom", product.getString("uom_id"));
jsonParam.put("qty_delivered_updateable", "");
jsonParam.put("customer_lead", "");
jsonParam.put("product_tmpl_id", "");
jsonParam.put("state", "1");
jsonParam.put("product_packaging", "1");
jsonParam.put("tax_id", "1");
jsonParam.put("price_subtotal", "");
jsonParam.put("discount", "");
jsonParam.put("layout_category_id", "");
jsonParam.put("name", "");
jsonParam.put("invoice_status", "1");
jsonParam.put("product_id", "1");
jsonParam.put("invoice_lines", "1");
jsonParam.put("route_id", "1");
arguments.add(jsonParam);
JSONObject context = new JSONObject();
context.put("lang", "mn_MN");
context.put("tz", false);
context.put("uid", mUser.getUserId());
context.put("company_id", mUser.getCompanyId());
context.put("pricelist", pricelist);
context.put("field_parent", "order_id");
context.put("partner_id", customer.getInt("id"));
context.put("uom", product.getInt("uom_id"));
context.put("quantity", qty);
context.put("uom_qty_change", true);
arguments.add(context);
String method = "onchange";
Object response = helper.callMethod(method, arguments, new HashMap<String, Object>());
JSONObject jsonObject = new JSONObject((Map) response);
if (jsonObject.has("warning") && !jsonObject.getString("warning").equals("false")) {
Object warning_obj = jsonObject.get("warning");
JSONObject message = new JSONObject((Map) warning_obj);
warning = message.getString("message");
}
OValues values = new OValues();
Object value_obj = jsonObject.get("value");
JSONObject json_value = new JSONObject((Map) value_obj);
values.put("product_id", product.getInt("id"));
values.put("name", json_value.getString("name"));
values.put("product_uom_qty", qty);
values.put("product_uom", product.getInt("uom_id"));
values.put("price_unit", json_value.getDouble("price_unit"));
values.put("price_subtotal", json_value.getDouble("price_subtotal"));
values.put("invoice_lines", new JSONArray());
values.put("procurement_ids", new JSONArray());
values.put("discount", 0);
values.put("customer_lead", json_value.getInt("customer_lead"));
values.put("analytic_tag_ids", new JSONArray());
values.put("route_id", false);
values.put("product_packaging", false);
values.put("layout_category_id", false);
values.put("tax_id", new JSONArray());
JSONArray tax_id = new JSONArray();
//tax_id.put(6);
//tax_id.put(false);
//tax_id.put(json_value.getJSONArray("tax_id"));
values.put("tax_id", new JSONArray().put(tax_id));
//values.put("th_weight", (json_value.has("th_weight")) ? json_value.get("th_weight") : 0);
//values.put("discount", (json_value.has("discount")) ? json_value.get("discount") : 0);
if (extra != null) {
values.put("order_id", extra.getInt(OColumn.ROW_ID));
}
items.add(values.toDataRow());
}
} catch (Exception e) {
Log.e(TAG,"Exception: " + e.getMessage(), e);
}
return items;
}
@Override
protected void onPostExecute(List<ODataRow> row) {
super.onPostExecute(row);
if (row != null) {
objects.clear();
objects.addAll(row);
mAdapter.notifyDataSetChanged(objects);
float total = 0.0f;
for (ODataRow rec : row) {
total += rec.getFloat("price_subtotal");
}
total_amt.setText(String.format("%.2f", total));
untaxedAmt.setText(total_amt.getText());
}
progressDialog.dismiss();
if (warning != null) {
OAlert.showWarning(SalesDetail.this, warning.trim());
}
}
}
Hi @purevsurento , Thank you! It seems working! Do my understanding correct that it send all 'sale.order.line' data from client, that will avoid not query data at server (so changed product_id can be kept)? If so, it can apply for 'onchange_partner_id' too ? (that avoid to change code at server side) But , my return result lacking some value: price_unit, price_subtotal,.. May I did something wrong?
OdooSyncResponse{response=OdooResponse{jsonrpc='2.0', error='null', id=5380, result={domain={product_uom=[[category_id, =, 1.0]]}, value={product_tmpl_id=[21.0, [C-Case] Computer Case], name=[C-Case] Computer Case, product_uom=[1.0, Unit(s)]}}}, object=null}
Hi @donghd the results of my above example code : {domain={product_uom=[[category_id, =, 50.0]]}, value={price_subtotal=1780.0, customer_lead=7.0, tax_id=[[5.0], [4.0, 1.0]], price_unit=1780.0, name=product name}}
How can i see your source code? So i can more recommend.
Hi @purevsurento , thank you for supportive reply. So I did somewhere mistake, I try to investigate first. If i am unable, I hope to get your recommend!
Hi @donghd
good luck.
Hi @purevsurento sorry, I'd like make clear one more thing. My return result differ from Odoo v9 community version & Odoo v10 community version. What is your server version? (enterprise version?)
Hi @donghd My server Odoo v10 community version
Hi @purevsurento ,
Thank you for your info.
In my case, I found issue when pricelist == 0, then it cannot get correct return value.
Therefore, if pricelist == 0, it will be assigned value as 1 instead. So far, it is okay now.
I have trouble not figure out how to set params: when execute callMethod (onchange_partner_id, product_id_change) Odoo 9.0 or 10.0? what format data should below data to be changed?: