TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Procurement Process Optimization with Python

Samir Saci
TDS Archive
Published in
7 min readSep 7, 2021

--

Illustration of procurement strategy problem for store replenishment with Python. The process starts with an alert sent from the store’s reserve to the ERP system (step 1). The ERP sends a purchase order to the supplier (step 2). The supplier ships the order (step 3), and the goods are transported to the store’s reserve for replenishment (step 4). The image depicts key stages of inventory management and order fulfillment, emphasizing cost optimization across transportation and inventory
Optimize Store Procurement Strategy — (Image by Author)

Procurement management is a strategic approach to acquiring goods or services from preferred vendors within your determined budget.

As a data scientist, can you optimize procurement with Python?

Analytics can help you balance supply and demand to ensure a minimum inventory level to meet your store's demand.

In this article, we will present a simple methodology using Non-Linear Programming with Python to design an optimal procurement process for a mid-size retail store considering:

  • Transportation Costs from the Supplier Warehouse to the Store Reserve ($/Carton)
  • Costs to finance your inventory (% of inventory value in $)
  • Reserve (Store’s Warehouse) Rental Costs for storage ($/Carton)
SUMMARY
I. Scenario
As a Supply Planning manager you need to optimize inventory allocation to reduce transportation costs.
II. Build your Model
1. Declare your decision variables

What are you trying to decide?
2. Declare your objective function
What do you want to minimize?
3. Define the constraints
What are the limits in resources?
4. Solve the model and prepare the results
What is the suggestion of the model?
III. Conclusion & Next Steps
1. Inventory Management Rules with Python
What if we have a complex distribution of the demand?
2. Simulate scenarios with a digital twin
How to estimate the impact of a specific rule on cost and performance?
3. Automate Order Creation in your ERP
Deploy an automated bot that will create purchase orders in SAP

How do you automate procurement with Python?

Problem Statement

As a data scientist, you would like to support the store Manager of a mid-size retail location.

She is in charge of setting the replenishment quantity in the ERP.

When the inventory level for each SKU is below a certain threshold, your ERP automatically sends a Purchase Order (PO) to your supplier.

What is the optimal order quantity and frequency?

To determine the right quantity for your PO, you must balance the constraints of stock capacity, transportation, and inventory costs.

  • A supplier receives your orders via EDI connection and ships them using a 3rd Party Transportation company at your expense
  • 60 active stock-keeping units (SKU) with a purchasing price ($/carton) and a yearly sales quantity (Cartons/year)
  • Transportation using a 3rd party company that operates parcel delivery invoiced per carton ($/Carton)
  • Storage Location (Store’s Reserve) with a capacity of 480 boxes stored on shelves
A 3D model of a warehouse storage shelf with five levels, each containing large cardboard boxes. The structure consists of orange beams and blue vertical supports. This visual represents the storage capacity for goods in a retail store reserve, where each shelf cell can hold up to 16 boxes, illustrating how the store manager must account for storage constraints when determining replenishment quantities.
Cell with a capacity of 16 boxes — (Image by Author)

To simplify the comprehension, let’s introduce some notations

Mathematical equations displayed in a blackboard-style format defining parameters for a procurement strategy. The equations cover demand (D), purchasing cost per carton ©, and quantity per purchase order (Q). These variables are crucial in calculating optimal procurement quantities for a store’s inventory management and cost minimization
Notations — (Image by Author)

What are the other parameters?

More equations defining the replenishment rate (R), the number of yearly replenishments (R), and transportation costs (T) that depend on fixed and variable factors. This image is used to show how transportation costs factor into the overall procurement cost analysis for optimal store inventory management.
Equations— (Image by Author)

b = 42.250 $
A = -0.3975 $/Carton

What about the cost of storing goods?

You have the financial costs.

Equations explaining the average inventory level (I), purchasing cost, and capital cost of inventory. The model shows how capital costs impact the store’s procurement process, considering the financial burden of holding inventory. This helps determine optimal replenishment levels.
Equations — (Image by Author)

As a mid-size business, your cost of capital is quite high: 12.5%.

Storage Costs

A formula for calculating the storage costs (ST), factoring in the average inventory level (I), maximum storage capacity (Imax), and monthly rent for the storage area. This visual helps explain how storage costs play a role in the overall procurement process and cost optimization strategy.
Equations — (Image by Author)

In this model, we suppose we have the world's best landlord.

She invoices us by carton occupied, taking the average value per year.

We will not pay for the empty locations.

Imax= 480
Rmonth= 2,000 $/Month

Which Quantity per replenishment Qi should you set in the ERP to minimize the total costs?

In the next section, we will build a model to estimate this quantity using Python.

🏫 Discover 70+ case studies using analytics for supply chain optimization 🚚, sustainability🌳and business optimization 🏪: Cheat Sheet

Build your Model

Unlike the previous article in the series, we won’t use PuLP as we are not dealing with a linear programming problem.

SciPy optimization functions can solve this non-linear minimization problem.

Declare your decision variables

What are you trying to decide?

We want to set the quantity per replenishment order sent by our ERP to the supplier.

A mathematical equation defining the replenishment quantity (Qi) per purchase order for a specific stock-keeping unit (SKU) as part of the procurement optimization model. This equation highlights the key variable in determining how much stock is ordered at each replenishment cycle, critical for balancing inventory and transportation costs.
Equations — (Image by Author)

However, to simplify our calculation, we will use the number of replenishments per year Ri as a decision variable.

