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

diveshdut 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 dd2d941b33 OFBIZ-13463: Fixed false late flag on REQUIRED_MRP proposed 
supply in MRP engine (#1485)
dd2d941b33 is described below

commit dd2d941b338098842dc0498c4fcc4a881a1c02ad
Author: Divesh Dutta <[email protected]>
AuthorDate: Fri Jul 24 20:28:40 2026 +0530

    OFBIZ-13463: Fixed false late flag on REQUIRED_MRP proposed supply in MRP 
engine (#1485)
    
    # Jira Ticket:
    
    https://issues.apache.org/jira/browse/OFBIZ-13463
    
    ## Summary
    
    Fixed a false `isLate = Y` condition for proposed MRP supply generated
    from stock-policy replenishment markers.
    
    MRP creates an internal replenishment trigger when current QOH is below
    `ProductFacility.minimumStock`, then immediately creates proposed
    supply. The proposed requirement start date can be a few milliseconds
    earlier than the MRP run timestamp, which caused the proposed supply
    event to be incorrectly marked late.
    
    This change prevents that false late classification for `REQUIRED_MRP`-
    driven proposed supply while preserving the existing late behavior for
    real late demand/supply situations.
    
    ## Changes
    
    - added a small helper in `MrpServices` to evaluate whether a proposed
    order should be late
    - excluded `REQUIRED_MRP` source events from proposed-order late
    classification
    - kept the original timestamp-based late behavior for non-`REQUIRED_MRP`
    source events
    - added dedicated MRP regression tests
    - added a dedicated manufacturing MRP test suite registration
---
 applications/manufacturing/ofbiz-component.xml     |  2 +-
 .../manufacturing/test/MrpServicesTests.groovy     | 84 ++++++++++++++++++++++
 .../ofbiz/manufacturing/mrp/MrpServices.java       | 12 +++-
 applications/manufacturing/testdef/MrpTests.xml    | 26 +++++++
 4 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/applications/manufacturing/ofbiz-component.xml 
b/applications/manufacturing/ofbiz-component.xml
index 714ee21caf..071f38c02a 100644
--- a/applications/manufacturing/ofbiz-component.xml
+++ b/applications/manufacturing/ofbiz-component.xml
@@ -44,6 +44,7 @@ under the License.
 
     <test-suite loader="main" location="testdef/productionruntests.xml"/>
     <test-suite loader="main" location="testdef/InventoryIssuanceTests.xml"/>
+    <test-suite loader="main" location="testdef/MrpTests.xml"/>
 
     <!-- web applications; will be mounted when using the embedded container 
-->
     <webapp name="manufacturing"
@@ -56,4 +57,3 @@ under the License.
         mount-point="/manufacturing"/>
 
 </ofbiz-component>
-
diff --git 
a/applications/manufacturing/src/main/groovy/org/apache/ofbiz/manufacturing/test/MrpServicesTests.groovy
 
b/applications/manufacturing/src/main/groovy/org/apache/ofbiz/manufacturing/test/MrpServicesTests.groovy
new file mode 100644
index 0000000000..271b8b3b15
--- /dev/null
+++ 
b/applications/manufacturing/src/main/groovy/org/apache/ofbiz/manufacturing/test/MrpServicesTests.groovy
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ofbiz.manufacturing.test
+
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.manufacturing.mrp.MrpServices
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+
+import java.sql.Timestamp
+
+class MrpServicesTests extends OFBizTestCase {
+
+    MrpServicesTests(String name) {
+        super(name)
+    }
+
+    void testRequiredMrpProposedOrderIsNotLateForSlightlyEarlierTimestamp() {
+        Timestamp runStartedAt = Timestamp.valueOf('2026-07-22 11:30:00.100')
+        Timestamp requirementStartDate = Timestamp.valueOf('2026-07-22 
11:30:00.095')
+
+        assert !MrpServices.isProposedOrderLate(requirementStartDate, 
runStartedAt, mrpEvent(mrpEventTypeId: 'REQUIRED_MRP'))
+    }
+
+    void testNonRequiredMrpProposedOrderRemainsLateWhenStartDatePrecedesRun() {
+        Timestamp runStartedAt = Timestamp.valueOf('2026-07-22 11:30:00.100')
+        Timestamp requirementStartDate = Timestamp.valueOf('2026-07-22 
11:29:59.000')
+
+        assert MrpServices.isProposedOrderLate(requirementStartDate, 
runStartedAt, mrpEvent(mrpEventTypeId: 'SALES_ORDER_SHIP'))
+    }
+
+    private static GenericValue mrpEvent(Map fields) {
+        new StubGenericValue(fields)
+    }
+
+    private static class StubGenericValue extends GenericValue {
+
+        private final Map fields
+
+        StubGenericValue(Map fields) {
+            this.fields = fields
+        }
+
+        @Override
+        Object get(String name) {
+            fields[name]
+        }
+
+        @Override
+        Object get(Object key) {
+            fields[key]
+        }
+
+        @Override
+        String getString(String name) {
+            Object value = fields[name]
+            value == null ? null : value.toString()
+        }
+
+        Object getProperty(String name) {
+            if (fields.containsKey(name)) {
+                return fields[name]
+            }
+            super.getProperty(name)
+        }
+
+    }
+
+}
diff --git 
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java
 
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java
index 2b11362c14..6c0549bde1 100644
--- 
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java
+++ 
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java
@@ -622,6 +622,16 @@ public class MrpServices {
         }
     }
 
+    /**
+     * Returns whether a proposed supply order should be classified as late 
for the current MRP run.
+     */
+    public static boolean isProposedOrderLate(Timestamp requirementStartDate, 
Timestamp runStartedAt, GenericValue sourceEvent) {
+        if (sourceEvent != null && 
"REQUIRED_MRP".equals(sourceEvent.getString("mrpEventTypeId"))) {
+            return false;
+        }
+        return requirementStartDate.compareTo(runStartedAt) < 0;
+    }
+
     /**
      * Process the bill of material (bom) of the product  to insert components 
in the MrpEvent table.
      * Before inserting in the entity, test if there is the record already 
existing to add quantity rather to create a new one.
@@ -945,7 +955,7 @@ public class MrpServices {
                         String eventFacilityId = isBuilt ? 
manufacturingFacilityId : facilityId;
                         try {
                             
InventoryEventPlannedServices.createOrUpdateMrpEvent(eventMap, 
proposedOrder.getQuantity(), eventFacilityId,
-                                    eventName, 
(proposedOrder.getRequirementStartDate().compareTo(now) < 0), delegator);
+                                    eventName, 
isProposedOrderLate(proposedOrder.getRequirementStartDate(), now, 
inventoryEventForMRP), delegator);
                         } catch (GenericEntityException e) {
                             return 
ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, 
"ManufacturingMrpCreateOrUpdateEvent",
                                     UtilMisc.toMap("parameters", parameters), 
locale));
diff --git a/applications/manufacturing/testdef/MrpTests.xml 
b/applications/manufacturing/testdef/MrpTests.xml
new file mode 100644
index 0000000000..0e255d074f
--- /dev/null
+++ b/applications/manufacturing/testdef/MrpTests.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<test-suite suite-name="mrptests"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        
xsi:noNamespaceSchemaLocation="https://ofbiz.apache.org/dtds/test-suite.xsd";>
+    <test-case case-name="mrp-services-tests">
+        <junit-test-suite 
class-name="org.apache.ofbiz.manufacturing.test.MrpServicesTests"/>
+    </test-case>
+</test-suite>

Reply via email to