1. Price List Algorithm

January 31, 2024


This is a description of the "price list algorithm" as it has been currently implemented in Erply back office and API.

This document has been written to provide insight into the algorithm, and help resolve issues. This algorithm CAN be implemented in other applications, too, if needed — but please note that it is quite extensive. We may also update the algorithm (add new features) without prior notice.

1. Input Parameters

Calculating a product's price list price uses the following information:

  • Product being sold;
  • Its quantity (if the “Quantity Discounts” extra module has been enabled);
  • Customer;
  • Location.

The location may belong to a store region.

At first, Erply:

  • Identifies what customer group the customer belongs to, what is its parent group, parent’s parent etc., up to the top of customer group hierarchy.
  • Identifies what product group the product belongs to, what is its parent group, parent’s parent etc., up to the top of product group hierarchy.

2. Applicable Price Lists and Their Order

For calculating a “store price”, the following price lists apply, in the following order. The algorithm walks through all these price lists:

  1. Region’s price lists
  2. Region + customer group price lists
    1. Starting with price lists associated with the top-level customer group, followed by price lists associated with groups further down in the hierarchy.
  3. Warehouse’s price lists 1, 2, 3, 4, 5

For calculating a “customer price”, the following price lists apply, in the following order:

  1. Customer group’s price lists 1, 2, 3, 4, 5
    1. Starting with price lists associated with the top-level customer group, followed by price lists associated with groups further down in the hierarchy.
  2. Customer’s price lists 1, 2, 3, 4, 5

3. Algorithm

  1. Erply starts from product card price and applies all “store price lists”, yielding the “store price”.
  2. Erply takes the “store price” and additionally applies all “customer price lists”, yielding the “customer price”.
    1. If configuration parameter "warehouse_and_client_pricelists_do_not_cumulate" = 1, Erply starts with the product card price instead.
  3. The lower of the two (store price / customer price) always takes precedence.

4. Additionally applying one manually selected price list

When creating a sales document in back office, user can additionally pick one price list manually. Similarly, API call calculateShoppingCart allows to manually specify a price list with input parameter "pricelistID".

This manually selected price list is applied differently, depending if the account is using Berlin or Classic back office. (API uses the algorithm from back office, so the back office flavor affects API's behavior, too)

How it works in Berlin

  1. It is applied last — after customer and store price lists.
  2. Percentage discounts are calculated relative to product card price.
  3. Lowest price always wins: if customer or store price is lower, then the price from the manually selected price list will not apply. This approach was selected because it is consistent with how the algorithm has always compared store price and customer price.
  4. If the manually selected price list does not contain a price for that item, store or customer price remains in effect.

This is the algorithm since version 5.44. Before that, the lowest price did not win: by manually picking a price list, price could increase.

How it works in Classic

If user selects a price list manually, only that list is applied; all customer and store price lists are ignored entirely.

This behavior has been in effect since Classic 4.5.