Main Scripts

Custom Order Processing Script Documentation

11min

Introduction

This document provides an overview and documentation for an order processing script that automates various tasks related to order data manipulation. The script is designed to be run periodically to process orders, update shipping costs, VAT rates, and generate CSV files for further processing. The files ae then uploaded to the clients dropbox for processing. Below, you'll find details on how the script works, its main functions, and the dependencies it relies on.

Installation

1.Clone the repository and install the dependencies

Shell


2.Run the script

Shell


Script Overview

The custom order processing script is written in JavaScript and serves the purpose of processing order data obtained from Linworks. It performs the following key tasks:

  1. Retrieving order data from Linnworks.
  2. Updating shipping costs for orders based on various conditions provided by the client.
  3. Updating location references for orders based on specific criteria.
  4. Updating VAT (Value Added Tax) rates for items in orders.
  5. Converting currency for order prices to GBP (British Pound).
  6. Generating two CSV files for further use: one for normal orders and another for orders with location references.

Script Structure

The script consists of several functions and steps. Here's an overview of the key functions and what they do:

getLinnsData()

This function retrieves order data from Linnworks using an endpoint, /Dashboards/ExecuteCustomScriptQuery, that allows you to send a custom SQL query. It performs data filtering and processing to obtain the required order information.

Text


To Understand the SQL script youll have to go through the Linnworks API Documentation and Database Structure

updateShipping(data)

This function updates shipping costs for items in orders based on various conditions, such as currency and postage cost.

JS


updatelocationRef(data)

This function updates location references for orders based on specific criteria, including source, sub-source, and email addresses.

JS


makeOtputCSV(data)

This function generates a CSV file for normal orders (without location references) after processing.

makeLocationOtputCSV(data)

This function generates a CSV file for orders with location references after processing.

updateVAT(data)

This function updates VAT rates for items in orders by reading data from the vat.csv file.

main()

The main function orchestrates the entire order processing workflow. It performs the following steps:

  • Retrieves order data from the SQL database.
  • Filters out already processed orders.
  • Updates VAT rates.
  • Updates shipping costs.
  • Updates location references.
  • Converts currency.
  • Generates CSV files.
  • Uploads generated files to Dropbox and an SFTP server.
  • Logs processing information.

Scheduling

The script uses the node-cron library to run periodically. It schedules the main() function to run at specified intervals (e.g., every 30 minutes).

Conclusion

This custom order processing script is designed to automate various tasks related to order data manipulation, shipping cost updates, VAT rate updates, and more.