[OFBiz] SVN: r7053 - in trunk/applications/product: script/org/ofbiz/product/inventory servicedef src/org/ofbiz/product/inventory

jacopo@svn.ofbiz.org jacopo at svn.ofbiz.org
Thu Mar 23 00:15:04 CST 2006


Author: jacopo
Date: 2006-03-23 00:14:49 -0600 (Thu, 23 Mar 2006)
New Revision: 7053

Modified:
   trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml
   trunk/applications/product/servicedef/services_facility.xml
   trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java
Log:
Some small, but significant, changes to the way inventory item's transfers are done.
1) added a new OUT parameter, oldOwnerPartyId, to the updateInventoryItem service to allow to use ECA to manage the change of an inventory item's owner
2) if the inventory item is transferred to a facility owned by a different party from the inventory item's owner party, then the inventory item's owner is changed (using the updateInventoryItem service).

About #2: maybe automatically transferring ownership is not always a good idea, so probably it would be nice to add a field to the InventoryTransfer entity to specify if the ownership must be changed or not (transferOwnership=Y/N).


Modified: trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml
===================================================================
--- trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml	2006-03-23 03:43:31 UTC (rev 7052)
+++ trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml	2006-03-23 06:14:49 UTC (rev 7053)
@@ -160,6 +160,7 @@
         <make-value entity-name="InventoryItem" value-name="lookupPKMap"/>
         <set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
         <find-by-primary-key map-name="lookupPKMap" value-name="lookedUpValue"/>
+        <field-to-result field-name="lookedUpValue.ownerPartyId" result-name="oldOwnerPartyId"/>
         <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
         <store-value value-name="lookedUpValue"/>
     </simple-method>

Modified: trunk/applications/product/servicedef/services_facility.xml
===================================================================
--- trunk/applications/product/servicedef/services_facility.xml	2006-03-23 03:43:31 UTC (rev 7052)
+++ trunk/applications/product/servicedef/services_facility.xml	2006-03-23 06:14:49 UTC (rev 7053)
@@ -57,6 +57,7 @@
             <exclude field-name="availableToPromiseTotal"/>
             <exclude field-name="quantityOnHandTotal"/>
         </auto-attributes>
+        <attribute name="oldOwnerPartyId" mode="OUT" optional="false" type="String"/>
     </service>
     <service name="checkProductInventoryDiscontinuation" engine="simple"
                 location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="checkProductInventoryDiscontinuation" auth="false">

Modified: trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java
===================================================================
--- trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java	2006-03-23 03:43:31 UTC (rev 7052)
+++ trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java	2006-03-23 06:14:49 UTC (rev 7053)
@@ -201,12 +201,14 @@
         String inventoryTransferId = (String) context.get("inventoryTransferId");
         GenericValue inventoryTransfer = null;
         GenericValue inventoryItem = null;
+        GenericValue destinationFacility = null;
         GenericValue userLogin = (GenericValue) context.get("userLogin");        
         
         try {
             inventoryTransfer = delegator.findByPrimaryKey("InventoryTransfer", 
                     UtilMisc.toMap("inventoryTransferId", inventoryTransferId));
-            inventoryItem = inventoryTransfer.getRelatedOne("InventoryItem");  
+            inventoryItem = inventoryTransfer.getRelatedOne("InventoryItem");
+            destinationFacility = inventoryTransfer.getRelatedOne("ToFacility");
         } catch (GenericEntityException e) {
             return ServiceUtil.returnError("Inventory Item/Transfer lookup problem [" + e.getMessage() + "]");
         }
@@ -246,14 +248,33 @@
         }
 
         // set the fields on the item
-        inventoryItem.set("facilityId", inventoryTransfer.get("facilityIdTo"));
-        inventoryItem.set("containerId", inventoryTransfer.get("containerIdTo"));
-        inventoryItem.set("locationSeqId", inventoryTransfer.get("locationSeqIdTo"));
+        Map updateInventoryItemMap = UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId"),
+                                                    "facilityId", inventoryTransfer.get("facilityIdTo"),
+                                                    "containerId", inventoryTransfer.get("containerIdTo"),
+                                                    "locationSeqId", inventoryTransfer.get("locationSeqIdTo"),
+                                                    "userLogin", userLogin);
+        // if the destination facility's owner is different 
+        // from the inventory item's ownwer, 
+        // the inventory item is assigned to the new owner.
+        if (destinationFacility != null && destinationFacility.get("ownerPartyId") != null) {
+            String fromPartyId = inventoryItem.getString("ownerPartyId");
+            String toPartyId = destinationFacility.getString("ownerPartyId");
+            if (fromPartyId == null || !fromPartyId.equals(toPartyId)) {
+                updateInventoryItemMap.put("ownerPartyId", toPartyId);
+            }
+        }
+        try {
+            Map result = dctx.getDispatcher().runSync("updateInventoryItem", updateInventoryItemMap);
+            if (ServiceUtil.isError(result)) {
+                return ServiceUtil.returnError("Inventory item store problem", null, null, result);
+            }
+        } catch (GenericServiceException exc) {
+            return ServiceUtil.returnError("Inventory item store problem [" + exc.getMessage() + "]");
+        }
 
         // store the entities
         try {
             inventoryTransfer.store();
-            inventoryItem.store();
         } catch (GenericEntityException e) {
             return ServiceUtil.returnError("Inventory store problem [" + e.getMessage() + "]");
         }



More information about the Svn mailing list