From 20232002c70b6fc9cd636bbceddc1637e07d1791 Mon Sep 17 00:00:00 2001 From: Jacopo Cappellato Date: Thu, 19 Apr 2007 15:36:38 +0000 Subject: [PATCH] First version of the methods to compute the start date of requirements created by the MRP for products with WIP in their BOM. More tests still need to be done. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@530461 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/ofbiz/manufacturing/bom/BOMNode.java | 22 +++++++++++++++++++ .../jobshopmgt/ProductionRunServices.java | 8 +------ .../ofbiz/manufacturing/mrp/MrpServices.java | 4 +--- .../manufacturing/mrp/ProposedOrder.java | 13 ++++++++--- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java b/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java index bc7a6cbb5a..1dcaf6a096 100644 --- a/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java +++ b/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java @@ -38,6 +38,8 @@ import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.manufacturing.mrp.ProposedOrder; + /** An ItemCoinfigurationNode represents a component in a bill of materials. */ @@ -563,6 +565,26 @@ public class BOMNode { return productionRunId; } + public Timestamp getStartDate(String facilityId, Timestamp requiredBydate) { + Timestamp minStartDate = requiredBydate; + if ("WIP".equals(getProduct().getString("productTypeId"))) { + ProposedOrder proposedOrder = new ProposedOrder(getProduct(), facilityId, facilityId, true, requiredBydate, getQuantity()); + proposedOrder.calculateStartDate(0, null, delegator, dispatcher, userLogin); + Timestamp startDate = proposedOrder.getRequirementStartDate(); + minStartDate = startDate; + for (int i = 0; i < childrenNodes.size(); i++) { + BOMNode oneChildNode = (BOMNode)childrenNodes.get(i); + if (oneChildNode != null) { + Timestamp childStartDate = oneChildNode.getStartDate(facilityId, startDate); + if (childStartDate.compareTo(minStartDate) < 0) { + minStartDate = childStartDate; + } + } + } + } + return minStartDate; + } + public boolean isWarehouseManaged() { boolean isWarehouseManaged = false; try { diff --git a/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java b/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java index 7e6ba662d5..7397af2e61 100644 --- a/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java +++ b/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java @@ -1834,13 +1834,7 @@ public class ProductionRunServices { } String productionRunId = (String)resultService.get("productionRunId"); result.put("productionRunId", productionRunId); - -// try { -// requirement.remove(); -// } catch (GenericEntityException e) { -// return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRequirementNotDeleted", locale)); -// } - + result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunCreated",UtilMisc.toMap("productionRunId", productionRunId), locale)); return result; } diff --git a/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java b/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java index 1692f80113..e48e4b538e 100644 --- a/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java +++ b/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java @@ -600,9 +600,7 @@ public class MrpServices { Debug.logError("Error : parameters = "+parameters,module); return ServiceUtil.returnError("Problem, can not initialise the table InventoryEventPlanned, for more detail look at the log"); } - // TODO : modifier le jeux d'essai de TGR pour mettre 0 au niveau pf long bomLevel = 0; - // iteration for the bomLevel for which there are some events do { //get the products from the InventoryEventPlanned table for the current billOfMaterialLevel (ie. BOM) parameters = UtilMisc.toMap("billOfMaterialLevel", new Long(bomLevel), "userLogin", userLogin); @@ -677,7 +675,7 @@ public class MrpServices { 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, now); + ProposedOrder proposedOrder = new ProposedOrder(product, facilityId, manufacturingFacilityId, isBuilt, eventDate, qtyToStock); proposedOrder.setMrpName(mrpName); // calculate the ProposedOrder quantity and update the quantity object property. proposedOrder.calculateQuantityToSupply(reorderQuantity, minimumStock, iteratorListInventoryEventForMRP); diff --git a/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java b/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java index 3340445291..c31b0ff84f 100644 --- a/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java +++ b/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java @@ -32,6 +32,7 @@ import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.manufacturing.bom.BOMTree; import org.ofbiz.manufacturing.jobshopmgt.ProductionRun; import org.ofbiz.manufacturing.techdata.TechDataServices; import org.ofbiz.service.DispatchContext; @@ -57,11 +58,10 @@ public class ProposedOrder { 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, Timestamp now) { + public ProposedOrder(GenericValue product, String facilityId, String manufacturingFacilityId, boolean isBuilt, Timestamp requiredByDate, double quantity) { this.product = product; this.productId = product.getString("productId"); this.facilityId = facilityId; @@ -227,7 +227,14 @@ public class ProposedOrder { LocalDispatcher dispatcher = ctx.getDispatcher(); GenericDelegator delegator = ctx.getDelegator(); Map parameters = UtilMisc.toMap("userLogin", userLogin); - + if (isBuilt) { + try { + BOMTree tree = new BOMTree(productId, "MANUF_COMPONENT", null, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin); + requirementStartDate = tree.getRoot().getStartDate(manufacturingFacilityId, requiredByDate); + } catch (Exception e) { + Debug.logError(e,"Error : computing the requirement start date. " + e.getMessage(), module); + } + } parameters.put("productId", productId); parameters.put("statusId", "REQ_PROPOSED"); parameters.put("facilityId", (isBuilt? manufacturingFacilityId: facilityId));