Package org.openbravo.costing
Class CostingAlgorithm
- java.lang.Object
-
- org.openbravo.costing.CostingAlgorithm
-
- Direct Known Subclasses:
AverageAlgorithm
,StandardAlgorithm
public abstract class CostingAlgorithm extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CostingAlgorithm.CostDimension
Dimensions available to manage the cost on an entity.
-
Field Summary
Fields Modifier and Type Field Description protected Currency
costCurrency
protected HashMap<CostingAlgorithm.CostDimension,BaseOBObject>
costDimensions
protected CostingRule
costingRule
protected Organization
costOrg
protected static org.apache.logging.log4j.Logger
log4j
protected MaterialTransaction
transaction
protected CostingServer.TrxType
trxType
-
Constructor Summary
Constructors Constructor Description CostingAlgorithm()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected BigDecimal
getBOMPartCost()
Calculates the cost of a BOM Production used part using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.protected BigDecimal
getBOMProductCost()
Calculates the cost of a produced BOM product.Currency
getCostCurrency()
protected BigDecimal
getDefaultCost()
protected BigDecimal
getInternalConsCost()
Calculates the cost of an Internal Consumption line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.protected BigDecimal
getInternalConsNegativeCost()
Calculates the cost of a negative internal consumption using the Default Cost.protected BigDecimal
getInternalConsVoidCost()
Returns the cost of the original internal consumption.protected BigDecimal
getIntMovementFromCost()
Calculates the cost of the From transaction of an Internal Movement line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.protected BigDecimal
getIntMovementToCost()
Calculates the total cost amount of an incoming internal movement.protected BigDecimal
getInventoryClosingCost()
Calculates the total cost amount of the physical inventory as if it were an Inventory Decrease transaction.protected BigDecimal
getInventoryDecreaseCost()
Calculates the cost of a Inventory line that decrease the stock using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.protected BigDecimal
getInventoryIncreaseCost()
Calculates the total cost amount of a physical inventory that results on an increment of stock.protected BigDecimal
getInventoryOpeningCost()
Calculates the total cost amount of the physical inventory as if it were an Inventory Increase transaction.protected BigDecimal
getOriginalInOutLineCost()
Returns the cost of the canceled Shipment/Receipt line on the date it is canceled.protected abstract BigDecimal
getOutgoingTransactionCost()
Calculates the total cost amount of an outgoing transaction.protected BigDecimal
getPriceListCost()
Calculates the transaction cost based on the purchase price list of the product.protected BigDecimal
getReceiptCost()
protected BigDecimal
getReceiptDefaultCost()
protected BigDecimal
getReceiptNegativeCost()
Calculates the cost of a Negative Receipt line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.protected BigDecimal
getReceiptReturnCost()
Calculates the cost of a Returned Receipt line as a regular outgoing transaction.protected BigDecimal
getReceiptVoidCost()
Method to calculate the cost of Voided Receipts.protected BigDecimal
getReturnedInOutLineCost()
Gets the returned in out line and returns the proportional cost amount based on the original movement quantity and the returned movement quantity.protected BigDecimal
getShipmentCost()
Calculates the cost of a Shipment line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.protected BigDecimal
getShipmentNegativeCost()
Calculates the cost of a negative Shipment line.protected BigDecimal
getShipmentReturnCost()
Method to calculate cost of Returned Shipments.protected BigDecimal
getShipmentVoidCost()
Method to calculate the cost of Voided Shipments.BigDecimal
getTransactionCost()
Based on the transaction type, calls the corresponding method to calculate and return the total cost amount of the transaction.protected BigDecimal
getTransactionStandardCost()
Calculates the transaction cost based on the Standard Cost of the product on the Transaction Process Date.protected BigDecimal
getZeroMovementQtyCost()
Auxiliary method for transactions with 0 Movement quantity.void
init(CostingServer costingServer)
Initializes the instance of the CostingAlgorith with the MaterialTransaction that is being to be calculated and the cost dimensions values in case they have to be used.
-
-
-
Field Detail
-
transaction
protected MaterialTransaction transaction
-
costDimensions
protected HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions
-
costOrg
protected Organization costOrg
-
costCurrency
protected Currency costCurrency
-
trxType
protected CostingServer.TrxType trxType
-
costingRule
protected CostingRule costingRule
-
log4j
protected static org.apache.logging.log4j.Logger log4j
-
-
Method Detail
-
init
public void init(CostingServer costingServer)
Initializes the instance of the CostingAlgorith with the MaterialTransaction that is being to be calculated and the cost dimensions values in case they have to be used. It initializes several values:- Organization, it's used the Legal Entity dimension. If this is null Asterisk organization is used.
- Currency, it takes the currency defined for the Organization. If this is null it uses the currency defined for the Client.
- Transaction Type, it calculates its type.
- Parameters:
costingServer
- CostingServer instance calculating the cost of the transaction.
-
getTransactionCost
public BigDecimal getTransactionCost() throws OBException
Based on the transaction type, calls the corresponding method to calculate and return the total cost amount of the transaction.- Returns:
- the total cost amount of the transaction.
- Throws:
OBException
- when the transaction type is unknown.
-
getOutgoingTransactionCost
protected abstract BigDecimal getOutgoingTransactionCost()
Calculates the total cost amount of an outgoing transaction.
-
getZeroMovementQtyCost
protected BigDecimal getZeroMovementQtyCost()
Auxiliary method for transactions with 0 Movement quantity. It can be overwritten by Costing Algorithms to return null if further actions are needed.
-
getShipmentCost
protected BigDecimal getShipmentCost()
Calculates the cost of a Shipment line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getShipmentReturnCost
protected BigDecimal getShipmentReturnCost()
Method to calculate cost of Returned Shipments. Cost is calculated based on the proportional cost of the original receipt. If no original receipt is found the default cost is returned.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getShipmentVoidCost
protected BigDecimal getShipmentVoidCost()
Method to calculate the cost of Voided Shipments. By default the cost is calculated getting the cost of the original shipment. If no original shipment is found the Default Cost is returned.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getShipmentNegativeCost
protected BigDecimal getShipmentNegativeCost()
Calculates the cost of a negative Shipment line. By default if the product is purchased the cost is based on its purchase price. If it is not purchased its Standard Cost is used.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getReceiptCost
protected BigDecimal getReceiptCost()
-
getReceiptReturnCost
protected BigDecimal getReceiptReturnCost()
Calculates the cost of a Returned Receipt line as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getReceiptVoidCost
protected BigDecimal getReceiptVoidCost()
Method to calculate the cost of Voided Receipts. By default the cost is calculated getting the cost of the original payment. If no original Receipt is found cost is calculated as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getReceiptNegativeCost
protected BigDecimal getReceiptNegativeCost()
Calculates the cost of a Negative Receipt line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getReceiptDefaultCost
protected BigDecimal getReceiptDefaultCost()
-
getOriginalInOutLineCost
protected BigDecimal getOriginalInOutLineCost() throws OBException
Returns the cost of the canceled Shipment/Receipt line on the date it is canceled.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
- Throws:
OBException
- when no original in out line is found.
-
getReturnedInOutLineCost
protected BigDecimal getReturnedInOutLineCost() throws OBException
Gets the returned in out line and returns the proportional cost amount based on the original movement quantity and the returned movement quantity.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
- Throws:
OBException
- when no original in out line is found.
-
getInventoryDecreaseCost
protected BigDecimal getInventoryDecreaseCost()
Calculates the cost of a Inventory line that decrease the stock using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getInventoryIncreaseCost
protected BigDecimal getInventoryIncreaseCost()
Calculates the total cost amount of a physical inventory that results on an increment of stock. Default Cost is used.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getInventoryOpeningCost
protected BigDecimal getInventoryOpeningCost()
Calculates the total cost amount of the physical inventory as if it were an Inventory Increase transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getInventoryClosingCost
protected BigDecimal getInventoryClosingCost()
Calculates the total cost amount of the physical inventory as if it were an Inventory Decrease transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getIntMovementFromCost
protected BigDecimal getIntMovementFromCost()
Calculates the cost of the From transaction of an Internal Movement line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getIntMovementToCost
protected BigDecimal getIntMovementToCost()
Calculates the total cost amount of an incoming internal movement. The cost amount is the same than the related outgoing transaction. The outgoing transaction cost is calculated if it has not been yet.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
- Throws:
OBException
- when no related internal movement is found.
-
getInternalConsCost
protected BigDecimal getInternalConsCost()
Calculates the cost of an Internal Consumption line using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getInternalConsNegativeCost
protected BigDecimal getInternalConsNegativeCost()
Calculates the cost of a negative internal consumption using the Default Cost.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getInternalConsVoidCost
protected BigDecimal getInternalConsVoidCost()
Returns the cost of the original internal consumption.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getBOMPartCost
protected BigDecimal getBOMPartCost()
Calculates the cost of a BOM Production used part using by default thegetOutgoingTransactionCost()
method as a regular outgoing transaction.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getBOMProductCost
protected BigDecimal getBOMProductCost()
Calculates the cost of a produced BOM product. Its cost is the sum of the used products transactions costs. If these has not been calculated yet they are calculated.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getDefaultCost
protected BigDecimal getDefaultCost()
-
getTransactionStandardCost
protected BigDecimal getTransactionStandardCost()
Calculates the transaction cost based on the Standard Cost of the product on the Transaction Process Date.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
-
getPriceListCost
protected BigDecimal getPriceListCost()
Calculates the transaction cost based on the purchase price list of the product. It searches first for a default price list and if none exists takes one.- Returns:
- BigDecimal object representing the total cost amount of the transaction.
- Throws:
OBException
- when no PriceList is found for the product.
-
getCostCurrency
public Currency getCostCurrency()
- Returns:
- the base currency used to calculate all the costs.
-
-