Skip to content

Commit a07c44f

Browse files
Adrian-Wolfmbrohl
authored andcommitted
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
1 parent a41f054 commit a07c44f

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

applications/datamodel/entitydef/order-entitymodel.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ under the License.
549549
<field name="unitListPrice" type="currency-precise"></field>
550550
<field name="unitAverageCost" type="currency-amount"></field>
551551
<field name="unitRecurringPrice" type="currency-amount"></field>
552+
<field name="discountRate" type="fixed-point"></field>
552553
<field name="isModifiedPrice" type="indicator"></field>
553554
<field name="recurringFreqUomId" type="id"></field>
554555
<field name="itemDescription" type="description"></field>

applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4376,6 +4376,7 @@ public List<GenericValue> makeOrderItems(boolean explodeItems, boolean replaceAg
43764376
orderItem.set("selectedAmount", item.getSelectedAmount());
43774377
orderItem.set("unitPrice", item.getBasePrice());
43784378
orderItem.set("unitListPrice", item.getListPrice());
4379+
orderItem.set("discountRate", item.getDiscountRate());
43794380
orderItem.set("isModifiedPrice", item.getIsModifiedPrice() ? "Y" : "N");
43804381
orderItem.set("isPromo", item.getIsPromo() ? "Y" : "N");
43814382

applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public class ShoppingCartItem implements java.io.Serializable {
135135
*/
136136
private BigDecimal reservNthPPPerc = BigDecimal.ZERO;
137137
private BigDecimal listPrice = BigDecimal.ZERO;
138+
private BigDecimal discountRate = null;
138139
/**
139140
* flag to know if the price have been modified
140141
*/
@@ -1412,6 +1413,7 @@ public void updatePrice(LocalDispatcher dispatcher, ShoppingCart cart) throws Ca
14121413
}
14131414

14141415
this.setSpecialPromoPrice((BigDecimal) priceResult.get("specialPromoPrice"));
1416+
this.discountRate = (BigDecimal) priceResult.get("discountRate");
14151417
}
14161418

14171419
this.orderItemPriceInfos = UtilGenerics.cast(priceResult.get("orderItemPriceInfos"));
@@ -2502,6 +2504,14 @@ public void setListPrice(BigDecimal listPrice) {
25022504
this.listPrice = listPrice;
25032505
}
25042506

2507+
/**
2508+
* Returns the DiscountRate
2509+
* @return discountRate
2510+
*/
2511+
public BigDecimal getDiscountRate() {
2512+
return discountRate;
2513+
}
2514+
25052515
/**
25062516
* Returns isModifiedPrice
25072517
*/

applications/product/servicedef/services_pricepromo.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ under the License.
4949
<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>
5050
<attribute name="price" type="BigDecimal" mode="OUT" optional="false"/>
5151
<attribute name="listPrice" type="BigDecimal" mode="OUT" optional="true"/>
52+
<attribute name="discountRate" type="BigDecimal" mode="OUT" optional="true" />
5253
<attribute name="defaultPrice" type="BigDecimal" mode="OUT" optional="true"/>
5354
<attribute name="competitivePrice" type="BigDecimal" mode="OUT" optional="true"/>
5455
<attribute name="averageCost" type="BigDecimal" mode="OUT" optional="true"/>

applications/product/src/main/java/org/apache/ofbiz/product/price/PriceServices.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ public static Map<String, Object> calculateProductPrice(DispatchContext dctx, Ma
343343

344344
boolean validPriceFound = false;
345345
BigDecimal defaultPrice = BigDecimal.ZERO;
346+
BigDecimal listPrice = null;
347+
BigDecimal discountRate = null;
346348
List<GenericValue> orderItemPriceInfos = new LinkedList<>();
347349
if (defaultPriceValue != null) {
348350
// If a price calc formula (service) is specified, then use it to get the unit price
@@ -366,13 +368,19 @@ public static Map<String, Object> calculateProductPrice(DispatchContext dctx, Ma
366368
if (UtilValidate.isNotEmpty(customAttributes)) {
367369
inMap.put("customAttributes", customAttributes);
368370
}
371+
inMap.put("productStoreGroupId", productStoreGroupId);
372+
inMap.put("partyId", partyId);
369373
try {
370374
Map<String, Object> outMap = dispatcher.runSync(customMethod.getString("customMethodName"), inMap);
371375
if (ServiceUtil.isSuccess(outMap)) {
372376
BigDecimal calculatedDefaultPrice = (BigDecimal) outMap.get("price");
377+
BigDecimal calculatedListPrice = (BigDecimal) outMap.get("listPrice");
378+
BigDecimal calculatedDiscountRate = (BigDecimal) outMap.get("discountRate");
373379
orderItemPriceInfos = UtilGenerics.cast(outMap.get("orderItemPriceInfos"));
374380
if (UtilValidate.isNotEmpty(calculatedDefaultPrice)) {
375381
defaultPrice = calculatedDefaultPrice;
382+
listPrice = calculatedListPrice;
383+
discountRate = calculatedDiscountRate;
376384
validPriceFound = true;
377385
}
378386
}
@@ -388,9 +396,13 @@ public static Map<String, Object> calculateProductPrice(DispatchContext dctx, Ma
388396
}
389397
}
390398

391-
BigDecimal listPrice = listPriceValue != null ? listPriceValue.getBigDecimal("price") : null;
399+
boolean skipPriceRules = true;
400+
if (listPrice == null && listPriceValue != null) {
401+
listPrice = listPriceValue.getBigDecimal("price");
402+
skipPriceRules = listPrice == null;
403+
}
392404

393-
if (listPrice == null) {
405+
if (skipPriceRules) {
394406
// no list price, use defaultPrice for the final price
395407

396408
// ========= ensure calculated price is not below minSalePrice or above maxSalePrice =========
@@ -407,6 +419,8 @@ public static Map<String, Object> calculateProductPrice(DispatchContext dctx, Ma
407419
validPriceFound = true;
408420
}
409421

422+
result.put("listPrice", listPrice);
423+
result.put("discountRate", discountRate);
410424
result.put("basePrice", defaultPrice);
411425
result.put("price", defaultPrice);
412426
result.put("defaultPrice", defaultPrice);

0 commit comments

Comments
 (0)