Author: jleroux
Date: Sat Sep 10 21:54:53 2011
New Revision: 1167613

URL: http://svn.apache.org/viewvc?rev=1167613&view=rev
Log:
"Applied fix from trunk for revision: 1167606  " (conflict handled by hand)
------------------------------------------------------------------------
r1167606 | jleroux | 2011-09-10 23:08:01 +0200 (sam., 10 sept. 2011) | 7 lines

A patch from Paul Foxworthy "loadCartFromQuote should put tax adjustments into 
the shipping group" https://issues.apache.org/jira/browse/OFBIZ-4391

loadCartFromQuote is currently copying all adjustments from a quote into the 
order-wide adjustments for the shopping cart. Tax adjustments should be copied 
into the shipping group, i.e. treated in a different way from adjustments like 
a discount.

There's also a, unit test that demonstrates the bug. Apply just the test patch 
and you should see the problem. Apply the other patch with the change to 
loadCartFromQuote, and the test should pass.

jleroux: also a French label fix
------------------------------------------------------------------------

Modified:
    
ofbiz/branches/release11.04/applications/order/script/org/ofbiz/order/test/ShoppingCartTests.xml
    
ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
    ofbiz/branches/release11.04/applications/order/testdef/ShoppingCartTests.xml
    ofbiz/branches/release11.04/applications/party/config/PartyEntityLabels.xml

Modified: 
ofbiz/branches/release11.04/applications/order/script/org/ofbiz/order/test/ShoppingCartTests.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release11.04/applications/order/script/org/ofbiz/order/test/ShoppingCartTests.xml?rev=1167613&r1=1167612&r2=1167613&view=diff
==============================================================================
--- 
ofbiz/branches/release11.04/applications/order/script/org/ofbiz/order/test/ShoppingCartTests.xml
 (original)
+++ 
ofbiz/branches/release11.04/applications/order/script/org/ofbiz/order/test/ShoppingCartTests.xml
 Sat Sep 10 21:54:53 2011
@@ -104,12 +104,12 @@ under the License.
             <field field="skipInventoryChecks" type="Boolean"/>
             <field field="skipProductChecks" type="Boolean"/>
         </call-object-method>
-        
+
         <set field="itemIdex" from-field="itemIdex" type="Integer"/>
         <call-object-method method-name="findCartItem" 
obj-field="shoppingCart" ret-field="cartItem">
             <field field="itemIdex" type="int"/>
         </call-object-method>
-        
+
         <set field="groupIdx" value="0" type="Integer"/>
         <call-object-method method-name="setItemShipGroupQty" 
obj-field="shoppingCart">
             <field field="cartItem" 
type="org.ofbiz.order.shoppingcart.ShoppingCartItem"/>
@@ -135,7 +135,7 @@ under the License.
         <set field="orderAdjustmentShipping.orderAdjustmentTypeId" 
value="SHIPPING_CHARGES"/>
         <set field="orderAdjustmentShipping.shipGroupSeqId" value="00001"/>
         <set field="orderAdjustmentShipping.amount" value="12.10" 
type="BigDecimal"/>
-        
+
         <call-object-method method-name="addAdjustment" 
obj-field="shoppingCart">
             <field field="orderAdjustmentShipping" 
type="org.ofbiz.entity.GenericValue"/>
         </call-object-method>
@@ -260,4 +260,74 @@ under the License.
         <assert><not><if-empty field="orderMap.orderId"/></not></assert>
         <check-errors/>
     </simple-method>
