This is an automated email from the ASF dual-hosted git repository.

mbrohl pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new a07c44f516 Extending individual discountRate value (OFBIZ-12802)
a07c44f516 is described below

commit a07c44f51660f091feec66723017b3366b243b11
Author: Adrian Wolf <adrian.w...@ecomify.de>
AuthorDate: Mon Apr 17 10:09:12 2023 +0200

    Extending individual discountRate value (OFBIZ-12802)
    
    + Addition of additional context information "productStoreGroupId" and
    "partyId" to the call parameters of a "customMethodName"
    price-calc-service
    + Obtaining the fields discountRate and listPrice from calling a
    "customMethodName" price-calc-service
    
    + discountRate as Result Field
    + Transport original discount rate from custom price calculation over
    cart to order to have the correct rate instead of back-calculating it
    from unitPrice and unitListPrice
---
 applications/datamodel/entitydef/order-entitymodel.xml |  1 +
 .../apache/ofbiz/order/shoppingcart/ShoppingCart.java  |  1 +
 .../ofbiz/order/shoppingcart/ShoppingCartItem.java     | 10 ++++++++++
 .../product/servicedef/services_pricepromo.xml         |  1 +
 .../org/apache/ofbiz/product/price/PriceServices.java  | 18 ++++++++++++++++--
 5 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/applications/datamodel/entitydef/order-entitymodel.xml 
b/applications/datamodel/entitydef/order-entitymodel.xml
index f827711b7a..54b3cd9bba 100644
--- a/applications/datamodel/entitydef/order-entitymodel.xml
+++ b/applications/datamodel/entitydef/order-entitymodel.xml
@@ -549,6 +549,7 @@ under the License.
       <field name="unitListPrice" type="currency-precise"></field>
       <field name="unitAverageCost" type="currency-amount"></field>
       <field name="unitRecurringPrice" type="currency-amount"></field>
+      <field name="discountRate" type="fixed-point"></field>
       <field name="isModifiedPrice" type="indicator"></field>
       <field name="recurringFreqUomId" type="id"></field>
       <field name="itemDescription" type="description"></field>
diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
index 42f9c702ec..431c6cfb12 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
@@ -4376,6 +4376,7 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
                 orderItem.set("selectedAmount", item.getSelectedAmount());
                 orderItem.set("unitPrice", item.getBasePrice());
                 orderItem.set("unitListPrice", item.getListPrice());
+                orderItem.set("discountRate", item.getDiscountRate());
                 orderItem.set("isModifiedPrice", item.getIsModifiedPrice() ? 
"Y" : "N");
                 orderItem.set("isPromo", item.getIsPromo() ? "Y" : "N");
 
diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
index 8a3064b45d..1bf7b3b8d1 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
@@ -135,6 +135,7 @@ public class ShoppingCartItem implements 
java.io.Serializable {
      */
     private BigDecimal reservNthPPPerc = BigDecimal.ZERO;
     private BigDecimal listPrice = BigDecimal.ZERO;
+    private BigDecimal discountRate = null;
     /**
      * flag to know if the price have been modified
      */
@@ -1412,6 +1413,7 @@ public class ShoppingCartItem implements 
java.io.Serializable {
                         }
 
                         this.setSpecialPromoPrice((BigDecimal) 
priceResult.get("specialPromoPrice"));
+                        this.discountRate = (BigDecimal) 
priceResult.get("discountRate");
                     }
 
                     this.orderItemPriceInfos = 
UtilGenerics.cast(priceResult.get("orderItemPriceInfos"));
@@ -2502,6 +2504,14 @@ public class ShoppingCartItem implements 
java.io.Serializable {
         this.listPrice = listPrice;
     }
 
+    /**
+     * Returns the DiscountRate
+     * @return discountRate
+     */
+    public BigDecimal getDiscountRate() {
+        return discountRate;
+    }
+
     /**
      * Returns isModifiedPrice
      */
