Author: jacopoc
Date: Tue Apr 20 15:55:27 2010 New Revision: 935969 URL: http://svn.apache.org/viewvc?rev=935969&view=rev Log: Patch from Bob Morley, OFBIZ-3724: when a ProductionRun was created the WorkEffortCostCalc relations were not cloned from the routing tasks. This resulted in not being able to change the CostCalc as part of a ProductionRun unless you were to change the routing task template for all production runs. – Modified: ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/test/ProductionRunTests.xml ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java ofbiz/trunk/applications/manufacturing/testdef/data/ManufacturingTestsData.xml Modified: ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/test/ProductionRunTests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/test/ProductionRunTests.xml?rev=935969&r1=935968&r2=935969&view=diff ============================================================================== --- ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/test/ProductionRunTests.xml (original) +++ ofbiz/trunk/applications/manufacturing/script/org/ofbiz/manufacturing/test/ProductionRunTests.xml Tue Apr 20 15:55:27 2010 @@ -93,6 +93,19 @@ under the License. <if-compare field="productionRunTask.estimatedMilliSeconds" operator="equals" value="300000.00" type="BigDecimal"/> </assert> + <!-- Verify that the cost calcs were copied from the routing task to the production run task --> + <entity-and list="costCalcs" entity-name="WorkEffortCostCalc"> + <field-map field-name="workEffortId" from-field="productionRunTask.workEffortId" /> + </entity-and> + <first-from-list entry="costCalc" list="costCalcs"/> + + <assert> + <not><if-empty field="costCalc" /></not> + <if-compare field="costCalc.costComponentTypeId" operator="equals" value="OTHER_COST" /> + <if-compare field="costCalc.costComponentCalcId" operator="equals" value="TASK_COST_CALC" /> + </assert> + + <!-- Verify that the BOM was properly copied to the production run task --> <entity-and list="productionRunMaterials" entity-name="WorkEffortGoodStandard"> <field-map field-name="workEffortId" from-field="productionRunTask.workEffortId"/> <field-map field-name="productId" value="MAT_A_COST"/> Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=935969&r1=935968&r2=935969&view=diff ============================================================================== --- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original) +++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Tue Apr 20 15:55:27 2010 @@ -345,6 +345,7 @@ public class ProductionRunServices { } String productionRunTaskId = (String) resultService.get("workEffortId"); if (Debug.infoOn()) Debug.logInfo("ProductionRunTaskId created: " + productionRunTaskId, module); + // The newly created production run task is associated to the routing task // to keep track of the template used to generate it. serviceContext.clear(); @@ -357,34 +358,11 @@ public class ProductionRunServices { } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortAssoc service", module); } - // copy date valid WorkEffortPartyAssignments from the routing task to the run task - List workEffortPartyAssignments = null; - try { - workEffortPartyAssignments = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment", - UtilMisc.toMap("workEffortId", routingTaskAssoc.getString("workEffortIdTo")))); - } catch (GenericEntityException e) { - Debug.logError(e.getMessage(), module); - } - if (workEffortPartyAssignments != null) { - Iterator i = workEffortPartyAssignments.iterator(); - while (i.hasNext()) { - GenericValue workEffortPartyAssignment = (GenericValue) i.next(); - Map partyToWorkEffort = UtilMisc.toMap( - "workEffortId", productionRunTaskId, - "partyId", workEffortPartyAssignment.getString("partyId"), - "roleTypeId", workEffortPartyAssignment.getString("roleTypeId"), - "fromDate", workEffortPartyAssignment.getTimestamp("fromDate"), - "statusId", workEffortPartyAssignment.getString("statusId"), - "userLogin", userLogin - ); - try { - resultService = dispatcher.runSync("assignPartyToWorkEffort", partyToWorkEffort); - } catch (GenericServiceException e) { - Debug.logError(e, "Problem calling the assignPartyToWorkEffort service", module); - } - if (Debug.infoOn()) Debug.logInfo("ProductionRunPartyassigment for party: " + workEffortPartyAssignment.get("partyId") + " created", module); - } - } + + // clone associated objects from the routing task to the run task + String routingTaskId = routingTaskAssoc.getString("workEffortIdTo"); + cloneWorkEffortPartyAssignments(ctx, userLogin, routingTaskId, productionRunTaskId); + cloneWorkEffortCostCalcs(ctx, userLogin, routingTaskId, productionRunTaskId); // Now we iterate thru the components returned by the getManufacturingComponents service // TODO: if in the BOM a routingWorkEffortId is specified, but the task is not in the routing @@ -439,6 +417,74 @@ public class ProductionRunServices { result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunCreated",UtilMisc.toMap("productionRunId", productionRunId), locale)); return result; } + + /** + * Make a copy of the party assignments that were defined on the template routing task to the new production run task. + */ + private static void cloneWorkEffortPartyAssignments(DispatchContext dctx, GenericValue userLogin, String routingTaskId, String productionRunTaskId) { + List workEffortPartyAssignments = null; + try { + workEffortPartyAssignments = EntityUtil.filterByDate( + dctx.getDelegator().findByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("workEffortId", routingTaskId))); + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + } + + if (workEffortPartyAssignments != null) { + Iterator i = workEffortPartyAssignments.iterator(); + while (i.hasNext()) { + GenericValue workEffortPartyAssignment = (GenericValue) i.next(); + Map partyToWorkEffort = UtilMisc.toMap( + "workEffortId", productionRunTaskId, + "partyId", workEffortPartyAssignment.getString("partyId"), + "roleTypeId", workEffortPartyAssignment.getString("roleTypeId"), + "fromDate", workEffortPartyAssignment.getTimestamp("fromDate"), + "statusId", workEffortPartyAssignment.getString("statusId"), + "userLogin", userLogin + ); + try { + dctx.getDispatcher().runSync("assignPartyToWorkEffort", partyToWorkEffort); + } catch (GenericServiceException e) { + Debug.logError(e, "Problem calling the assignPartyToWorkEffort service", module); + } + if (Debug.infoOn()) Debug.logInfo("ProductionRunPartyassigment for party: " + workEffortPartyAssignment.get("partyId") + " created", module); + } + } + } + + /** + * Make a copy of the cost calc entities that were defined on the template routing task to the new production run task. + */ + private static void cloneWorkEffortCostCalcs(DispatchContext dctx, GenericValue userLogin, String routingTaskId, String productionRunTaskId) { + List<GenericValue> workEffortCostCalcs = null; + try { + workEffortCostCalcs = EntityUtil.filterByDate( + dctx.getDelegator().findByAnd("WorkEffortCostCalc", UtilMisc.toMap("workEffortId", routingTaskId))); + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + } + + if (workEffortCostCalcs != null) { + for (GenericValue costCalc : workEffortCostCalcs) { + Map<String, Object> createCostCalc = UtilMisc.toMap( + "workEffortId", productionRunTaskId, + "costComponentTypeId", costCalc.getString("costComponentTypeId"), + "costComponentCalcId", costCalc.getString("costComponentCalcId"), + "fromDate", costCalc.get("fromDate"), + "thruDate", costCalc.get("thruDate"), + "userLogin", userLogin + ); + + try { + dctx.getDispatcher().runSync("createWorkEffortCostCalc", createCostCalc); + } catch (GenericServiceException gse) { + Debug.logError(gse, "Problem calling the createWorkEffortCostCalc service", module); + } + if (Debug.infoOn()) Debug.logInfo("ProductionRun CostCalc for cost calc: " + costCalc.getString("costComponentCalcId") + " created", module); + } + } + } + /** * Update a Production Run. * <li> update field and after recalculate the entire ProductionRun data (routingTask and productComponent) @@ -1034,15 +1080,11 @@ public class ProductionRunServices { if (UtilValidate.isNotEmpty(routingTaskAssoc)) { routingTask = routingTaskAssoc.getRelatedOne("FromWorkEffort"); } - List workEffortCostCalcs = null; - if (UtilValidate.isEmpty(routingTask)) { - // there is no template, try to get the cost entries for the actual production run task, if any - workEffortCostCalcs = delegator.findByAnd("WorkEffortCostCalc", UtilMisc.toMap("workEffortId", productionRunTaskId)); - } else { - workEffortCostCalcs = delegator.findByAnd("WorkEffortCostCalc", UtilMisc.toMap("workEffortId", routingTask.getString("workEffortId"))); - } + // Get all the valid CostComponentCalc entries + List workEffortCostCalcs = workEffortCostCalcs = delegator.findByAnd("WorkEffortCostCalc", UtilMisc.toMap("workEffortId", productionRunTaskId)); workEffortCostCalcs = EntityUtil.filterByDate(workEffortCostCalcs); + Iterator workEffortCostCalcsIt = workEffortCostCalcs.iterator(); while (workEffortCostCalcsIt.hasNext()) { GenericValue workEffortCostCalc = (GenericValue)workEffortCostCalcsIt.next(); @@ -1082,6 +1124,7 @@ public class ProductionRunServices { dispatcher.runSync(customMethod.getString("customMethodName"), inMap); } } + // Now get the cost information associated to the fixed asset and compute the costs GenericValue fixedAsset = workEffort.getRelatedOne("FixedAsset"); if (UtilValidate.isEmpty(fixedAsset) && UtilValidate.isNotEmpty(routingTask)) { Modified: ofbiz/trunk/applications/manufacturing/testdef/data/ManufacturingTestsData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/testdef/data/ManufacturingTestsData.xml?rev=935969&r1=935968&r2=935969&view=diff ============================================================================== --- ofbiz/trunk/applications/manufacturing/testdef/data/ManufacturingTestsData.xml (original) +++ ofbiz/trunk/applications/manufacturing/testdef/data/ManufacturingTestsData.xml Tue Apr 20 15:55:27 2010 @@ -29,6 +29,7 @@ under the License. <SecurityGroupPermission groupId="MANUFADMIN" permissionId="ACCTG_ATX_CREATE"/> <SecurityGroupPermission groupId="MANUFADMIN" permissionId="ACCTG_ATX_UPDATE"/> <SecurityGroupPermission groupId="MANUFADMIN" permissionId="ACCTG_PREF_VIEW"/> + <SecurityGroupPermission groupId="MANUFADMIN" permissionId="ACCOUNTING_CREATE"/> <SecurityGroupPermission groupId="MANUFADMIN" permissionId="ACCOUNTING_UPDATE"/> <SecurityGroupPermission groupId="MANUFADMIN" permissionId="FACILITY_CREATE"/> <Party partyId="TestManufAdmin" partyTypeId="PERSON"/> @@ -39,6 +40,7 @@ under the License. <SecurityGroupPermission groupId="SUPPLYADMIN" permissionId="MANUFACTURING_VIEW"/> <SecurityGroupPermission groupId="SUPPLYADMIN" permissionId="WORKEFFORTMGR_CREATE"/> <SecurityGroupPermission groupId="SUPPLYADMIN" permissionId="WORKEFFORTMGR_UPDATE"/> + <SecurityGroupPermission groupId="SUPPLYADMIN" permissionId="ACCOUNTING_CREATE"/> <Party partyId="TestSupplyAdmin" partyTypeId="PERSON"/> <Person partyId="TestSupplyAdmin" firstName="Supply" lastName="Admin"/> <UserLogin partyId="TestSupplyAdmin" userLoginId="TestSupplyAdmin"/> |
Free forum by Nabble | Edit this page |