+
+    <simple-method method-name="testLoadCartFromQuote" short-description="Test 
loading shopping cart from quote" login-required="false">
+        <entity-one entity-name="UserLogin" value-field="userLogin">
+            <field-map field-name="userLoginId" value="system"/>
+        </entity-one>
+
+        <set field="createQuoteMap.userLogin" from-field="userLogin"/>
+        <set field="createQuoteMap.partyId" value="DemoCustomer"/>
+        <set field="createQuoteMap.currencyUomId" value="USD"/>
+        <set field="createQuoteMap.description" value="Test quote"/>
+        <set field="createQuoteMap.issueDate" value="2011-11-01 10:00:00.0" 
type="Timestamp"/>
+        <set field="createQuoteMap.productStoreId" value="9000"/>
+        <set field="createQuoteMap.quoteName" value="Test quote"/>
+        <set field="createQuoteMap.quoteTypeId" value="PRODUCT_QUOTE"/>
+        <set field="createQuoteMap.statusId" value="QUO_APPROVED"/>
+        <set field="createQuoteMap.validFromDate" value="2011-11-01 
10:00:00.0"  type="Timestamp"/>
+        <call-service service-name="createQuote" in-map-name="createQuoteMap">
+            <result-to-field result-name="quoteId"/>
+        </call-service>
+        <check-errors/>
+
+        <set field="createQuoteItemMap.userLogin" from-field="userLogin"/>
+        <set field="createQuoteItemMap.quoteId" from-field="quoteId"/>
+        <set field="createQuoteItemMap.productId" value="GZ-1000"/>
+        <set field="createQuoteItemMap.quantity" value="10" type="BigDecimal"/>
+        <set field="createQuoteItemMap.quoteUnitPrice" value="15.00" 
type="BigDecimal"/>
+        <call-service service-name="createQuoteItem" 
in-map-name="createQuoteItemMap">
+            <result-to-field result-name="quoteItemSeqNo"/>
+        </call-service>
+        <check-errors/>
+
+        <set field="createQuoteAdjustmentMap.userLogin" 
from-field="userLogin"/>
+        <set field="createQuoteAdjustmentMap.quoteId" from-field="quoteId"/>
+        <set field="createQuoteAdjustmentMap.quoteItemSeqId" 
from-field="quoteItemSeqId"/>
+        <set field="createQuoteAdjustmentMap.amount" value="15.00" 
type="BigDecimal"/>
+        <set field="createQuoteAdjustmentMap.includeInShipping " value="N"/>
+        <set field="createQuoteAdjustmentMap.includeInTax" value="Y"/>
+        <set field="createQuoteAdjustmentMap.quoteAdjustmentTypeId" 
value="SALES_TAX"/>
+        <set field="createQuoteAdjustmentMap.taxAuthGeoId" value="UT"/>
+        <set field="createQuoteAdjustmentMap.taxAuthPartyId" 
value="UT_TAXMAN"/>
+        <call-service service-name="createQuoteAdjustment" 
in-map-name="createQuoteAdjustmentMap">
+            <result-to-field result-name="quoteAdjustmentId"/>
+        </call-service>
+        <check-errors/>
+
+        <set field="loadCartFromQuoteMap.userLogin" from-field="userLogin"/>
+        <set field="loadCartFromQuoteMap.quoteId" from-field="quoteId"/>
+        <set field="loadCartFromQuoteMap.applyQuoteAdjustments" value="true"/>
+        <call-service service-name="loadCartFromQuote" 
in-map-name="loadCartFromQuoteMap">
+            <result-to-field result-name="shoppingCart"/>
+        </call-service>
+        <check-errors/>
+
+        <set field="expected" value="15.00" type="BigDecimal"/>
+
+        <call-object-method obj-field="shoppingCart" 
method-name="getTotalSalesTax" ret-field="totalSalesTax"/>
+        <assert><if-compare-field operator="equals" field="totalSalesTax" 
to-field="expected"/></assert>
+
+        <set field="shipGroupNumber" value="0" type="Integer"/>
+        <call-object-method obj-field="shoppingCart" 
method-name="getTotalSalesTax" ret-field="totalSalesTax">
+            <field field="shipGroupNumber" type="int"/>
+        </call-object-method>
+        <assert><if-compare-field operator="equals" field="totalSalesTax" 
to-field="expected"/></assert>
+
+        <set field="expected" value="165.00" type="BigDecimal"/>
+        <call-object-method obj-field="shoppingCart" 
method-name="getGrandTotal" ret-field="grandTotal"/>
+        <assert><if-compare-field operator="equals" field="grandTotal" 
to-field="expected"/></assert>
+        <check-errors/>
+    </simple-method>
+
 </simple-methods>

Modified: 
ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java?rev=1167613&r1=1167612&r2=1167613&view=diff
==============================================================================
--- 
ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
 (original)
+++ 
ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
 Sat Sep 10 21:54:53 2011