A mathematical expression showing the replenishment rate (Ri) as the annual demand (Di) divided by the replenishment quantity (Qi). The image further defines Ri as the number of replenishments per year for a specific SKU, essential for optimizing procurement cycles and minimizing total operational costs.
Equations — (Image by Author)

The replenishment quantity will be calculated using the formula below.

Note: We accept a replenishment case quantity that is not an integer.

Declare your objective function

What do you want to minimize?

An equation showing the total cost of transportation and inventory management (T), accounting for variables like transportation cost per replenishment (A and b), purchasing cost, and storage costs (STi). This formula models the total procurement cost, helping determine the most cost-efficient replenishment strategy.
Equations — (Image by Author)

The purchasing cost is not included in the objective function as it is out of the scope of our optimization targets.

Code

Define the constraints

What are the limits in resources that will determine your feasible region?

An inequality constraint representing that the maximum inventory level must be less than or equal to the store’s storage capacity (Imax). This is a critical constraint in the procurement optimization model to ensure that inventory levels do not exceed physical storage limits.
Equations — (Image by Author)

This is where problems start, as we have a non-linear constraint (1/Ri).

A final set of constraints for the replenishment rate (Ri), which should be positive, between 1 and 100. This constraint ensures that replenishment rates are feasible within the supplier’s minimum and maximum order quantities for a stock-keeping unit.
Equations — (Image by Author)

Solve the model and prepare the results

What are the results of your simulation?

Initial Guess

Unlike Linear Programming, we need to provide an initial vector of a potential solution to the algorithm for the first iteration to initiate it.

Here, we’ll assume that 2 replenishments per year for all SKUs could be a good candidate.

$63,206.7 total cost for initial guessing
Hopefully the optimal solution will be lower

Solve

Comment

I found no method to implement Integer Non-Linear Programming using Scipy solvers.

If you have a better solution than this quick-and-dirty rounding using another Python library, please share it in the comment section.

For 100 Iterations
-> Initial Solution: $28,991.9
-> Integer Solution: $29,221.3 with a maximum inventory of 356 cartons

You can find the complete code in this GitHub repository 👇

Conclusion

We can see here that transportation costs mainly drive our solution, as we have a maximum stock of 356 boxes.

This optimized solution is 56% better than the initial guess of 2 yearly replenishments for all references.

However, it’s based on a strong assumption of a constant demand.

Inventory Management with Python

In the retail industry, inventory management systems often employ a fixed, rule-driven approach to forecasting and replenishing stock.

What if we have a stochastic distribution of your demand, and we want to avoid stock-outs?

You can then face stock-outs as your ordering rules (inventory rules) are not robust enough to absorb the variability, as in the example below.

A three-panel chart showing stochastic demand, replenishment, and inventory levels for a product. The top chart (red) shows fluctuating demand, the middle chart (blue) represents regular replenishment points, and the bottom chart (green) displays inventory levels depleting and replenishing in response to variable demand. This visual illustrates a scenario with normal demand distribution with Python.
Example of a stochastic demand with a deterministic inventory policy — (Image by Author)

Therefore, you must implement advanced inventory management rules to ensure our stores have enough goods to sell.

A set of equations defining average demand over lead time (µ_LD), standard deviation of demand (σ_LD), reorder point (s), and safety stock (SS). These formulas are used to calculate the safety stock needed to buffer against demand variability during the lead time, crucial for continuous inventory review policies with a normally distributed demand.
Demand distribution characteristics— (Image by Author)

They consider key parameters defining your demand distribution to ensure you have enough safety stock to absorb the variability.

For more information, have a look at this article 👇

What if we implement these rules vs. a simple EOQ?

You can simulate the effect on costs and performance with digital twin models.

Include the Model in a Digital Twin

A digital twin is a digital replica of a physical object or system.

Visual representation of a supply chain flow, featuring a factory, warehouse, and store connected by transportation, with Python logos indicating different scripts for simulating processes at each step (factory, warehouse, store).
Supply Chain Digital Twin with Python — (Image by Author)

This computer model can represent our store replenished by suppliers with a planner creating orders.

A graphic illustrating four key components of a factory process: location (a map pin icon), production line (a machine), cost (a price tag), and personnel (a worker). The visual highlights the stages of manufacturing, cost evaluation, and human involvement in the production process.
Example of Factory Parameters — (Image by Author)

Such an optimization model can be implemented to simulate warehouse replenishment orders sent to suppliers or factories.

For instance, we can test several scenarios to see how the model reacts

  • High rental costs and low transportation costs
  • Non-linear purchasing costs
  • Higher Minimum Order Quantity

💡 For more details,

Now that you have found the optimal ordering policy to minimize costs and avoid stock-outs, how can you implement it?

Have you heard about Robotic Process Automation?

SAP Automation of Order Creation for Retail

A purchase order is a document to request items or services from a vendor at an agreed-upon price.

Purchase Order Creation Menu in SAP — (Image by Author)

A fashion retail company preparing for the spring/summer collection must create dozens of purchase orders for its suppliers.

To create our Purchase Order, we need to fill in multiple pieces of information.

This can become a nightmare if done manually!

Example of Automation of Purchase Order Creation — (Image by Author)

I’ve designed a workflow to create this automation using SAP GUI tool and Visual Basic.

If you want to implement it, have a look at the article linked below 👇

About Me

Let’s connect on Linkedin and Twitter. I am a Supply Chain Engineer who uses data analytics to improve logistics operations and reduce costs.

For consulting or advice on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting.

If you are interested in Data Analytics and Supply Chain, look at my website.

💌 New articles straight in your inbox for free: Newsletter
📘 Your complete guide for Supply Chain Analytics: Analytics Cheat Sheet

--

--