Tip #2.2 Auto-updating shipment charges from multiple shipment records to invoices in Zoho Inventory

Tip #2.2 Auto-updating shipment charges from multiple shipment records to invoices in Zoho Inventory

Hello again,

Earlier today, we saw how you can automate the process of calculating shipment charges from every shipment order associated with a sales order and adding it to the total amount. And here in this post which happens to be the part 2 of the same, we will see how we can do the same for your invoices.

Now before we begin, you need a few things for this custom function to work:

1) You have to make the invoice from a sales order by opening a sales order in Shipped status, clicking on the Create button that you can find somewhere inside every sales order and selecting Invoice from the drop-down. (In other words, convert a Shipped Sales Order into an invoice and not from an order that still has unshipped items).
2) All shipments made for a particular sales order, must be recorded as manual shipments.
3) Also, you'll need to generate an auth token for your account. To do so, log in to your Zoho Account and then  click on this link before you begin setting up this custom function . Copy the auth token and keep it safe.

Now let's see how we can setup this custom function.

Method 2. Auto-updating total shipment charge to an invoice: (Method 1 is for sales orders which we saw in the part 1 of this post)
  • Open your Zoho Inventory organization.

  • Click on the gear icon from the top-right corner to select Automation from the drop-down.

  • Inside of Automation, select the drop-down near the +New Workflow button and select Custom Functions.

  • Give your workflow a name without any spaces between words.

  • The module will be Invoices. 

  • The condition for this custom function shall be "When an Invoice is created".

  • The trigger point for this function will be "Immediate".

  • Copy and paste the code segment below inside the Deluge pane:

shipamt = List(); 

authtoken = "Copy and paste your authtoken here";

invoiceID = invoice.get("invoice_id");

invoicedate = invoice.get("date").toDate();

organizationID = organization.get("organization_id");

res = invokeurl

[

url :"https://inventory.zoho.com/api/v1/invoices/" + invoiceID + "?organization_id=" + organizationID + "&authtoken=" + authtoken

type :GET

];

inv = res.get("invoice");

soid = inv.get("salesorder_id");

//replace authtoken and orgid

response = invokeurl

[

url :"https://inventory.zoho.com/api/v1/salesorders/" + soid + "?authtoken=" + authtoken + "&organization_id=" + organizationID

type :GET

];

so = response.get("salesorder");

pkg = so.get("packages").toList();

sid = List();

for each pk in pkg

{

sid.add(pk.get("shipment_id"));

}

i=0;

sumamt = 0;

for each index i in sid

{

resp = invokeurl

[

url :"https://inventory.zoho.com/api/v1/shipmentorders/" + sid.get(i) + "?authtoken=" + authtoken + "&organization_id=" + organizationID

type :GET

];

shipdet=resp.get("shipmentorder");

charges = shipdet.get("shipping_charge").toDecimal();

sumamt = sumamt + charges;

}

info sumamt;

bson = Map();

bson.put("invoice_number",invoice.get("invoice_number"));

bson.put("customer_id",invoice.get("customer_id"));

bson.put("shipping_charge",sumamt);

fin = zoho.inventory.updateRecord("Invoices",organizationID,invoiceID,bson);

info fin.toMap().get("message");

  • Make sure you copy and paste the auth token number that you had generated earlier to line 2 of this code fragment that says: authtoken = "Copy and paste your auth token here";

  • Hit Save to finish.

Now every time you make an invoice for a shipped sales order, the total shipment charge will be updated automatically.


​Hope this helps you in your order fulfilment endeavors. Have you ever tried writing custom functions by yourself? Email your discoveries, questions and suggestions to  support@zoho-inventory.com .

Until next time.

Your everyday end user,
Ajay Aadhithya Chandrasekaran
Zoho Inventory




    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

                          Writer is a powerful online word processor, designed for collaborative work.

                            Zoho CRM コンテンツ




                              ご検討中の方