Firstly, this code works to convert a sales order(SO) to a purchase order (PO) via a button, however I am running into an issue when I convert the SO where the values from the line items are not pulled across from the SO to the PO.
The ones in question are the Discount/Adjustment, Wholesale Price and Maker Price.
I think the code below first references the Product module record first hence the API names, Euro Price for Maker Price and Wholesale_Price_1 for the Wholesale Price.
Below is the code I am using, it may also be something simple where I shouldn't be using the API names but the field names and vice versa - if anyone could assist with this would be grateful.
string button.PO_from_SO(String soId)
{
respMap = zoho.crm.getRecordById("Sales_Orders",soId.toLong());
productDet = ifnull(respMap.get("Product_Details"),list());
pdlist = List();
for each eachProd in productDet
{
productvalue = eachProd.get("product");
proid = productvalue.get("id");
proname = productvalue.get("name");
mp = Map();
mp.put("product",{"name":proname,"id":proid});
mp.put("quantity",ifnull(eachProd.get("quantity"),"0").toLong());
mp.put("list_price",ifnull(eachProd.get("list_price"),"0.0").toDecimal());
mp.put("discount",ifnull(eachProd.get("discount"),"0.0").toDecimal());
mp.put("wholesale_price",ifnull(eachProd.get("wholesale_price_1"),"0.0").toDecimal());
mp.put("maker_price",ifnull(eachProd.get("euro_Price"),"0.0").toDecimal());
mp.put("total",ifnull(eachProd.get("total"),"0.0").toDecimal());
mp.put("net_total",ifnull(eachProd.get("net_total"),"0.0").toDecimal());
pdlist.add(mp);
}
paramap = Map();
paramap.put("Product_Details",pdlist);
paramap.put("Subject",ifnull(respMap.get("Subject"),""));
contact = respMap.get("Contact_Name");
if(contact != null)
{
paramap.put("Contact_Name",contact.get("id"));
}
paramap.put("Terms_and_Conditions",ifnull(respMap.get("Terms_and_Conditions"),""));
paramap.put("Description",ifnull(respMap.get("Description"),""));
paramap.put("Adjustment",ifnull(respMap.get("Adjustment"),"0.0").toDecimal());
paramap.put("Discount",ifnull(respMap.get("Discount"),"0.0").toDecimal());
paramap.put("Maker Price",ifnull(respMap.get("maker_price"),"0.0").toDecimal());
paramap.put("Wholesale Price",ifnull(respMap.get("wholesale_price"),"0.0").toDecimal());
createResp = zoho.crm.createRecord("Purchase_Orders",paramap);
info createResp;
return "Sales order successully converted to Purchase Order";
}