Projects:AverageCostRefactor/TechnicalSpecs/CostingAlgorithm
Costing Algorithm
New abstract class, CostingAlgorithm, that has to be extended by each algorithm.
Available methods
This class have several methods that can be used or overwritten by each Costing Algorithm implementation.
Initialization methods
Constructor and init. Receives the Transaction that is being processed and the Costing Rule that has to be applied. Gets the Organization and Currency to be used. Builds dimensions HashMap, based on rule definition.
Method to calculate transaction's amount
This method gets the transaction type and calls the corresponding method. Returns the total amount of the transaction.
Method for each incoming transaction type
One method for each incoming transaction type (receipt, internal movement,...). Returns the total amount of the transaction. Each transaction type has its own default method to get the cost that can be overriden by the algorithms. See Common transaction type list and Other implmented transaction types sections.
Method for outgoing transactions
Method to be implemented by the algorithms. Returns the total amount of the transaction.
Method for transaction with movement qty set to zero
Method that returns zero cost with no further calculation when the movement quantity is zero. It can be overriden by algorithms, if this method returns null means that the transaction cost be calculated as a regular transaction based on its type.
Default transaction cost
There are some corner cases when is not possible to get the price of the transaction to calculate the cost. For example a negative shipment. On these cases the default transaction cost method is used. This method takes into account the purchase price list of the product (if the transaction has a business partner its purchase price list is used) and the default standard cost of the product. If both values are available it uses the newer one. If none is available it throws an exception.
The default standard cost is a record on the Costing tab of the Product window with Cost Type Standard Cost. This value has to be added on a defined date range. It is the same value used for the Standard Algorithm.
Cost initialization
TBD Method to initialize the cost when a new costing rule is added.
Method for cost adjustments
Method to populate the Cost Adjustment lines when an adjustment needs to be done. It has to search the transactions that are affected by the adjustment and calculate the amount that needs to be adjusted.
Implemented Costing Algorithms
Average Costing
Standard Costing
The cost is stored for a date range in Product's Costing tab. This cost is used for all transactions during that period of time. This cost has to be logged manually for each legal entity.
List of common transaction types
Receipt
Cost calculated based on the related Order price, not including taxes.
Exceptions
- If the price of the related order is changed afterwards there is no adjustment done on the calculated cost. This cost difference is considered when the Purchase Invoice with the new price is processed. As would be considered a price change that happens only in the invoice.
- If there is not related oder it uses the newer of the following 3 values:
- Last purchase order price of the receipt's vendor for the product.
- Purchase pricelist of the product.
- Default Cost of the product.
Return Receipt
Regular outgoing transaction cost.
Shipment
Regular outgoing transaction cost.
Return Shipment
Cost calculated based on the proportional cost of the original returned shipment.
Exceptions
- If the original shipment is not found default cost method is used.
Physical inventory increasing stock
Cost based on the default cost method.
Physical inventory decreasing stock
Regular outgoing transaction cost.
Internal movement from
Regular outgoing transaction cost.
Internal movement to
Same cost than the From transaction.
Internal consumption
Regular outgoing transaction cost.
Used BOM Production part
Regular outgoing transaction cost.
Produced BOM Production product
Sum of transaction costs of each part used to produce the BOM product.
Manufacturing product
TBD Manufacturing costs have to be reimplemented from PL to Java.
Other implemented transaction types
In Openbravo ERP there are other less common transaction types implemented whose cost needs to be calculated as well.
Canceled Receipt
Cost calculated based on the original receipt cost (including cost adjustments added to the original receipt before the cancellation). If no original receipt is found cost is calculated as a regular outgoing transaction.
Canceled Shipment
Cost calculated based on the original shipment cost (including cost adjustments added to the original shipment before the cancellation). If no original shipment is found cost is calculated based on the default cost method.
Canceled Internal consumption
Same cost that the canceled internal consumption (including cost adjustments added to the original shipment before the cancellation). If no original internal consumption is found cost is calculated based on the default cost method.
Negative Receipt
Regular outgoing transaction cost.
Negative Shipment
Cost is calculated based on the default cost method.
Negative Internal consumption
Cost is calculated based on the default cost method.