@@ -201,7 +201,7 @@ public class ShoppingCartServices {
         cart.setOrderName(orderHeader.getString("orderName"));
         cart.setOrderStatusId(orderHeader.getString("statusId"));
         cart.setOrderStatusString(currentStatusString);
-        cart.setFacilityId(orderHeader.getString("originFacilityId"));        
+        cart.setFacilityId(orderHeader.getString("originFacilityId"));
 
         try {
             cart.setUserLogin(userLogin, dispatcher);
@@ -509,7 +509,7 @@ public class ShoppingCartServices {
                 try {
                     orderItemAttributesList = 
delegator.findByAnd("OrderItemAttribute", UtilMisc.toMap("orderId", orderId, 
"orderItemSeqId", orderItemSeqId));
                     if (UtilValidate.isNotEmpty(orderAttributesList)) {
-                        for(GenericValue orderItemAttr : 
orderItemAttributesList) {
+                        for (GenericValue orderItemAttr : 
orderItemAttributesList) {
                             String name = orderItemAttr.getString("attrName");
                             String value = 
orderItemAttr.getString("attrValue");
                             cartItem.setOrderItemAttribute(name, value);
@@ -543,12 +543,7 @@ public class ShoppingCartServices {
                 List<GenericValue> itemAdjustments = 
orh.getOrderItemAdjustments(item);
                 if (itemAdjustments != null) {
                     for(GenericValue itemAdjustment : itemAdjustments) {
-                        if 
("SALES_TAX".equals(itemAdjustment.get("orderAdjustmentTypeId")) ||
-                                
"VAT_TAX".equals(itemAdjustment.get("orderAdjustmentTypeId")) ||
-                                
"VAT_PRICE_CORRECT".equals(itemAdjustment.get("orderAdjustmentTypeId"))) {
-                            continue;
-                        }
-                        cartItem.addAdjustment(itemAdjustment);
+                        if (!isTaxAdjustment(itemAdjustment)) 
cartItem.addAdjustment(itemAdjustment);
                     }
                 }
             }
@@ -607,12 +602,7 @@ public class ShoppingCartServices {
                             } else {
                                 List<GenericValue> itemTaxAdj = 
cartShipItemInfo.itemTaxAdj;
                                 for (GenericValue shipGroupItemAdjustment : 
shipGroupItemAdjustments) {
-                                    if 
("SALES_TAX".equals(shipGroupItemAdjustment.get("orderAdjustmentTypeId")) ||
-                                            
"VAT_TAX".equals(shipGroupItemAdjustment.get("orderAdjustmentTypeId")) ||
-                                            
"VAT_PRICE_CORRECT".equals(shipGroupItemAdjustment.get("orderAdjustmentTypeId")))
 {
-                                        
itemTaxAdj.add(shipGroupItemAdjustment);
-                                        continue;
-                                    }
+                                    if 
(isTaxAdjustment(shipGroupItemAdjustment)) 
itemTaxAdj.add(shipGroupItemAdjustment);
                                 }
                             }
                         }
@@ -748,7 +738,7 @@ public class ShoppingCartServices {
                 cart.addOrderTerm(quoteTerm.getString("termTypeId"), 
orderItemSeqId,termValue, termDays, 
quoteTerm.getString("textValue"),quoteTerm.getString("description"));
             }
         }
-        
+
         // set the attribute information
         if (UtilValidate.isNotEmpty(quoteAttributes)) {
             for(GenericValue quoteAttribute : quoteAttributes) {
@@ -892,10 +882,24 @@ public class ShoppingCartServices {
         // If applyQuoteAdjustments is set to false then standard cart 
adjustments are used.
         if (applyQuoteAdjustments) {
             // The cart adjustments, derived from quote adjustments, are added 
to the cart
+
+            // Tax adjustments should be added to the shipping group and 
shipping group item info
+            // Other adjustments like promotional price should be added to the 
cart independent of
+            // the ship group.
+            // We're creating the cart right now using data from the quote, so 
there cannot yet be more than one ship group.
+
+            List<GenericValue> cartAdjs = cart.getAdjustments();
+            CartShipInfo shipInfo = cart.getShipInfo(0);
+
             List<GenericValue> adjs = orderAdjsMap.get(quoteId);
+
             if (adjs != null) {
-                cart.getAdjustments().addAll(adjs);
+                for (GenericValue adj : adjs) {
+                    if (isTaxAdjustment( adj )) shipInfo.shipTaxAdj.add(adj);
+                    else cartAdjs.add(adj);
+                }
             }
+
             // The cart item adjustments, derived from quote item adjustments, 
are added to the cart
             if (quoteItems != null) {
                 Iterator<ShoppingCartItem> i = cart.iterator();
@@ -908,11 +912,20 @@ public class ShoppingCartServices {
                         adjs = null;
                     }
                     if (adjs != null) {
-                        item.getAdjustments().addAll(adjs);
+                        for (GenericValue adj : adjs) {
+                            if (isTaxAdjustment( adj )) {
+                                CartShipItemInfo csii = 
shipInfo.getShipItemInfo(item);
+
+                                if (csii.itemTaxAdj == null) 
shipInfo.setItemInfo(item, UtilMisc.toList(adj));
+                                else csii.itemTaxAdj.add(adj);
+                            }
+                            else item.addAdjustment(adj);
+                        }
                     }
                 }
             }
         }
+
         // set the item seq in the cart
         if (nextItemSeq > 0) {
             try {
@@ -928,6 +941,12 @@ public class ShoppingCartServices {
         return result;
     }
 
+    private static boolean isTaxAdjustment(GenericValue cartAdj) {
+        String adjType = cartAdj.getString("orderAdjustmentTypeId");
+
+        return "SALES_TAX".equals(adjType) || "VAT_TAX".equals(adjType) || 
"VAT_PRICE_CORRECT".equals(adjType);
+    }
+
     public static Map<String, Object>loadCartFromShoppingList(DispatchContext 
dctx, Map<String, Object> context) {
         LocalDispatcher dispatcher = dctx.getDispatcher();
         Delegator delegator = dctx.getDelegator();
@@ -1034,7 +1053,7 @@ public class ShoppingCartServices {
                         Debug.logError(e, module);
                         return ServiceUtil.returnError(e.getMessage());
                     }
-                    
+
                     // set the modified price
                     if (modifiedPrice != null && modifiedPrice.doubleValue() 
!= 0) {
                         ShoppingCartItem item = cart.findCartItem(itemIndex);

Modified: 
ofbiz/branches/release11.04/applications/order/testdef/ShoppingCartTests.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release11.04/applications/order/testdef/ShoppingCartTests.xml?rev=1167613&r1=1167612&r2=1167613&view=diff
==============================================================================
--- 
ofbiz/branches/release11.04/applications/order/testdef/ShoppingCartTests.xml 
(original)
+++ 
ofbiz/branches/release11.04/applications/order/testdef/ShoppingCartTests.xml 
Sat Sep 10 21:54:53 2011
@@ -18,11 +18,14 @@ specific language governing permissions 
 under the License.
 -->
 
-<test-suite suite-name="shopingcarttests"
+<test-suite suite-name="shoppingcarttests"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd";>
 
     <test-case case-name="shoppingCart-test">
         <simple-method-test 
location="component://order/script/org/ofbiz/order/test/ShoppingCartTests.xml" 
name="testCreateShoppingCart"/>
     </test-case>
+    <test-case case-name="loadCartFromQuote-test">
+        <simple-method-test 
location="component://order/script/org/ofbiz/order/test/ShoppingCartTests.xml" 
name="testLoadCartFromQuote"/>
+    </test-case>
 </test-suite>

Modified: 
ofbiz/branches/release11.04/applications/party/config/PartyEntityLabels.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release11.04/applications/party/config/PartyEntityLabels.xml?rev=1167613&r1=1167612&r2=1167613&view=diff
==============================================================================
--- ofbiz/branches/release11.04/applications/party/config/PartyEntityLabels.xml 
(original)
+++ ofbiz/branches/release11.04/applications/party/config/PartyEntityLabels.xml 
Sat Sep 10 21:54:53 2011
@@ -2800,7 +2800,7 @@
         <value xml:lang="de">Empfänger der Anfrage</value>
         <value xml:lang="en">Request Taker</value>
         <value xml:lang="es">Receptor de peticiones</value>
-        <value xml:lang="fr">Employé aux recherches</value>
+        <value xml:lang="fr">Preneur de commande</value>
         <value xml:lang="hi_IN">अनुरोध लेने 
वाला</value>
         <value xml:lang="it">Acquirente soggetto</value>
         <value xml:lang="pt_BR">Receptor de pedidos</value>


Reply via email to