If any one is interested, I finished and it works, removing the oldest
inventory first.
<simple-method method-name="createPhysicalInventoryAndVariance"
short-description="Create a PhysicalInventory and an InventoryItemVariance">
<entity-condition entity-name="InventoryItem"
list="inventoryItemList">
<condition-list combine="or">
<condition-expr field-name="productId" operator="equals"
from-field="parameters.productId"/>
<condition-expr field-name="quantityOnHandTotal"
operator="not-equals" value="0"/>
</condition-list>
<order-by field-name="datetimeReceived"/>
</entity-condition>
<set field="MyVariance" from-field="parameters.quantityOnHandVar"
type="BigDecimal"/>
<set field="MyCompareValue" value="1" type="BigDecimal"/>
<iterate list="inventoryItemList" entry="inventoryItem">
<set field="parameters.inventoryItemId"
from-field="inventoryItem.inventoryItemId"/>
<if-not-empty field="parameters.quantityOnHandVar">
<if-compare field="parameters.quantityOnHandVar"
operator="not-equals" value="0">
<if-compare field="parameters.quantityOnHandVar"
operator="greater" value="0">
<set from-field="parameters.quantityOnHandVar"
field="parameters.availableToPromiseVar"/>
<set-service-fields service-name="createPhysicalInventory"
map="parameters" to-map="createPhysicalInventoryMap"/>
<call-service service-name="createPhysicalInventory"
in-map-name="createPhysicalInventoryMap">
<result-to-field result-name="physicalInventoryId"
field="parameters.physicalInventoryId"/>
<result-to-result result-name="physicalInventoryId"
service-result-name="physicalInventoryId"/>
</call-service>
<set-service-fields
service-name="createInventoryItemVariance" map="parameters"
to-map="createInventoryItemVarianceMap"/>
<call-service service-name="createInventoryItemVariance"
in-map-name="createInventoryItemVarianceMap"/>
<set field="parameters.quantityOnHandVar" value="0"
type="BigDecimal"/>
</if-compare>
<if-compare field="parameters.quantityOnHandVar"
operator="less" value="0">
<set field="MyCompareValue" from-field =
"${inventoryItem.quantityOnHandTotal + parameters.quantityOnHandVar}"
type="BigDecimal" default-value="0"/>
<if-compare field="MyCompareValue"
operator="greater-equals" value="0" type="BigDecimal">
<set from-field="parameters.quantityOnHandVar"
field="parameters.availableToPromiseVar"/>
<set-service-fields
service-name="createPhysicalInventory" map="parameters"
to-map="createPhysicalInventoryMap"/>
<call-service service-name="createPhysicalInventory"
in-map-name="createPhysicalInventoryMap">
<result-to-field result-name="physicalInventoryId"
field="parameters.physicalInventoryId"/>
<result-to-result result-name="physicalInventoryId"
service-result-name="physicalInventoryId"/>
</call-service>
<set-service-fields
service-name="createInventoryItemVariance" map="parameters"
to-map="createInventoryItemVarianceMap"/>
<call-service service-name="createInventoryItemVariance"
in-map-name="createInventoryItemVarianceMap"/>
<set field="parameters.quantityOnHandVar" value="0"
type="BigDecimal"/>
</if-compare>
<if-compare field="parameters.quantityOnHandVar"
operator="not-equals" value="0">
<if-compare field="inventoryItem.quantityOnHandTotal"
operator="greater" value="0">
<set field="MyVariance"
from-field="inventoryItem.quantityOnHandTotal" type="BigDecimal"/>
<set field="MyVariance" value="${MyVariance * -1}"/>
<set field="parameters.quantityOnHandVar"
value="${MyVariance}" type="BigDecimal"/>
<set from-field="parameters.quantityOnHandVar"
field="parameters.availableToPromiseVar"/>
<set-service-fields
service-name="createPhysicalInventory" map="parameters"
to-map="createPhysicalInventoryMap"/>
<call-service service-name="createPhysicalInventory"
in-map-name="createPhysicalInventoryMap">
<result-to-field result-name="physicalInventoryId"
field="parameters.physicalInventoryId"/>
<result-to-result
result-name="physicalInventoryId"
service-result-name="physicalInventoryId"/>
</call-service>
<set-service-fields
service-name="createInventoryItemVariance" map="parameters"
to-map="createInventoryItemVarianceMap"/>
<call-service
service-name="createInventoryItemVariance"
in-map-name="createInventoryItemVarianceMap"/>
<set field="parameters.quantityOnHandVar"
from-field="MyCompareValue"/>
</if-compare>
</if-compare>
</if-compare>
</if-compare>
</if-not-empty>
</iterate>
<set from-field="parameters.quantityOnHandVar"
field="parameters.availableToPromiseVar"/>
<set-service-fields service-name="createPhysicalInventory"
map="parameters" to-map="createPhysicalInventoryMap"/>
<call-service service-name="createPhysicalInventory"
in-map-name="createPhysicalInventoryMap">
<result-to-field result-name="physicalInventoryId"
field="parameters.physicalInventoryId"/>
<result-to-result result-name="physicalInventoryId"
service-result-name="physicalInventoryId"/>
</call-service>
<set-service-fields service-name="createInventoryItemVariance"
map="parameters" to-map="createInventoryItemVarianceMap"/>
<call-service service-name="createInventoryItemVariance"
in-map-name="createInventoryItemVarianceMap"/>
</simple-method>
-----
Joel Fradkin
--
View this message in context:
http://ofbiz.135035.n4.nabble.com/Need-to-modfy-createInventoryItemVariance-tp4657198p4657247.html
Sent from the OFBiz - User mailing list archive at Nabble.com.