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

gsperi 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 691c74c  Fixed: multiple facility inventory reservation issue 
(OFBIZ-12264)
691c74c is described below

commit 691c74c66bed39112368e671caffd4402fa7bbd7
Author: Giulio Speri <giulio.sp...@mpstyle.it>
AuthorDate: Fri Apr 1 01:06:33 2022 +0200

    Fixed: multiple facility inventory reservation issue (OFBIZ-12264)
    
    The ProductStore is set up to reserve inventory from more than one
    facility, so the flag oneInventoryFacility is set to N.
    Flags requireInventory and reserveInventory are both to Y.
    Flag allocateInventory is N.
    
    A product can be anyway reserved in a ProductStoreFacility with its
    thru date set and past, so is disabled, and if is not present enough
    inventory quantity on other facilities.
    
    Added filtering by date on multiple facility code in
    reserveStoreInventoryMethod() and on isStoreInventoryAvailable().
    This is the first part of the problem resolution; the second part is
    accomplished by path to OFBIZ-12455 Jira.
    
    Thanks: Jacques Le Roux and Pierre SMith for Jira feedbacks, Nicola
    Mazzoni for helping in bug analaysis and Jacopo Cappellato for path
    review.
---
 .../groovyScripts/product/store/ProductStoreServices.groovy | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git 
a/applications/product/groovyScripts/product/store/ProductStoreServices.groovy 
b/applications/product/groovyScripts/product/store/ProductStoreServices.groovy
index 9f05ebb..e4c22d0 100644
--- 
a/applications/product/groovyScripts/product/store/ProductStoreServices.groovy
+++ 
b/applications/product/groovyScripts/product/store/ProductStoreServices.groovy
@@ -176,6 +176,7 @@ def reserveStoreInventory() {
             List productStoreFacilities = from("ProductStoreFacility")
                     .where(productStoreId: productStore.productStoreId)
                     .orderBy("sequenceNum")
+                    .filterByDate()
                     .cache()
                     .queryList()
             for (GenericValue productStoreFacility : productStoreFacilities) {
@@ -184,29 +185,28 @@ def reserveStoreInventory() {
                     // TODO: must entire quantity be available in one location?
                     // Right now the answer is yes, it only succeeds if one 
facility has sufficient inventory for the order.
                     Map callServiceMapIABF = [productId: parameters.productId, 
facilityId: productStoreFacility.facilityId]
-                    logInfo("ProductStoreService:In productStoreFacilities 
loop: [" + parameters.facilityId + "]")
                     Map serviceResultIABF = run service: 
"getInventoryAvailableByFacility", with: callServiceMapIABF
                     BigDecimal availableToPromiseTotal = 
serviceResultIABF.availableToPromiseTotal
-
                     if (availableToPromiseTotal >= parameters.quantity) {
                         storeFound = productStoreFacility
                     }
                 }
             }
             // didn't find anything? Take the first facility from list
+            GenericValue defaultStoreFound
             if (!storeFound) {
-                storeFound = productStoreFacilities.get(0)
+                defaultStoreFound = productStore.getRelatedOne("Facility", 
true)
             }
-            facilityId = storeFound.facilityId ?: ""
+            facilityId = storeFound ? storeFound.facilityId : 
defaultStoreFound.facilityId
             Map serviceResult = run service: 
"reserveProductInventoryByFacility", with: [*: parameters,
                                                                                
          facilityId: facilityId,
                                                                                
          requireInventory: requireInventory,
                                                                                
          reserveOrderEnumId: productStore.reserveOrderEnumId]
             quantityNotReserved = serviceResult.quantityNotReserved
-            logInfo("Inventory IS reserved in facility with id 
[${storeFound.facilityId}] for product id [${parameters.productId}]; desired 
quantity was ${parameters.quantity}")
+            logInfo("Inventory IS reserved in facility with id [${facilityId}] 
for product id [${parameters.productId}]; desired quantity was 
${parameters.quantity}")
         }
     } else {
-        List productStoreFacilities = 
from("ProductStoreFacility").where(productStoreId: productStore.productStoreId, 
facilityId: facilityId).cache().orderBy("sequenceNum").queryList()
+        List productStoreFacilities = 
from("ProductStoreFacility").where(productStoreId: productStore.productStoreId, 
facilityId: 
facilityId).cache().orderBy("sequenceNum").filterByDate().queryList()
         GenericValue facilityFound
         for (GenericValue productStoreFacility : productStoreFacilities) {
             // Search Product Store Facilities to insure the facility passed 
in is associated to the Product Store passed in
@@ -314,6 +314,7 @@ def isStoreInventoryAvailable() {
         List productStoreFacilities = from("ProductStoreFacility")
                 .where(productStoreId: productStore.productStoreId)
                 .orderBy("sequenceNum")
+                .filterByDate()
                 .cache()
                 .queryList()
         available = "N"

Reply via email to