You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2010/03/12 09:27:42 UTC
svn commit: r922177 - in /ofbiz/trunk/applications:
order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
product/src/org/ofbiz/product/price/PriceServices.java
Author: jleroux
Date: Fri Mar 12 08:27:42 2010
New Revision: 922177
URL: http://svn.apache.org/viewvc?rev=922177&view=rev
Log:
A slightly modified patch from Geir Ove Grønmo "Calculation of promotions and price rules should support multi-level GROUP_ROLLUP" (https://issues.apache.org/jira/browse/OFBIZ-3440) - OFBIZ-3440
The calculation of product prices given promotion and price rules do not currently take multi-level GROUP_ROLLUP party relations into account.
The calculation of price rules consider two levels of GROUP_ROLLUP only, while the calculation of promotions take just a single level of GROUP_ROLLUP into account.
The attached patch will calculate price rules and promotions for GROUP_ROLLUPs for an arbitrary number of GROUP_ROLLUPs. This is essential in the situation where there are hierarchies of parties.
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.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=922177&r1=922176&r2=922177&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 Fri Mar 12 08:27:42 2010
@@ -980,21 +980,21 @@ public class ProductPromoWorker {
if (UtilValidate.isEmpty(partyId) || UtilValidate.isEmpty(condValue)) {
compareBase = Integer.valueOf(1);
} else {
- String groupPartyId = condValue;
- if (partyId.equals(groupPartyId)) {
- compareBase = Integer.valueOf(0);
- } else {
+ String groupPartyId = condValue;
+ if (partyId.equals(groupPartyId)) {
+ compareBase = new Integer(0);
+ } else {
// look for PartyRelationship with partyRelationshipTypeId=GROUP_ROLLUP, the partyIdTo is the group member, so the partyIdFrom is the groupPartyId
- List partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"));
+ List<GenericValue> partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"));
// and from/thru date within range
partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, true);
- // then 0 (equals), otherwise 1 (not equals)
+
if (UtilValidate.isNotEmpty(partyRelationshipList)) {
- compareBase = Integer.valueOf(0);
- } else {
- compareBase = Integer.valueOf(1);
- }
- }
+ compareBase = new Integer(0);
+ } else {
+ compareBase = new Integer(checkConditionPartyHierarchy(delegator, nowTimestamp, groupPartyId, partyId));
+ }
+ }
}
} else if ("PPIP_PARTY_CLASS".equals(inputParamEnumId)) {
if (UtilValidate.isEmpty(partyId) || UtilValidate.isEmpty(condValue)) {
@@ -1002,7 +1002,7 @@ public class ProductPromoWorker {
} else {
String partyClassificationGroupId = condValue;
// find any PartyClassification
- List partyClassificationList = delegator.findByAndCache("PartyClassification", UtilMisc.toMap("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId));
+ List<GenericValue> partyClassificationList = delegator.findByAndCache("PartyClassification", UtilMisc.toMap("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId));
// and from/thru date within range
partyClassificationList = EntityUtil.filterByDate(partyClassificationList, true);
// then 0 (equals), otherwise 1 (not equals)
@@ -1181,6 +1181,21 @@ public class ProductPromoWorker {
return false;
}
+ private static int checkConditionPartyHierarchy(Delegator delegator, Timestamp nowTimestamp, String groupPartyId, String partyId) throws GenericEntityException{
+ List<GenericValue> partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"));
+ partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true);
+ for (GenericValue genericValue : partyRelationshipList) {
+ String partyIdFrom = (String)genericValue.get("partyIdFrom");
+ if (partyIdFrom.equals(groupPartyId)) {
+ return 0;
+ }
+ if (0 == checkConditionPartyHierarchy(delegator, nowTimestamp, groupPartyId, partyIdFrom)) {
+ return 0;
+ }
+ }
+ return 1;
+ }
+
public static class ActionResultInfo {
public boolean ranAction = false;
public BigDecimal totalDiscountAmount = BigDecimal.ZERO;
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java?rev=922177&r1=922176&r2=922177&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java Fri Mar 12 08:27:42 2010
@@ -1198,7 +1198,9 @@ public class PriceServices {
if (partyId.equals(groupPartyId)) {
compare = 0;
} else {
- // look for PartyRelationship with partyRelationshipTypeId=GROUP_ROLLUP, the partyIdTo is the group member, so the partyIdFrom is the groupPartyId
+ // look for PartyRelationship with
+ // partyRelationshipTypeId=GROUP_ROLLUP, the partyIdTo is
+ // the group member, so the partyIdFrom is the groupPartyId
List<GenericValue> partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"));
// and from/thru date within range
partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true);
@@ -1206,15 +1208,7 @@ public class PriceServices {
if (UtilValidate.isNotEmpty(partyRelationshipList)) {
compare = 0;
} else {
- // before setting 1 try one more query: look for a 2 hop relationship
- List<GenericValue> partyRelationshipTwoHopList = delegator.findByAndCache("PartyRelationshipToFrom", UtilMisc.toMap("onePartyIdFrom", groupPartyId, "twoPartyIdTo", partyId, "onePartyRelationshipTypeId", "GROUP_ROLLUP", "twoPartyRelationshipTypeId", "GROUP_ROLLUP"));
- partyRelationshipTwoHopList = EntityUtil.filterByDate(partyRelationshipTwoHopList, nowTimestamp, "oneFromDate", "oneThruDate", true);
- partyRelationshipTwoHopList = EntityUtil.filterByDate(partyRelationshipTwoHopList, nowTimestamp, "twoFromDate", "twoThruDate", true);
- if (UtilValidate.isNotEmpty(partyRelationshipTwoHopList)) {
- compare = 0;
- } else {
- compare = 1;
- }
+ compare = checkConditionPartyHierarchy(delegator, nowTimestamp, groupPartyId, partyId);
}
}
}
@@ -1281,6 +1275,22 @@ public class PriceServices {
return false;
}
+ private static int checkConditionPartyHierarchy(Delegator delegator, Timestamp nowTimestamp, String groupPartyId, String partyId) throws GenericEntityException{
+ List<GenericValue> partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"));
+ partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true);
+ for (GenericValue genericValue : partyRelationshipList) {
+ String partyIdFrom = (String)genericValue.get("partyIdFrom");
+ if (partyIdFrom.equals(groupPartyId)) {
+ return 0;
+ }
+ if (0 == checkConditionPartyHierarchy(delegator, nowTimestamp, groupPartyId, partyIdFrom)) {
+ return 0;
+ }
+ }
+
+ return 1;
+ }
+
/**
* Calculates the purchase price of a product
*/
Re: svn commit: r922177 - in /ofbiz/trunk/applications: order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
product/src/org/ofbiz/product/price/PriceServices.java
Posted by Adam Heath <do...@brainfood.com>.
jleroux@apache.org wrote:
> Author: jleroux
> Date: Fri Mar 12 08:27:42 2010
> New Revision: 922177
>
> URL: http://svn.apache.org/viewvc?rev=922177&view=rev
> Log:
> A slightly modified patch from Geir Ove Grønmo "Calculation of promotions and price rules should support multi-level GROUP_ROLLUP" (https://issues.apache.org/jira/browse/OFBIZ-3440) - OFBIZ-3440
>
> The calculation of product prices given promotion and price rules do not currently take multi-level GROUP_ROLLUP party relations into account.
> The calculation of price rules consider two levels of GROUP_ROLLUP only, while the calculation of promotions take just a single level of GROUP_ROLLUP into account.
> The attached patch will calculate price rules and promotions for GROUP_ROLLUPs for an arbitrary number of GROUP_ROLLUPs. This is essential in the situation where there are hierarchies of parties.
>
> Modified:
> ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
> ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java
>
> + private static int checkConditionPartyHierarchy(Delegator delegator, Timestamp nowTimestamp, String groupPartyId, String partyId) throws GenericEntityException{
> + List<GenericValue> partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"));
> + partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true);
> + for (GenericValue genericValue : partyRelationshipList) {
> + String partyIdFrom = (String)genericValue.get("partyIdFrom");
> + if (partyIdFrom.equals(groupPartyId)) {
> + return 0;
> + }
> + if (0 == checkConditionPartyHierarchy(delegator, nowTimestamp, groupPartyId, partyIdFrom)) {
> + return 0;
> + }
> + }
> +
> + return 1;
> + }
> +
It would be nice to have this method in the party component. My guy
wants to say there might already been a method to do this.