【问题标题】:Overwriting descriptions from items on sales order with default descriptions + not updating rate?使用默认描述覆盖销售订单项目的描述 + 不更新率?
【发布时间】: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


    【解决方案1】:

    编辑于 2023-01-13:

    我在行项目的第一个循环中修改了函数。 基本上,我们保留行项目的所有属性/键,只删除line_item_id

    ...
    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();
            /*
            // Instead of manually setting up each key of a line item
            // We will just copy from ele1 to pro2 variable
            // Then remove the line_item_id, as currently we are not able to override line items with that
            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());
            */
            pro2 = ele1;
            pro2.remove("line_item_id"); // remove the key
            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
        {
    ...
    

    我不太清楚问题 #1。为什么您仍然需要每个订单项的item_id?是否有任何信息需要保留但在使用该功能时丢失了?

    对于问题 #2,您需要先删除费率,然后再添加它。

    ....
    }
        found = false;
        for each  ele1 in line_items
        {
            if(ele1.get("item_id") == "2015797000015488030")
            {
                // remove rate
                ele1.remove("rate");
                // then add again
                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()
    ....
    

    【讨论】:

    • 谢谢桑巴达!如果没有将行项目添加到 pdlist,它会覆盖订单上的项目,item_id 为 2015797000015488030。否则不确定解决方法吗?
    • 我在答案中添加了修改后的脚本。请查看它是否符合您的要求。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多