This is an automated email from the ASF dual-hosted git repository.

JacquesLeRoux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 8b49790c01 Fixed production run cost calculation logic to consider 
returned items in material cost calculation. (#1182)
8b49790c01 is described below

commit 8b49790c0100fadf2be1a4e05fa28fc44aec5c2e
Author: Nameet Jain <[email protected]>
AuthorDate: Mon May 11 14:25:43 2026 +0530

    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)
---
 .../jobshopmgt/ProductionRunServices.java          | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git 
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
 
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
index b3e52d5ea5..56c599cfb2 100644
--- 
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
+++ 
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
@@ -1308,6 +1308,29 @@ public class ProductionRunServices {
                 materialsCost = 
materialsCost.add(unitCost.multiply(quantity)).setScale(DECIMALS, ROUNDING);
                 materialsCostByCurrency.put(currencyUomId, materialsCost);
             }
+            List<GenericValue> returns = 
EntityQuery.use(delegator).from("WorkEffortAndInventoryProduced")
+                    .where("workEffortId", productionRunTaskId).queryList();
+            for (GenericValue inventoryProduced : returns) {
+                // We check if it is a "return" (i.e. a product that was a 
component of the task)
+                GenericValue component = 
EntityQuery.use(delegator).from("WorkEffortGoodStandard")
+                        .where("workEffortId", productionRunTaskId,
+                                "productId", 
inventoryProduced.get("productId"),
+                                "workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED")
+                        .queryFirst();
+                if (component != null) {
+                    BigDecimal quantity = 
inventoryProduced.getBigDecimal("quantityOnHandTotal");
+                    BigDecimal unitCost = 
inventoryProduced.getBigDecimal("unitCost");
+                    if (UtilValidate.isNotEmpty(unitCost) && 
UtilValidate.isNotEmpty(quantity)) {
+                        String currencyUomId = 
inventoryProduced.getString("currencyUomId");
+                        if 
(!materialsCostByCurrency.containsKey(currencyUomId)) {
+                            materialsCostByCurrency.put(currencyUomId, 
BigDecimal.ZERO);
+                        }
+                        BigDecimal materialsCost = 
materialsCostByCurrency.get(currencyUomId);
+                        materialsCost = 
materialsCost.subtract(unitCost.multiply(quantity)).setScale(DECIMALS, 
ROUNDING);
+                        materialsCostByCurrency.put(currencyUomId, 
materialsCost);
+                    }
+                }
+            }
             for (String currencyUomId : materialsCostByCurrency.keySet()) {
                 BigDecimal materialsCost = 
materialsCostByCurrency.get(currencyUomId);
                 Map<String, Object> inMap = UtilMisc.<String, 
Object>toMap("userLogin", userLogin,

Reply via email to