Skip to content

Commit ae45e30

Browse files
nameet-jainJacquesLeRoux
authored andcommitted
Fixed production run cost calculation logic to consider returned items in material cost calculation. (#1182)
Fixed: production run cost calculation logic to consider returned items in material cost calculation. (OFBIZ-13243)
1 parent e456b65 commit ae45e30

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,29 @@ public static Map<String, Object> createProductionRunTaskCosts(DispatchContext c
13081308
materialsCost = materialsCost.add(unitCost.multiply(quantity)).setScale(DECIMALS, ROUNDING);
13091309
materialsCostByCurrency.put(currencyUomId, materialsCost);
13101310
}
1311+
List<GenericValue> returns = EntityQuery.use(delegator).from("WorkEffortAndInventoryProduced")
1312+
.where("workEffortId", productionRunTaskId).queryList();
1313+
for (GenericValue inventoryProduced : returns) {
1314+
// We check if it is a "return" (i.e. a product that was a component of the task)
1315+
GenericValue component = EntityQuery.use(delegator).from("WorkEffortGoodStandard")
1316+
.where("workEffortId", productionRunTaskId,
1317+
"productId", inventoryProduced.get("productId"),
1318+
"workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED")
1319+
.queryFirst();
1320+
if (component != null) {
1321+
BigDecimal quantity = inventoryProduced.getBigDecimal("quantityOnHandTotal");
1322+
BigDecimal unitCost = inventoryProduced.getBigDecimal("unitCost");
1323+
if (UtilValidate.isNotEmpty(unitCost) && UtilValidate.isNotEmpty(quantity)) {
1324+
String currencyUomId = inventoryProduced.getString("currencyUomId");
1325+
if (!materialsCostByCurrency.containsKey(currencyUomId)) {
1326+
materialsCostByCurrency.put(currencyUomId, BigDecimal.ZERO);
1327+
}
1328+
BigDecimal materialsCost = materialsCostByCurrency.get(currencyUomId);
1329+
materialsCost = materialsCost.subtract(unitCost.multiply(quantity)).setScale(DECIMALS, ROUNDING);
1330+
materialsCostByCurrency.put(currencyUomId, materialsCost);
1331+
}
1332+
}
1333+
}
13111334
for (String currencyUomId : materialsCostByCurrency.keySet()) {
13121335
BigDecimal materialsCost = materialsCostByCurrency.get(currencyUomId);
13131336
Map<String, Object> inMap = UtilMisc.<String, Object>toMap("userLogin", userLogin,

0 commit comments

Comments
 (0)