Author: jacopoc
Date: Mon Mar 26 05:19:49 2007 New Revision: 522494 URL: http://svn.apache.org/viewvc?view=rev&rev=522494 Log: Improvements to the MRP algorithm: sales orders ship group dates are now considered, better handling of orders without dates (they are now moved far in the future). Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java ofbiz/trunk/applications/order/entitydef/entitygroup.xml ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java?view=diff&rev=522494&r1=522493&r2=522494 ============================================================================== --- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java (original) +++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java Mon Mar 26 05:19:49 2007 @@ -84,6 +84,7 @@ List listResult = null; try{ listResult = delegator.findAll("InventoryEventPlanned"); + //int numOfRecordsRemoved = delegator.removeByCondition("InventoryEventPlanned", null); } catch(GenericEntityException e) { Debug.logError(e,"Error : delegator.findAll(\"InventoryEventPlanned\")", module); return ServiceUtil.returnError("Problem, we can not find all the items of InventoryEventPlanned, for more detail look at the log"); @@ -111,6 +112,7 @@ while (listResultIt.hasNext()){ GenericValue tmpRequirement = (GenericValue)listResultIt.next(); listResultRoles.addAll(tmpRequirement.getRelated("RequirementRole")); + //int numOfRecordsRemoved = delegator.removeRelated("RequirementRole", tmpRequirement); } delegator.removeAll(listResultRoles); delegator.removeAll(listResult); @@ -139,11 +141,14 @@ // ---------------------------------------- // Loads all the approved sales order items and purchase order items // ---------------------------------------- + // This is the default required date for orders without dates spesified: + // by convention it is a date far in the future of 100 years. + Timestamp notAssignedDate = UtilDateTime.getYearStart(now, 0, 0, 100); resultList = null; iteratorResult = null; - parameters = UtilMisc.toMap("orderTypeId", "SALES_ORDER", "itemStatusId", "ITEM_APPROVED"); + parameters = UtilMisc.toMap("orderTypeId", "SALES_ORDER", "oiStatusId", "ITEM_APPROVED"); try { - resultList = delegator.findByAnd("OrderHeaderAndItems", parameters, UtilMisc.toList("orderId")); + resultList = delegator.findByAnd("OrderHeaderItemAndShipGroup", parameters, UtilMisc.toList("orderId")); } catch(GenericEntityException e) { Debug.logError(e, "Error : delegator.findByAnd(\"OrderItem\", parameters\")", module); Debug.logError(e, "Error : parameters = "+parameters,module); @@ -154,11 +159,29 @@ genericResult = (GenericValue) iteratorResult.next(); String productId = genericResult.getString("productId"); Double eventQuantityTmp = new Double(-1.0 * genericResult.getDouble("quantity").doubleValue()); - Timestamp estimatedShipDate = genericResult.getTimestamp("estimatedDeliveryDate"); - if (estimatedShipDate == null) { - estimatedShipDate = now; + // This is the order in which order dates are considered: + // OrderItemShipGroup.shipByDate + // OrderItemShipGroup.shipAfterDate + // OrderItem.shipBeforeDate + // OrderItem.shipAfterDate + // OrderItem.estimatedDeliveryDate + Timestamp requiredByDate = genericResult.getTimestamp("shipByDate"); + if (UtilValidate.isEmpty(requiredByDate)) { + requiredByDate = genericResult.getTimestamp("shipAfterDate"); + if (UtilValidate.isEmpty(requiredByDate)) { + requiredByDate = genericResult.getTimestamp("oiShipBeforeDate"); + if (UtilValidate.isEmpty(requiredByDate)) { + requiredByDate = genericResult.getTimestamp("oiShipAfterDate"); + if (UtilValidate.isEmpty(requiredByDate)) { + requiredByDate = genericResult.getTimestamp("oiEstimatedDeliveryDate"); + if (requiredByDate == null) { + requiredByDate = notAssignedDate; + } + } + } + } } - parameters = UtilMisc.toMap("productId", productId, "eventDate", estimatedShipDate, "inventoryEventPlanTypeId", "SALE_ORDER_SHIP"); + parameters = UtilMisc.toMap("productId", productId, "eventDate", requiredByDate, "inventoryEventPlanTypeId", "SALE_ORDER_SHIP"); try { InventoryEventPlannedServices.createOrUpdateInventoryEventPlanned(parameters, eventQuantityTmp, null, genericResult.getString("orderId") + "-" + genericResult.getString("orderItemSeqId"), false, delegator); } catch (GenericEntityException e) { @@ -408,13 +431,16 @@ } public static void logMrpError(String productId, String errorMessage, GenericDelegator delegator) { - try{ + logMrpError(productId, UtilDateTime.nowTimestamp(), errorMessage, delegator); + } + public static void logMrpError(String productId, Timestamp eventDate, String errorMessage, GenericDelegator delegator) { + try { if (UtilValidate.isNotEmpty(productId) && UtilValidate.isNotEmpty(errorMessage)) { GenericValue inventoryEventError = delegator.makeValue("InventoryEventPlanned", UtilMisc.toMap("productId", productId, - "eventDate", UtilDateTime.nowTimestamp(), + "eventDate", eventDate, "inventoryEventPlanTypeId", "ERROR", "eventName", errorMessage)); - inventoryEventError.create(); + delegator.createOrStore(inventoryEventError); } } catch (GenericEntityException e) { Debug.logError(e, "Error calling logMrpError for productId [" + productId + "] and errorMessage [" + errorMessage + "]", module); @@ -632,7 +658,7 @@ eventDate = inventoryEventForMRP.getTimestamp("eventDate"); // to be just before the requirement eventDate.setTime(eventDate.getTime()-1); - ProposedOrder proposedOrder = new ProposedOrder(product, facilityId, manufacturingFacilityId, isBuilt, eventDate, qtyToStock); + ProposedOrder proposedOrder = new ProposedOrder(product, facilityId, manufacturingFacilityId, isBuilt, eventDate, qtyToStock, now); proposedOrder.setMrpName(mrpName); // calculate the ProposedOrder quantity and update the quantity object property. proposedOrder.calculateQuantityToSupply(reorderQuantity, minimumStock, iteratorListInventoryEventForMRP); @@ -676,7 +702,7 @@ requirementId = proposedOrder.create(ctx, userLogin); } if (UtilValidate.isEmpty(productFacility) && !isBuilt) { - logMrpError(productId, "No ProductFacility record for [" + facilityId + "]; no requirement created.", delegator); + logMrpError(productId, now, "No ProductFacility record for [" + facilityId + "]; no requirement created.", delegator); } Map eventMap = UtilMisc.toMap("productId", product.getString("productId"), Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java?view=diff&rev=522494&r1=522493&r2=522494 ============================================================================== --- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java (original) +++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java Mon Mar 26 05:19:49 2007 @@ -57,10 +57,11 @@ protected String mrpName; protected Timestamp requiredByDate; protected Timestamp requirementStartDate; + protected Timestamp now; protected double quantity; - public ProposedOrder(GenericValue product, String facilityId, String manufacturingFacilityId, boolean isBuilt, Timestamp requiredByDate, double quantity) { + public ProposedOrder(GenericValue product, String facilityId, String manufacturingFacilityId, boolean isBuilt, Timestamp requiredByDate, double quantity, Timestamp now) { this.product = product; this.productId = product.getString("productId"); this.facilityId = facilityId; Modified: ofbiz/trunk/applications/order/entitydef/entitygroup.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitygroup.xml?view=diff&rev=522494&r1=522493&r2=522494 ============================================================================== --- ofbiz/trunk/applications/order/entitydef/entitygroup.xml (original) +++ ofbiz/trunk/applications/order/entitydef/entitygroup.xml Mon Mar 26 05:19:49 2007 @@ -50,6 +50,7 @@ <entity-group group="org.ofbiz" entity="OrderHeaderItemAndInv" /> <entity-group group="org.ofbiz" entity="OrderHeaderItemAndInvRoles" /> <entity-group group="org.ofbiz" entity="OrderHeaderItemAndRoles" /> + <entity-group group="org.ofbiz" entity="OrderHeaderItemAndShipGroup" /> <entity-group group="org.ofbiz" entity="OrderHeaderNote" /> <entity-group group="org.ofbiz" entity="OrderHeaderNoteView" /> <entity-group group="org.ofbiz" entity="OrderHeaderWorkEffort" /> Modified: ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml?view=diff&rev=522494&r1=522493&r2=522494 ============================================================================== --- ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml (original) +++ ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml Mon Mar 26 05:19:49 2007 @@ -594,6 +594,44 @@ <key-map field-name="productId"/> </relation> </view-entity> + <view-entity entity-name="OrderHeaderItemAndShipGroup" + package-name="org.ofbiz.order.order" + never-cache="true" + title="OrderHeader, OrderItem And ShipGroups View Entity"> + <member-entity entity-alias="OH" entity-name="OrderHeader"/> + <member-entity entity-alias="OI" entity-name="OrderItem"/> + <member-entity entity-alias="OISGA" entity-name="OrderItemShipGroupAssoc"/> + <member-entity entity-alias="OISG" entity-name="OrderItemShipGroup"/> + <alias-all entity-alias="OH"/> + <alias-all entity-alias="OISGA"/> + <alias-all entity-alias="OISG"/> + <alias-all entity-alias="OI"> + <exclude field="quantity"/> + <exclude field="cancelQuantity"/> + <exclude field="shipAfterDate"/> + <exclude field="shipBeforeDate"/> + <exclude field="estimatedShipDate"/> + <exclude field="estimatedDeliveryDate"/> + </alias-all> + <alias entity-alias="OI" name="oiQuantity" field="quantity"/> + <alias entity-alias="OI" name="oiCancelQuantity" field="cancelQuantity"/> + <alias entity-alias="OI" name="oiShipAfterDate" field="shipAfterDate"/> + <alias entity-alias="OI" name="oiShipBeforeDate" field="shipBeforeDate"/> + <alias entity-alias="OI" name="oiEstimatedShipDate" field="estimatedShipDate"/> + <alias entity-alias="OI" name="oiEstimatedDeliveryDate" field="estimatedDeliveryDate"/> + <alias entity-alias="OI" name="oiStatusId" field="statusId"/> + <view-link entity-alias="OH" rel-entity-alias="OI"> + <key-map field-name="orderId"/> + </view-link> + <view-link entity-alias="OI" rel-entity-alias="OISGA"> + <key-map field-name="orderId"/> + <key-map field-name="orderItemSeqId"/> + </view-link> + <view-link entity-alias="OISGA" rel-entity-alias="OISG"> + <key-map field-name="orderId"/> + <key-map field-name="shipGroupSeqId"/> + </view-link> + </view-entity> <view-entity entity-name="OrderItemAndShipGroupAssoc" package-name="org.ofbiz.order.order" never-cache="true" |
Free forum by Nabble | Edit this page |