svn commit: r655452 - in /ofbiz/trunk/applications/order: data/OrderTypeData.xml entitydef/entitygroup.xml entitydef/entitymodel.xml script/org/ofbiz/order/order/OrderServices.xml servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

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

svn commit: r655452 - in /ofbiz/trunk/applications/order: data/OrderTypeData.xml entitydef/entitygroup.xml entitydef/entitymodel.xml script/org/ofbiz/order/order/OrderServices.xml servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

bibryam
Author: bibryam
Date: Mon May 12 02:36:04 2008
New Revision: 655452

URL: http://svn.apache.org/viewvc?rev=655452&view=rev
Log:
"Store Order Item changes" from Jira Issue OFBIZ-1773

Modified:
    ofbiz/trunk/applications/order/data/OrderTypeData.xml
    ofbiz/trunk/applications/order/entitydef/entitygroup.xml
    ofbiz/trunk/applications/order/entitydef/entitymodel.xml
    ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/order/data/OrderTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/data/OrderTypeData.xml?rev=655452&r1=655451&r2=655452&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/data/OrderTypeData.xml (original)
+++ ofbiz/trunk/applications/order/data/OrderTypeData.xml Mon May 12 02:36:04 2008
@@ -79,6 +79,12 @@
     <Enumeration description="Affiliate Channel" enumCode="AFFIL_CHANNEL" enumId="AFFIL_SALES_CHANNEL" sequenceId="07" enumTypeId="ORDER_SALES_CHANNEL"/>
     <Enumeration description="eBay Channel" enumCode="EBAY_CHANNEL" enumId="EBAY_SALES_CHANNEL" sequenceId="08" enumTypeId="ORDER_SALES_CHANNEL"/>
     <Enumeration description="Unknown Channel" enumCode="UNKOWN_CAHNNEL" enumId="UNKNWN_SALES_CHANNEL" sequenceId="99" enumTypeId="ORDER_SALES_CHANNEL"/>
+    <EnumerationType description="Order Item Change Type" enumTypeId="ODR_ITM_CHANGE_TYPE" hasTable="N" parentTypeId=""/>
+    <Enumeration description="Order Item Update" enumCode="ITM_UPDATE" enumId="ODR_ITM_UPDATE" sequenceId="01" enumTypeId="ODR_ITM_CHANGE_TYPE"/>
+    <Enumeration description="Order Item Cancel" enumCode="ITM_CANCEL" enumId="ODR_ITM_CANCEL" sequenceId="02" enumTypeId="ODR_ITM_CHANGE_TYPE"/>
+    <EnumerationType description="Order Item Change Reason" enumTypeId="ODR_ITM_CH_REASON" hasTable="N" parentTypeId=""/>
+    <Enumeration description="Mis-Ordered Item" enumCode="MISORDER" enumId="OICR_MISORDER_ITEM" sequenceId="01" enumTypeId="ODR_ITM_CH_REASON"/>
+    <Enumeration description="Customer Changed Mind" enumCode="CHANGE_MIND" enumId="OICR_CUST_CHMIND" sequenceId="02" enumTypeId="ODR_ITM_CH_REASON"/>
 
     <QuoteType description="Other" hasTable="N" parentTypeId="" quoteTypeId="OTHER_QUOTE"/>
     <QuoteType description="Product" hasTable="N" parentTypeId="" quoteTypeId="PRODUCT_QUOTE"/>

Modified: ofbiz/trunk/applications/order/entitydef/entitygroup.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitygroup.xml?rev=655452&r1=655451&r2=655452&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/entitydef/entitygroup.xml (original)
+++ ofbiz/trunk/applications/order/entitydef/entitygroup.xml Mon May 12 02:36:04 2008
@@ -64,6 +64,7 @@
     <entity-group group="org.ofbiz" entity="OrderItemAssocType" />
     <entity-group group="org.ofbiz" entity="OrderItemAttribute" />
     <entity-group group="org.ofbiz" entity="OrderItemBilling" />
+    <entity-group group="org.ofbiz" entity="OrderItemChange" />
     <entity-group group="org.ofbiz" entity="OrderItemContactMech" />
     <entity-group group="org.ofbiz" entity="OrderItemGroup" />
     <entity-group group="org.ofbiz" entity="OrderItemShipGrpInvRes" />

Modified: ofbiz/trunk/applications/order/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitymodel.xml?rev=655452&r1=655451&r2=655452&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/order/entitydef/entitymodel.xml Mon May 12 02:36:04 2008
@@ -652,6 +652,40 @@
         <key-map field-name="itemIssuanceId"/>
       </relation>
     </entity>
