Most Powerful Open Source ERP

Aggregated Amount Unified Algorithm

discussion explaining the idea of a unified transformation algorithm
  • Last Update:2016-04-08
  • Version:001
  • Language:en

This discussion explains the idea of unified transformation algorithm which should be common to all AggregagtedAmountList generators.

Table of Contents

Discussion and Transformation Algorithm

Please refer to ERP5 Taxes and Discounts to better understand. It also provides some answers to the Discussion on Taxes

It does not discuss (yet) rounding issues.

# Generic Transformation Algorithm
#  the same algorithm should apply to payroll, taxes and MRP transformations

# Set the common arbitrary base amounts in a dictionary
base_amount = {
  'delivery': 1,
  'employee': 100,

# Set ungrouped empty result list
ungrouped_result = []

# Build the amounts from delivery lines and trade model lines
for line in delivery.contentValues(use='product'):
  # Set line level base application amounts
  for application in line.getBaseApplicationList(): # Acquired from Resource
    base_amount[application] = total_price=line.getTotalPrice()
  # Set line level arbitrary base amounts
    unit=(line.getQuantityUnit() == 'unit') * line.getQuantity(),
    ton=(line.getQuantityUnit() == 'ton') * line.getQuantity(),
    # more base applications could be set here
  # Feed the result with trade model (which must be ordered through constraint resolution)
  for trade_model_line in trade_model.contentValues(portal_type="Trade Model Line"):
    if trade_model_line.getResource():
      # This line has a resource, it is an output line
      amount = Amount(resource=trade_model_line.getResource(),
                      # Resource can be a VAT service or a Component in MRP
                              *(trade_model_line.getQuantity() or 1.0),
                      # Quantity is used a multiplier (like in transformations for MRP)
                      # Price could be empty here (like in Transformation)
                      # or set to the price of a product (ex. a Stamp)
                      # or set to a tax ratio (ie. price per value units)
                      # We save here the base contribution so that they can 
                      # be later used by getTotalPrice on the delivery itself
      # This line has a no resource, it is an intermediate line
      value = base_amount[trade_model_line.getBaseApplication()] 
              *(trade_model_line.getQuantity() or 1.0)
              # Quantity is used as a multiplier
              *(trade_model_line.getPrice() or 1.0)
              # Price is used as a ratio (also a kind of multiplier)
      for key in trade_model_line.getBaseContribution():
        base_amount[key] += value
# Compute the grouped result
grouped_result = SomeMovementGroup(ungrouped_result)

# Return result
return grouped_result

Related Articles