On 10/19/2010 03:35 AM, jler...@apache.org wrote:
Author: jleroux
Date: Tue Oct 19 08:35:19 2010
New Revision: 1024177

URL: http://svn.apache.org/viewvc?rev=1024177&view=rev
Log:
A patch from Sascha Rodekamp "Product Promo Worker description patch" 
(https://issues.apache.org/jira/browse/OFBIZ-3907) - OFBIZ-3907

This patch extends the order adjustment creation. If an order adjustment is 
created from a product promo the promo text will store in the order adjustment 
description. This helps identifying the order adjustment and later on the 
invoice item type : ITM_PROMOTION_ADJ.

Modified:
     
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java?rev=1024177&r1=1024176&r2=1024177&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
 Tue Oct 19 08:35:19 2010
@@ -1716,9 +1716,10 @@ public class ProductPromoWorker {
          amount = amount.setScale(decimals, rounding);
          GenericValue orderAdjustment = delegator.makeValue("OrderAdjustment",
                  UtilMisc.toMap("orderAdjustmentTypeId", 
"PROMOTION_ADJUSTMENT", amountField, amount,
-                    "productPromoId", productPromoAction.get("productPromoId"),
-                    "productPromoRuleId", 
productPromoAction.get("productPromoRuleId"),
-                    "productPromoActionSeqId", 
productPromoAction.get("productPromoActionSeqId")));
+                "productPromoId", productPromoAction.get("productPromoId"),
+                "productPromoRuleId", 
productPromoAction.get("productPromoRuleId"),
+                "productPromoActionSeqId", 
productPromoAction.get("productPromoActionSeqId"),
+                "description", getProductPromoDescription((String) 
productPromoAction.get("productPromoId"), delegator)));

          // if an orderAdjustmentTypeId was included, override the default
          if 
(UtilValidate.isNotEmpty(productPromoAction.getString("orderAdjustmentTypeId")))
 {
@@ -1733,9 +1734,10 @@ public class ProductPromoWorker {
          amount = amount.setScale(decimals, rounding);
          GenericValue orderAdjustment = delegator.makeValue("OrderAdjustment",
                  UtilMisc.toMap("orderAdjustmentTypeId", 
"PROMOTION_ADJUSTMENT", amountField, amount,
-                    "productPromoId", productPromoAction.get("productPromoId"),
-                    "productPromoRuleId", 
productPromoAction.get("productPromoRuleId"),
-                    "productPromoActionSeqId", 
productPromoAction.get("productPromoActionSeqId")));
+                "productPromoId", productPromoAction.get("productPromoId"),
+                "productPromoRuleId", 
productPromoAction.get("productPromoRuleId"),
+                "productPromoActionSeqId", 
productPromoAction.get("productPromoActionSeqId"),
+                "description", getProductPromoDescription((String) 
productPromoAction.get("productPromoId"), delegator)));

These 2 changes were reindented, without needing to be. It's nicer to have such changes separated; svn annotate now shows a false positive on these lines, when nothing has actually changed.


          // if an orderAdjustmentTypeId was included, override the default
          if 
(UtilValidate.isNotEmpty(productPromoAction.getString("orderAdjustmentTypeId")))
 {
@@ -1745,6 +1747,23 @@ public class ProductPromoWorker {
          cart.addAdjustment(orderAdjustment);
      }

+    private static String getProductPromoDescription(String prodPromoId, 
Delegator delegator) {
+        // get the promoText / promoName to set as a descr of the orderAdj
+        GenericValue prodPromo;
+        try {
+            prodPromo = delegator.findByPrimaryKeyCache("ProductPromo", 
UtilMisc.toMap("productPromoId", prodPromoId));
+            if (UtilValidate.isNotEmpty(prodPromo.get("promoText"))) {
+                return (String) prodPromo.get("promoText");
+            }
+            return (String) prodPromo.get("promoName");
+
+        } catch (GenericEntityException e) {
+            Debug.logWarning("Error getting ProductPromo for Id " + 
prodPromoId, module);
+        }
+
+        return null;
+    }
+
      protected static Integer findAdjustment(GenericValue productPromoAction, 
List adjustments) {
          for (int i = 0; i<  adjustments.size(); i++) {
              GenericValue checkOrderAdjustment = (GenericValue) 
adjustments.get(i);



Reply via email to