+    <entity entity-name="OrderItemChange"
+            package-name="org.ofbiz.order.order"
+            never-cache="true"
+            title="Order Item Change Entity">
+      <field name="orderItemChangeId" type="id-ne"></field>
+      <field name="orderId" type="id-ne"></field>
+      <field name="orderItemSeqId" type="id-ne"></field>
+      <field name="changeTypeEnumId" type="id"></field>      
+      <field name="changeDatetime" type="date-time"></field>
+      <field name="changeUserLogin" type="id-vlong"></field>
+      <field name="quantity" type="floating-point"></field>
+      <field name="cancelQuantity" type="floating-point"></field>
+      <field name="unitPrice" type="currency-amount"></field>
+      <field name="itemDescription" type="description"></field>
+      <field name="reasonEnumId" type="id"></field>
+      <field name="changeComments" type="comment"></field>      
+      <prim-key field="orderItemChangeId"/>    
+      <relation type="one-nofk" rel-entity-name="OrderHeader">
+        <key-map field-name="orderId"/>
+      </relation>
+      <relation type="one" fk-name="ORDER_ITCH_OITM" rel-entity-name="OrderItem">
+        <key-map field-name="orderId"/>
+        <key-map field-name="orderItemSeqId"/>
+      </relation>
+      <relation type="one" fk-name="ORDER_ITCH_TYPE" rel-entity-name="Enumeration">
+        <key-map field-name="changeTypeEnumId" rel-field-name="enumId"/>
+      </relation>            
+      <relation type="one" fk-name="ORDER_ITCH_REAS" title="Reason" rel-entity-name="Enumeration">
+          <key-map field-name="reasonEnumId" rel-field-name="enumId"/>
+      </relation>
+      <relation type="one" fk-name="ORDER_ITCH_USER" rel-entity-name="UserLogin">
+        <key-map field-name="changeUserLogin" rel-field-name="userLoginId"/>
+      </relation>      
+    </entity>
     <entity entity-name="OrderItemContactMech"
             package-name="org.ofbiz.order.order"
             never-cache="true"

Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml?rev=655452&r1=655451&r2=655452&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml (original)
+++ ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml Mon May 12 02:36:04 2008
@@ -882,4 +882,19 @@
         </if-empty>
         <field-to-result field-name="isBackOrder" result-name="isBackOrder"/>
     </simple-method>
+    
+    <simple-method method-name="createOrderItemChange" short-description="Creates a new Order Item Change record">
+        <make-value value-name="newEntity" entity-name="OrderItemChange"/>
+        <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+        <if-empty field-name="parameters.changeDatetime">
+            <now-timestamp-to-env env-name="nowTimestamp"/>
+            <set field="newEntity.changeDatetime" from-field="nowTimestamp"/>
+        </if-empty>
+        <if-empty field-name="parameters.changeUserLogin">
+            <set field="newEntity.changeUserLogin" from-field="userLogin.userLoginId"/>
+        </if-empty>
+        <sequenced-id-to-env sequence-name="OrderItemChange" env-name="newEntity.orderItemChangeId"/>
+        <create-value value-name="newEntity"/>
+        <field-to-result field-name="newEntity.orderItemChangeId" result-name="orderItemChangeId"/>                    
+    </simple-method>    
 </simple-methods>

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=655452&r1=655451&r2=655452&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Mon May 12 02:36:04 2008
@@ -823,4 +823,14 @@
         <attribute name="orderPaymentPreferenceId" type="String" mode="IN" optional="false"/>
         <attribute name="changeReason" type="String" mode="IN" optional="true"/>
     </service>    
+    
+    <service name="createOrderItemChange" engine="simple" auth="true" default-entity-name="OrderItemChange"
+            location="org/ofbiz/order/order/OrderServices.xml" invoke="createOrderItemChange">
+        <description>Creates a new OrderItemChange record</description>
+        <auto-attributes mode="OUT" include="pk" optional="false"/>
+        <auto-attributes mode="IN" include="nonpk" optional="true"/>
+        <override name="orderId" optional="false"/>
+        <override name="orderItemSeqId" optional="false"/>
+        <override name="changeTypeEnumId" optional="false"/>          
+    </service>    
 </services>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=655452&r1=655451&r2=655452&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon May 12 02:36:04 2008
@@ -1858,6 +1858,9 @@
                 }
 
                 if (availableQuantity.doubleValue() >= thisCancelQty.doubleValue()) {
+                    if (availableQuantity.doubleValue() == 0) {
+                        return ServiceUtil.returnSuccess();  //item already canceled
+                    }
                     orderItem.set("cancelQuantity", Double.valueOf(itemCancelQuantity.doubleValue() + thisCancelQty.doubleValue()));
                     orderItemShipGroupAssoc.set("cancelQuantity", Double.valueOf(aisgaCancelQuantity.doubleValue() + thisCancelQty.doubleValue()));
 
@@ -1868,6 +1871,24 @@
                         Debug.logError(e, module);
                         return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToSetCancelQuantity", UtilMisc.toMap("itemMsgInfo",itemMsgInfo), locale));
                     }
