ATP Formula Service
The following describes the ATP Formula Service in Order Management.
The ATP Formula Service is found in the warehousing extension. It allows you to create ATP formulas so that you can apply one of them to a base store.
Overview
API
This section describes the most important methods to use for ATP formulas.
AtpFormulaService.java:
/**
* Retrieves an {@link AtpFormulaModel} by its code.
*
* @param formulaCode
* The formula code for which we want to retrieve a specific {@link AtpFormulaModel}.
* @return the corresponding {@link AtpFormulaModel}.
*/
AtpFormulaModel getAtpFormulaByCode(String formulaCode);
/**
* Creates an {@link AtpFormulaModel}
*
* @param atpFormula
* The ATP formula to be created.
* @return the created {@link AtpFormulaModel}.
*/
AtpFormulaModel createAtpFormula(AtpFormulaModel atpFormula);
/**
* Updates an {@link AtpFormulaModel} based on its code
*
* @param atpFormula
* The ATP formula to be updated.
* @return the up to date {@link AtpFormulaModel}.
*/
AtpFormulaModel updateAtpFormula(AtpFormulaModel atpFormula);
/**
* Deletes an {@link AtpFormulaModel} from its code. Only possible if the formula is not assign to any base store
*
* @param formulaCode
* The formula code that we want to delete
*/
void deleteAtpFormula(String formulaCode);
/**
* Retrieves the ATP value from a specific formula
* @param atpFormula
* The {@link AtpFormulaModel} from which we want to retrieve the ATP value
* @param params
* The list of {@link de.hybris.platform.ordersplitting.model.StockLevelModel} to gather in order to define the ATP value
* @return the number of available item according to the params
*/
Long getAtpValueFromFormula(AtpFormulaModel atpFormula, Map<String, Object> params);
Getting an ATP Value From a Formula
The getAtpValueFromFormula method of the service retrieves the corresponding ATP value according to the formula and parameters given as arguments. It runs the calculation for every ATP formula variable and sums them up to return the final aggregated value.
Getting a Value for a Specific Variable
The getAtpFormulaVariableValue method is called for each entry in the VariableOperatorMap of the ATP formula.
DefaultAtpFormulaService.java:
/**
* Gets the value for a specific atpformula variable name
* @param params
* The parameters to apply to the method matching the name in {@link AvailableToPromiseDao}
* @param results
* The list of results already found and to which the result must be added
* @param formulaVarPropDescriptor
* The {@link PropertyDescriptor} for AtpFormulaVariable's property for which the value is requested
* @param atpFormula
* Indicates whether or not the value needs to ba added or subtracted
* @return the complete list of values including the found value
*/
protected List<Long> getAtpFormulaVariableValue(final Map<String, Object> params, final List<Long> results,
final PropertyDescriptor formulaVarPropDescriptor, final AtpFormulaModel atpFormula)
{
...
}
This method uses Java reflection to identify which method has to be used from the AvailableToPromiseDao. It also interprets if the value needs to be added or subtracted.
In the warehousing extension, the following ATP formula variables are provided by default.
warehousing-items.xml:
...
<typegroup name="AtpFormula">
<itemtype code="AtpFormula" autocreate="true" generate="true">
<description>Represents the attributes of an ATP formula.</description>
<deployment table="atpformulas" typecode="6509"/>
<attributes>
<attribute type="java.lang.String" qualifier="code">
<modifiers read="true" write="true" unique="true" optional="false"/>
<persistence type="property"/>
<description>A unique name of the formula.</description>
</attribute>
<attribute qualifier="availability" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how availability be included in the ATP calculation</description>
</attribute>
<attribute qualifier="allocation" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how allocation be included in the ATP calculation</description>
</attribute>
<attribute qualifier="cancellation" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how cancellation be included in the ATP calculation</description>
</attribute>
<attribute qualifier="increase" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how increase be included in the ATP calculation</description>
</attribute>
<attribute qualifier="reserved" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how reserved be included in the ATP calculation</description>
</attribute>
<attribute qualifier="shrinkage" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how shrinkage be included in the ATP calculation</description>
</attribute>
<attribute qualifier="wastage" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how wastage be included in the ATP calculation</description>
</attribute>
<attribute qualifier="external" type="java.lang.Boolean">
<modifiers read="true" write="true"/>
<persistence type="property"/>
<description>A flag to indicate how external availability be included in the ATP calculation</description>
</attribute>
<attribute qualifier="formulaString" type="java.lang.String">
<description>String representation of the AtpFormula</description>
<modifiers write="false" read="true"/>
<persistence type="dynamic" attributeHandler="atpFormulaStringHandler"/>
</attribute>
</attributes>
</itemtype>
</typegroup>
...
Which Formula is Used?
Now, how do you know which formula is used by the system to retrieve the ATP value? This is a configuration that is provided at the base store level. Each base store has a property which defines the default fallback ATP formula to be used.
warehousing-items.xml:
...
<relation code="BaseStore2AtpFormulaRelation" autocreate="true"
generate="true" localized="false">
<sourceElement type="BaseStore" qualifier="baseStores" cardinality="many" collectiontype="set">
</sourceElement>
<targetElement type="AtpFormula" qualifier="defaultAtpFormula" cardinality="one">
<modifiers/>
</targetElement>
</relation>
...
Import Formula Through Impex
By default, the same formula is used for all base stores. It is possible to adjust this via the admin console or via impex too. The ordermanagementaddon extension contains the import of the default ATP formula.
sourcing.impex:
INSERT_UPDATE AtpFormula;code[unique=true];availability;allocation;cancellation;increase;reserved;shrinkage;wastage ;Default_Formula;true;true;true;true;true;true;true;true INSERT_UPDATE BaseStore;uid[unique=true];defaultAtpFormula(code); ;electronics;Default_Formula; ;apparel-de;Default_Formula; ;apparel-uk;Default_Formula; ;powertools;Default_Formula;
The formula that represents this is the following:
AVAILABLE - ALLOCATED + CANCELLED + INCREASE - RESERVED - SHRINKAGE - WASTAGE + EXTERNAL
The AVAILABLE variable is always included in the formula and the Backoffice will always have it included by default and it can't be modified.
An important change is done to the way you can import the formula. You can either include a variable or exclude it. By default, those variables are configured in the Spring file to indicate which one is added and which is subtracted.
<!--The key in the map below must be AtpFormula variable and the value must always be either + or -
If the atpformula variable is not included in this map, the variable would not be considered while calculation, even if its included in the formula.
Also, if the sign is not either of + or -, that variable would be discarded during the calculation-->
<alias name="defaultAtpFormulaVar2ArithmeticOperatorMap" alias="atpFormulaVar2ArithmeticOperatorMap"/>
<util:map id="defaultAtpFormulaVar2ArithmeticOperatorMap" key-type="java.lang.String" value-type="java.lang.String">
<entry key="availability" value="+"/>
<entry key="allocation" value="-"/>
<entry key="cancellation" value="+"/>
<entry key="increase" value="+"/>
<entry key="reserved" value="-"/>
<entry key="shrinkage" value="-"/>
<entry key="wastage" value="-"/>
<entry key="returned" value="+"/>
<entry key="external" value="+"/>
</util:map>
This map is extensible and can accept a value of "+" or "-" for any additional variable that is added by customization. If this map was configured wrongfully by adding a value that is not "+" or "-" or a key that is not valid an exception will be thrown and the ATP value will be 0.
How is my Formula Aware of the Context in the Calculation?
Some classes that request the ATP calculation must be context specific in order to return the appropriate value. To enable the ATP formula, some beans leverage the scope prototype in order to keep in mind the context of execution. These prototypes must be fed with the ATP formula which is required by the commerceStockLevelCalculationStrategy.
warehousing-spring.xml:
...
<alias alias="warehouseStockService" name="defaultWarehouseStockService"/>
<bean id="defaultWarehouseStockService" scope="prototype"
class="de.hybris.platform.warehousing.stock.services.impl.DefaultWarehouseStockService">
<property name="stockService" ref="stockService"/>
<property name="commerceStockLevelCalculationStrategy" ref="commerceStockLevelCalculationStrategy"/>
<property name="stockLevelDao" ref="stockLevelDao"/>
<property name="modelService" ref="modelService"/>
<property name="warehouseStockLevelDao" ref="warehouseStockLevelDao"/>
</bean>
...
<alias alias="commerceStockLevelCalculationStrategy" name="warehousingAvailabilityCalculationStrategy"/>
<bean id="warehousingAvailabilityCalculationStrategy" parent="defaultCommerceStockLevelCalculationStrategy" scope="prototype"
class="de.hybris.platform.warehousing.atp.strategy.impl.WarehousingAvailabilityCalculationStrategy">
<property name="availableToPromiseDao" ref="availableToPromiseDao"/>
<property name="atpFormulaService" ref="atpFormulaService"/>
<property name="restockConfigService" ref="restockConfigService"/>
</bean>
...
<alias alias="stockLevelStatusStrategy" name="warehousingStockLevelStatusStrategy"/>
<bean id="warehousingStockLevelStatusStrategy" scope="prototype"
parent="commerceStockLevelStatusStrategy">
</bean>
<alias alias="stockService" name="warehousingStockService"/>
<bean id="warehousingStockService" scope="prototype"
parent="defaultStockService">
</bean>
...
-
DefaultAllocationService: The manual reallocation sets the ATP formula of the warehouseStockService.
- DefaultOutOfStockDeclineStrategy and DefaultDamagedStockLevelStrategy: The execution of the strategy sets the ATP formula of the warehouseStockService.
- WarehousingCommerceStockService:
-
getStockLevelForProductAndPointOfService, getStockLevelForProductAndBaseStore, getPosAndStockLevelStatusForProduct sets the ATP formula of the CommerceStockLevelCalculationStrategy.
- getStockLevelStatusForProductAndBaseStore, getStockLevelStatusForProductAndPointOfService sets the ATP formula of the CommerceStockLevelCalculationStrategy for the StockLevelStatusStrategy of the StockService.
-
- AvailabilitySourcingLocationPopulator and AvailabilitySourcingLocationFilter: Sets the ATP formula of the warehouseStockService.
- DefaultWarehouseStockService: Sets the ATP formula of the CommerceStockLevelCalculationStrategy.
- ConsignmentToReallocateController: Sets the ATP formula of the warehouseStockService.
Restock Configuration
It is important to note that the WarehousingAvailabilityCalculationStrategy contains a method to calculate availability; it filters out products of stock as well as products contained in the stock level bin that have the same bin code configured in the Restock Config. (via WarehouseAdministrator).
Class Diagram
The class diagram provides a general overview of the classes and interfaces for the ATP formula service.
From the Backoffice Application
To access the ATP formula feature from the Backoffice Administration Cockpit, you must login as a WarehouseAdministrator. Under the ATP Formulas screen, you can configure ATP formulas by including or excluding variables.
The AVAILABLE variable is always included by default and can't be modified.