Tip #1 Automating online sales order to invoice conversions in Zoho Inventory

Tip #1 Automating online sales order to invoice conversions in Zoho Inventory


Hello,
 
Hope the day is treating you well.
We've been getting more than a few requests from online sellers who use Zoho Inventory to help them automate invoice generation for all online orders that drop into Zoho Inventory automatically from a sales channel or a shopping cart that they have integrated. Are you an online seller like them? Then we've got some exciting news for you. You can do it with the help of a few simple things that we'll see here today.

So how do we go about this?
If you have integrated online sales channels like Amazon, Etsy and Ebay or a shopping cart like Shopify to Zoho Inventory, then you will be aware of sales orders being automatically generated inside of Zoho Inventory whenever your online customers buy something from you through these integrated channels. Since invoices are generated and automatically sent to your clients by the channel, you have little need of the invoices inside of Zoho Inventory apart from accounting purposes. Depending on the amount of online orders you get per day, it can get tricky to convert these orders into invoices manually. So we are going to automate this part for you with the help of a simple custom function. 
 
Wondering what custom functions are? They are one of the automation tools at your disposal inside of Zoho Inventory and can be accessed inside of Settings. To know more about custom functions in general, please refer to our help document.
 
Now let's see how we can write one to automatically convert all online sales orders into invoices as soon as they are generated within Zoho Inventory. 
 
Log in to your Zoho account and click on this link to generate an Auth Token which is required to make this work.
 
1) Open your Zoho Inventory organization.
2) Navigate to Settings using the gear icon from the top-right corner.
3) Select Automation from the sidebar. Click on the +New Workflow Rule button that is found at the top-right corner.
4) Out of the four tabs within Automation, select Custom Functions.
5) Now let's add a name for this workflow rule. (Note: Name cannot contain spaces)
6) The module to be chosen is Sales Orders.
7) Add a description if you need one.
8) Now, the workflow type is going to be Event Based.
9) And for the trigger, choose the option - "When a Sales Order is" "Created".
10) In the deluge pane, copy and paste the following code snippet:
 
salesorderID = salesorder.get("salesorder_id");
salesorderdate = salesorder.get("date").toDate();
organizationID = organization.get("organization_id");
authtoken = "
Copy and Paste your auth token in place of this text";
sal = invokeurl
[
url :"
https://inventory.zoho.com/api/v1/salesorders/" + salesorderID + "?authtoken=" + authtoken + "&organization_id=" + organizationID
type :GET
];
temp = sal.get("salesorder");
// info temp;
new = temp.get("sales_channel");
if(!new.equalsIgnoreCase("direct_sales"))
{
bson = Map();
customerID = salesorder.get("customer_id").toString();
salesoderdate = salesorder.get("date").toDate();
//invoice_number = salesorder.get("salesorder_number").replaceFirst("SO","INV");
//bson.put("invoice_number",);
bson.put("customer_id",customerID);
bson.put("date",salesorder.get("date"));
lineItems = salesorder.get("line_items").toList();
newLineItems = List();
for each lineItem in lineItems
{
lineItemMap = Map();
solineitemID = lineItem.get("line_item_id");
lineItemMap.put("salesorder_item_id",solineitemID);
id = lineItem.get("item_id");
lineItemMap.put("item_id",id);
des = lineItem.get("description");
lineItemMap.put("description",des);
wh = lineItem.get("warehouse_id");
lineItemMap.put("warehouse_id",wh);
quantity = lineItem.get("quantity");
lineItemMap.put("quantity",quantity);
r = lineItem.get("rate");
lineItemMap.put("rate",r);
d = lineItem.get("discount");
lineItemMap.put("discount",d);
tidd = lineItem.get("tax_id");
lineItemMap.put("tax_id",tidd);
tex = lineItem.get("tax_exemption_code");
lineItemMap.put("tax_exemption_code",tex);
newLineItems.add(lineItemMap);
}
bson.put("line_items",newLineItems);
if(temp.get("is_taxable").equalsIgnoreCase("true"))
{
bson.put("tax_id",temp.get("tax_id"));
}
else
{
bson.put("tax_exemption_id",temp.get("tax_exemption_id"));
bson.put("tax_authority_id",temp.get("tax_authority_id"));
}
response = zoho.inventory.createRecord("Invoices",organizationID,bson);
info bson;
info response.toMap().get("message");
inv = response.get("invoice");
info inv.get("invoice_id");
//marking as sent//
invoiceID = inv.get("invoice_id");
invoicedate = inv.get("date").toDate();
respond = invokeurl
[
url :"
https://inventory.zoho.com/api/v1/invoices/" + invoiceID + "/status/sent?authtoken=" + authtoken + "&organization_id=" + organizationID
type :POST
];
info respond.toMap().get("message");
}
else
{
info "Order is not from a Marketplace";
}
 
11) Before you save, you are required to copy and paste your auth token inside the quotes in the 4th line that says: authtoken = "Copy and Paste your auth token in place of this text";
Note: The auth token is a critical piece of information that helps the system identify you, so keep yours safe and confidential. Do not share it with anyone, not even with folks from Zoho.
12) Now, hit Save to finish.
 
Henceforth, all your online sales orders that are auto-generated from Amazon, Etsy, Ebay or Shopify will be automatically converted to invoices. And the status of these invoices inside of Zoho Inventory will be Sent. If you wish to auto-generate invoices of Paid status, then it can be made possible with a few changes. You can either experiment that part by yourself or contact us at support@zoho-inventory.com
 
Note: If you need this automation only for one channel, say for Shopify alone and not other channels, then you need to make a few changes to line 13 that originally says - if(!new.equalsIgnoreCase("direct_sales")) to if(new.equalsIgnoreCase("shopify"))
 
Hope this helps you in your online selling endeavors. Oh and by the way, have you ever dabbled with the custom functions module by yourself? You can share your discoveries, questions and suggestions with us anytime. We look forward to hearing from you. (Email us: 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 Marketing Automation


                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl 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

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now