+                    
+                    //  create order item change record
+                    Map serviceCtx = FastMap.newInstance();
+                    serviceCtx.put("orderId", orderItem.getString("orderId"));
+                    serviceCtx.put("orderItemSeqId", orderItem.getString("orderItemSeqId"));
+                    serviceCtx.put("cancelQuantity", thisCancelQty);
+                    serviceCtx.put("changeTypeEnumId", "ODR_ITM_CANCEL");
+                    serviceCtx.put("userLogin", userLogin);
+                    Map resp = null;
+                    try {
+                        resp = dispatcher.runSync("createOrderItemChange", serviceCtx);
+                    } catch (GenericServiceException e) {
+                        Debug.logError(e, module);
+                        return ServiceUtil.returnError(e.getMessage());
+                    }
+                    if (ServiceUtil.isError(resp)) {
+                        return ServiceUtil.returnError((String)resp.get(ModelService.ERROR_MESSAGE));
+                    }
 
                     if (thisCancelQty.doubleValue() >= itemQuantity.doubleValue()) {
                         // all items are cancelled -- mark the item as cancelled
@@ -3534,6 +3555,7 @@
         }
 
         // get the new orderItems, adjustments, shipping info and payments from the cart
+        List<GenericValue> modifiedItems = FastList.newInstance();        
         List toStore = new LinkedList();
         toStore.addAll(cart.makeOrderItems());
         toStore.addAll(cart.makeAllAdjustments());
@@ -3571,7 +3593,47 @@
                 if (valueObj.get("statusId") == null) {
                     valueObj.set("statusId", "PAYMENT_NOT_RECEIVED");
                 }
-            }
+            } else if ("OrderItem".equals(valueObj.getEntityName())) {
+                GenericValue oldOrderItem = null;
+                try {
+                    oldOrderItem = delegator.findByPrimaryKey("OrderItem", UtilMisc.toMap("orderId", valueObj.getString("orderId"), "orderItemSeqId", valueObj.getString("orderItemSeqId")));
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                    throw new GeneralException(e.getMessage());
+                }
+                if (UtilValidate.isNotEmpty(oldOrderItem)) {
+                    
+                    //  Existing order item found. Check for modifications and store if any
+                    String oldItemDescription = oldOrderItem.getString("itemDescription") != null ? oldOrderItem.getString("itemDescription") : "";
+                    Double oldQuantity = oldOrderItem.getDouble("quantity") != null ? oldOrderItem.getDouble("quantity") : Double.valueOf(0.00);
+                    Double oldUnitPrice = oldOrderItem.getDouble("unitPrice") != null ? oldOrderItem.getDouble("unitPrice") : Double.valueOf(0.00);
+                    
+                    boolean changeFound = false;
+                    if (oldItemDescription.equals(valueObj.getString("itemDescription"))) {
+                        oldOrderItem.remove("itemDescription");
+                    } else {
+                        changeFound = true;
+                    }
+                    
+                    Double quantityDif = Double.valueOf(valueObj.getDouble("quantity").doubleValue() - oldQuantity.doubleValue());
+                    Double unitPriceDif = Double.valueOf(valueObj.getDouble("unitPrice").doubleValue() - oldUnitPrice.doubleValue());
+                    if (quantityDif.doubleValue() == 0) {
+                        oldOrderItem.remove("quantity");
+                    } else {
+                        oldOrderItem.set("quantity", quantityDif);
+                        changeFound = true;
+                    }
+                    if (unitPriceDif.doubleValue() == 0) {
+                        oldOrderItem.remove("unitPrice");
+                    } else {
+                        oldOrderItem.set("unitPrice", unitPriceDif);
+                        changeFound = true;
+                    }
+                    if (changeFound) {
+                        modifiedItems.add(oldOrderItem);
+                    }                    
+                }                
+            }            
         }
         Debug.log("To Store Contains: " + toStore, module);
 
@@ -3583,6 +3645,30 @@
             throw new GeneralException(e.getMessage());
         }
 
+        //store the orderItem changes
+        if (UtilValidate.isNotEmpty(modifiedItems)) {            
+            for (GenericValue oldItemValues : modifiedItems) {
+                Map serviceCtx = FastMap.newInstance();
+                serviceCtx.put("orderId", oldItemValues.getString("orderId"));
+                serviceCtx.put("orderItemSeqId", oldItemValues.getString("orderItemSeqId"));
+                serviceCtx.put("itemDescription", oldItemValues.getString("itemDescription"));
+                serviceCtx.put("quantity", oldItemValues.getDouble("quantity"));
+                serviceCtx.put("unitPrice", oldItemValues.getDouble("unitPrice"));
+                serviceCtx.put("changeTypeEnumId", "ODR_ITM_UPDATE");                
+                serviceCtx.put("userLogin", userLogin);
+                Map resp = null;
+                try {
+                    resp = dispatcher.runSync("createOrderItemChange", serviceCtx);
+                } catch (GenericServiceException e) {
+                    Debug.logError(e, module);
+                    throw new GeneralException(e.getMessage());
+                }
+                if (ServiceUtil.isError(resp)) {
+                    throw new GeneralException((String) resp.get(ModelService.ERROR_MESSAGE));
+                }
+            }
+        }
+        
         // make the order item object map & the ship group assoc list
         List orderItemShipGroupAssoc = new LinkedList();
         Map itemValuesBySeqId = new HashMap();