【发布时间】:2023-01-13 20:38:36
【问题描述】:
有一个在 Zoho Books/Inventory 中运行的 deluge 脚本,它根据客户/项目模块和创建者表中的自定义字段计算一些费用。
脚本按预期工作(虽然比希望的要慢一点)但还有两个我正在努力克服的最后障碍。
问题 1) 脚本遍历销售订单上的每个行项目以检查它是否在项目模块的相关自定义字段中有一个条目然后它有效地刷新销售订单与行项目和一个新的行项目“回收费”与计算的费率。这很好,但是有一个非常具体的利基项目需要在每个销售订单上更新描述。在这种情况下,脚本会在此基础上运行并将用户更新的描述替换为该项目的默认描述。
问题 2) 脚本执行的计算按预期工作,但是,如果销售订单上存在行项目“回收费用”,则不会发生任何事情。如果用户删除该行并保存销售订单,它将按预期更新。
修复 1) 我已经尝试从销售订单中提取描述并将其添加到“pdlist”,虽然这确实保留了用户编辑的描述,但它从销售订单中删除了 item_ids,因此销售订单上的项目只是描述。
修复 2) 我尝试将变量分配给 false,然后检查行项目以查看是否存在“回收费”,如果存在则更新费率。这解决了添加多个“回收费”行项目但仍然不会更新费率(如果存在)的问题。
我在下面截断了脚本,应该是相关部分。
// Fetch SO and customer records
resp = zoho.inventory.getRecordsByID("salesorders",organizationID,salesorderID,"inventory1");
//info resp;
salesorder = resp.get("salesorder");
if(true)
{
info salesorder;
// return;
}
...
//GETTING CUSTOMER/SO SHIPPING INFO HERE//
...
for each custom_field in customer_custom_fields
{
if(custom_field.get("label") == "Remitter ID")
{
cf_remitter_id = custom_field.get("value");
}
}
// Set Recycling Fee to 0
Fee = 0;
// Check if Remitter ID is null
if(cf_remitter_id == "")
{
line_items = salesorder.get("line_items");
pdlist = List();
for each ele1 in line_items
{
item_id = ele1.get("item_id");
itemresp = zoho.inventory.getRecordsByID("items",organizationID,item_id,"inventory1");
//info itemresp;
item = itemresp.get("item");
custom_fields1 = item.get("custom_fields");
//info custom_fields1;
cf_recycling_category = "";
flag = false;
pro2 = Map();
pro2.put("item_id",ele1.get("item_id"));
//pro2.put("description",ele1.get("description"));
pro2.put("quantity",ele1.get("quantity"));
pro2.put("rate",ele1.get("rate"));
//pro.put("total",item_total.toDecimal());
//pro.put("net_total",item_total.toDecimal());
pdlist.add(pro2);
info pro2;
for each custom_field1 in custom_fields1
{
...
//LOOP TO CHECK FEES GOES HERE//
...
}
found = false;
for each ele1 in line_items
{
if(ele1.get("item_id") == "2015797000015488030")
{
ele1.put("rate",Fee.toDecimal());
ele1.put("quantity",1);
found = true;
break;
}
}
// Add new line item if it does not exist
if(found = false)
{
pro = Map();
pro.put("item_id",2015797000015488030);
pro.put("rate",Fee.toDecimal());
pro.put("quantity",1);
// pro.put("description");
pdlist.add(pro);
info pro;
}
mp = Map();
mp.put("line_items",pdlist);
up = zoho.inventory.updateRecord("salesorders",organizationID,salesorderID,mp,"inventory1");
info up;
}
【问题讨论】:
标签: zoho zoho-deluge zohobooks