Fixed: Production run not created for marketing package auto type product if component inventory is not available

(OFBIZ-10585)

When we create an order for marketing package auto, the system checks the component inventory and if found then it creates the production run job and produce marketing package inventory, but if component quantity not available then it does not create the job. So if we don't have an inventory item of component then production run should be created with created status.

Thanks: Yashwant Dhakad for report and Ankush Upadhyay for the patch.
This commit is contained in:
Pawan Verma
2019-11-23 11:59:07 +05:30
parent 463648a6ea
commit d00208cad9
3 changed files with 28 additions and 9 deletions
@@ -2800,6 +2800,29 @@ public class ProductionRunServices {
BigDecimal mktgPackagesAvailable = (BigDecimal) serviceResult.get("availableToPromiseTotal");
BigDecimal qtyToProduce = qtyRequired.min(mktgPackagesAvailable);
/*
Creating production run job for remaining quantity in created status
This will handle cases like if production run job creates for partial quantities or in case of fully backordered scenario.
*/
BigDecimal remainingQty = orderItem.getBigDecimal("quantity").subtract(qtyToProduce);
if(remainingQty.compareTo(ZERO) > 0) {
serviceContext.clear();
serviceContext.put("facilityId", facilityId);
serviceContext.put("userLogin", userLogin);
serviceContext.put("productId", orderItem.getString("productId"));
serviceContext.put("pRQuantity", remainingQty);
serviceContext.put("startDate", UtilDateTime.nowTimestamp());
serviceResult = dispatcher.runSync("createProductionRun", serviceContext);
if (ServiceUtil.isError(serviceResult)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
}
String productionRunIdForRemainingQty = (String)serviceResult.get("productionRunId");
try {
delegator.create("WorkOrderItemFulfillment", UtilMisc.toMap("workEffortId", productionRunIdForRemainingQty, "orderId", orderId, "orderItemSeqId", orderItemSeqId));
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunForMarketingPackagesCreationError", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "errorString", e.getMessage()), locale));
}
}
if (qtyToProduce.compareTo(ZERO) > 0) {
if (Debug.verboseOn()) { Debug.logVerbose("Required quantity (all orders) = [" + qtyRequired + "] quantity to produce = [" + qtyToProduce + "]", module); }
@@ -361,7 +361,6 @@ under the License.
</#if>
</td>
</tr>
<#break><#-- need only the first one -->
</#list>
</#if>
<#-- show linked order lines -->
@@ -703,19 +703,16 @@ under the License.
<set from-field="parameters.productId" field="lookupMktgPkgParams.productId"/>
<entity-one entity-name="Product" value-field="product"/>
<set field="isMarketingPkgAuto" value="${groovy: org.apache.ofbiz.entity.util.EntityTypeUtil.hasParentType(delegator, 'ProductType', 'productTypeId', product.productTypeId, 'parentTypeId', 'MARKETING_PKG_AUTO')}" type="Boolean"/>
<!-- In case of MARKETING_PKG_AUTO, pass MANUF_COMPONENT else PRODUCT_COMPONENT for MARKETING_PKG_PICK-->
<if-compare field="isMarketingPkgAuto" operator="equals" value="true" type="Boolean">
<set field="productIdMap.productId" from-field="product.productId"/>
<call-service service-name="getProductInventoryAvailable" in-map-name="productIdMap">
<result-to-field result-name="availableToPromiseTotal"/>
<result-to-field result-name="quantityOnHandTotal"/>
</call-service>
<set field="lookupMktgPkgParams.type" value="MANUF_COMPONENT"/>
<else>
<set value="PRODUCT_COMPONENT" field="lookupMktgPkgParams.type"/>
<call-service service-name="getAssociatedProducts" in-map-name="lookupMktgPkgParams">
<result-to-field result-name="assocProducts"/>
</call-service>
</else>
</if-compare>
<call-service service-name="getAssociatedProducts" in-map-name="lookupMktgPkgParams">
<result-to-field result-name="assocProducts"/>
</call-service>
<!-- if there are any components, then the ATP and QOH are based on the quantities of those component
products and found with another service -->