diff --git a/applications/product/servicedef/services_pricepromo.xml 
b/applications/product/servicedef/services_pricepromo.xml
index cd59004ea9..83f0ec0b9b 100644
--- a/applications/product/servicedef/services_pricepromo.xml
+++ b/applications/product/servicedef/services_pricepromo.xml
@@ -49,6 +49,7 @@ under the License.
         <attribute name="basePrice" type="BigDecimal" mode="OUT" 
optional="false"><!-- will only be different from price if there is a display 
price adjustment, for example: checkIncludeVat=Y and a VAT amount was found 
--></attribute>
         <attribute name="price" type="BigDecimal" mode="OUT" optional="false"/>
         <attribute name="listPrice" type="BigDecimal" mode="OUT" 
optional="true"/>
+        <attribute name="discountRate" type="BigDecimal" mode="OUT" 
optional="true" />
         <attribute name="defaultPrice" type="BigDecimal" mode="OUT" 
optional="true"/>
         <attribute name="competitivePrice" type="BigDecimal" mode="OUT" 
optional="true"/>
         <attribute name="averageCost" type="BigDecimal" mode="OUT" 
optional="true"/>
diff --git 
a/applications/product/src/main/java/org/apache/ofbiz/product/price/PriceServices.java
 
b/applications/product/src/main/java/org/apache/ofbiz/product/price/PriceServices.java
index 6c13e27151..66376141b4 100644
--- 
a/applications/product/src/main/java/org/apache/ofbiz/product/price/PriceServices.java
+++ 
b/applications/product/src/main/java/org/apache/ofbiz/product/price/PriceServices.java
@@ -343,6 +343,8 @@ public class PriceServices {
 
         boolean validPriceFound = false;
         BigDecimal defaultPrice = BigDecimal.ZERO;
+        BigDecimal listPrice = null;
+        BigDecimal discountRate = null;
         List<GenericValue> orderItemPriceInfos = new LinkedList<>();
         if (defaultPriceValue != null) {
             // If a price calc formula (service) is specified, then use it to 
get the unit price
@@ -366,13 +368,19 @@ public class PriceServices {
                     if (UtilValidate.isNotEmpty(customAttributes)) {
                         inMap.put("customAttributes", customAttributes);
                     }
+                    inMap.put("productStoreGroupId", productStoreGroupId);
+                    inMap.put("partyId", partyId);
                     try {
                         Map<String, Object> outMap = 
dispatcher.runSync(customMethod.getString("customMethodName"), inMap);
                         if (ServiceUtil.isSuccess(outMap)) {
                             BigDecimal calculatedDefaultPrice = (BigDecimal) 
outMap.get("price");
+                            BigDecimal calculatedListPrice = (BigDecimal) 
outMap.get("listPrice");
+                            BigDecimal calculatedDiscountRate = (BigDecimal) 
outMap.get("discountRate");
                             orderItemPriceInfos = 
UtilGenerics.cast(outMap.get("orderItemPriceInfos"));
                             if 
(UtilValidate.isNotEmpty(calculatedDefaultPrice)) {
                                 defaultPrice = calculatedDefaultPrice;
+                                listPrice = calculatedListPrice;
+                                discountRate = calculatedDiscountRate;
                                 validPriceFound = true;
                             }
                         }
@@ -388,9 +396,13 @@ public class PriceServices {
             }
         }
 
-        BigDecimal listPrice = listPriceValue != null ? 
listPriceValue.getBigDecimal("price") : null;
+        boolean skipPriceRules = true;
+        if (listPrice == null && listPriceValue != null) {
+            listPrice = listPriceValue.getBigDecimal("price");
+            skipPriceRules = listPrice == null;
+        }
 
-        if (listPrice == null) {
+        if (skipPriceRules) {
             // no list price, use defaultPrice for the final price
 
             // ========= ensure calculated price is not below minSalePrice or 
above maxSalePrice =========
@@ -407,6 +419,8 @@ public class PriceServices {
                 validPriceFound = true;
             }
 
+            result.put("listPrice", listPrice);
+            result.put("discountRate", discountRate);
             result.put("basePrice", defaultPrice);
             result.put("price", defaultPrice);
             result.put("defaultPrice", defaultPrice);

Reply via email to