Dev - inventory transfers and inventory ownership

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Dev - inventory transfers and inventory ownership

Jacopo Cappellato
Hi,

in rev 7053 I've committed some small (but remarkable) changes to the
way inventory items are transferred (see the attached log).

If you see any problems in it, please let me know and I'll fix them
immediately.

Also, what do you think about my last comment in the commit log:

"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)."

?

Thanks,

Jacopo

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() + "]");
         }

 
_______________________________________________
Svn mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/svn


 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - inventory transfers and inventory ownership

davidnwelton
> 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).

The mental model I have of stuff going from one owner to another
involves some paperwork...  How would this keep track of that for the
'bean counters'?

--
David N. Welton
 - http://www.dedasys.com/davidw/

Linux, Open Source Consulting
 - http://www.dedasys.com/
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - inventory transfers and inventory ownership

Jacopo Cappellato
The plan is to set up the posting of general ledger transactions to the
accounts of the two (sender/receiver) parties.

Jacopo

David Welton wrote:

>> 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).
>
> The mental model I have of stuff going from one owner to another
> involves some paperwork...  How would this keep track of that for the
> 'bean counters'?
>
> --
> David N. Welton
>  - http://www.dedasys.com/davidw/
>
> Linux, Open Source Consulting
>  - http://www.dedasys.com/
>  
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
>

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - inventory transfers and inventory ownership

BJ Freeman
Still reading and comprehending the change.
However for bean counters, there need to be a "paper trail" back to the
original transaction, from the Journal. That is why the IRS in the USA
requires keeping Receipts and invoices for 5 years.
if I understand the change, that record is changed, instead of creating
a transaction type recorder for Audit trail. if that is the case, then
this would not be a good idea.


Jacopo Cappellato sent the following on 3/23/06 2:28 AM:

> The plan is to set up the posting of general ledger transactions to the
> accounts of the two (sender/receiver) parties.
>
> Jacopo
>
> David Welton wrote:
>
>>>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).
>>
>>The mental model I have of stuff going from one owner to another
>>involves some paperwork...  How would this keep track of that for the
>>'bean counters'?
>>
>>--
>>David N. Welton
>> - http://www.dedasys.com/davidw/
>>
>>Linux, Open Source Consulting
>> - http://www.dedasys.com/
>>
>>_______________________________________________
>>Dev mailing list
>>[hidden email]
>>http://lists.ofbiz.org/mailman/listinfo/dev
>>
>
>
>  
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
>
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - inventory transfers and inventory ownership

Adrian Crum
I agree. There needs to be some kind of document. In effect, the inventory is
"sold" by the source, and "bought" by the destination.


BJ Freeman wrote:

> Still reading and comprehending the change.
> However for bean counters, there need to be a "paper trail" back to the
> original transaction, from the Journal. That is why the IRS in the USA
> requires keeping Receipts and invoices for 5 years.
> if I understand the change, that record is changed, instead of creating
> a transaction type recorder for Audit trail. if that is the case, then
> this would not be a good idea.
>
>
> Jacopo Cappellato sent the following on 3/23/06 2:28 AM:
>
>>The plan is to set up the posting of general ledger transactions to the
>>accounts of the two (sender/receiver) parties.
>>
>>Jacopo
>>
>>David Welton wrote:
>>
>>
>>>>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).
>>>
>>>The mental model I have of stuff going from one owner to another
>>>involves some paperwork...  How would this keep track of that for the
>>>'bean counters'?
>>>
>>>--
>>>David N. Welton
>>>- http://www.dedasys.com/davidw/
>>>
>>>Linux, Open Source Consulting
>>>- http://www.dedasys.com/
>>>
>>>_______________________________________________
>>>Dev mailing list
>>>[hidden email]
>>>http://lists.ofbiz.org/mailman/listinfo/dev
>>>
>>
>>
>>
>>_______________________________________________
>>Dev mailing list
>>[hidden email]
>>http://lists.ofbiz.org/mailman/listinfo/dev
>>
>
>  
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
>
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - inventory transfers and inventory ownership

Jacopo Cappellato
Ok,

each transfer is recorded with an entry in the InventoryTransfer entity
(from/to facility, date, status etc...), maybe we should add a new field
to store the originalOwnerId of the inventory item.

Thanks for your comments,

Jacopo

Adrian Crum wrote:

> I agree. There needs to be some kind of document. In effect, the inventory is
> "sold" by the source, and "bought" by the destination.
>
>
> BJ Freeman wrote:
>> Still reading and comprehending the change.
>> However for bean counters, there need to be a "paper trail" back to the
>> original transaction, from the Journal. That is why the IRS in the USA
>> requires keeping Receipts and invoices for 5 years.
>> if I understand the change, that record is changed, instead of creating
>> a transaction type recorder for Audit trail. if that is the case, then
>> this would not be a good idea.
>>
>>
>> Jacopo Cappellato sent the following on 3/23/06 2:28 AM:
>>
>>> The plan is to set up the posting of general ledger transactions to the
>>> accounts of the two (sender/receiver) parties.
>>>
>>> Jacopo
>>>
>>> David Welton wrote:
>>>
>>>
>>>>> 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).
>>>> The mental model I have of stuff going from one owner to another
>>>> involves some paperwork...  How would this keep track of that for the
>>>> 'bean counters'?
>>>>
>>>> --
>>>> David N. Welton
>>>> - http://www.dedasys.com/davidw/
>>>>
>>>> Linux, Open Source Consulting
>>>> - http://www.dedasys.com/
>>>>
>>>> _______________________________________________
>>>> Dev mailing list
>>>> [hidden email]
>>>> http://lists.ofbiz.org/mailman/listinfo/dev
>>>>
>>>
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [hidden email]
>>> http://lists.ofbiz.org/mailman/listinfo/dev
>>>
>>  
>> _______________________________________________
>> Dev mailing list
>> [hidden email]
>> http://lists.ofbiz.org/mailman/listinfo/dev
>>
>  
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
>

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev