Project:
View Issue Details[ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
ID | ||||||||||||
0050295 | ||||||||||||
Type | Category | Severity | Reproducibility | Date Submitted | Last Update | |||||||
feature request | [Modules] Loyalty Programs | major | N/A | 2022-09-20 21:59 | 2022-09-20 21:59 | |||||||
Reporter | axelmercado | View Status | public | |||||||||
Assigned To | Retail | |||||||||||
Priority | high | Resolution | open | Fixed in Version | ||||||||
Status | new | Fix in branch | Fixed in SCM revision | |||||||||
Projection | none | ETA | none | Target Version | ||||||||
OS | Any | Database | Any | Java version | ||||||||
OS Version | Database version | Ant version | ||||||||||
Product Version | SCM revision | |||||||||||
Regression date | ||||||||||||
Regression introduced by commit | ||||||||||||
Regression level | ||||||||||||
Review Assigned To | ||||||||||||
Regression introduced in release | ||||||||||||
Summary | 0050295: Loyalty: point fields with decimals | |||||||||||
Description | Patch proposed by the partner Practics: Our client needs to have the points with decimals, at the end his calculation rules are based on a % of the amount of the sale. For example, 1% points on a sale of 50 euros --> 0.5 points. The case is that by the design of loyalty the fields are integers in ad_column We have generated a patch that affects several modules to make the change from Long to BigDecimal. We would like you to analyze it and look to contribute. We think that for any customer it is valid at the end to do the management with decimals should not be a problem in any customer. One point that you have to take into account is that if other modules that you have set a Long you will have to adjust them. | |||||||||||
Steps To Reproduce | N/A | |||||||||||
Proposed Solution | Attached patch | |||||||||||
Tags | No tags attached. | |||||||||||
Attached Files | puntosConDecimales.diff [^] (36,510 bytes) 2022-09-20 21:59 [Show Content] [Hide Content]diff -ru Original/org.openbravo.loyalty.burn.expired/src/org/openbravo/loyalty/burn/expired/process/ExpirePointsUtils.java Modificado/org.openbravo.loyalty.burn.expired/src/org/openbravo/loyalty/burn/expired/process/ExpirePointsUtils.java --- a/modules/org.openbravo.loyalty.burn.expired/src/org/openbravo/loyalty/burn/expired/process/ExpirePointsUtils.java +++ b/modules/org.openbravo.loyalty.burn.expired/src/org/openbravo/loyalty/burn/expired/process/ExpirePointsUtils.java @@ -9,6 +9,7 @@ package org.openbravo.loyalty.burn.expired.process; +import java.math.BigDecimal; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -38,9 +39,9 @@ final boolean isManual) { // Data final List<OBLPEarnedPoints> expiredPoints = getExpiredPoints(selectedEarnedPoints, ruleConfig); - final Long totalPoints = BurnRunUtils.getTotalPoints(expiredPoints); + final BigDecimal totalPoints = BurnRunUtils.getTotalPoints(expiredPoints); // Logic - if (totalPoints == 0l) { + if (totalPoints.compareTo(BigDecimal.ZERO) == 0) { return; } final OBLPSubscription subscription = selectedEarnedPoints.get(0).getOblpSubscription(); diff -ru Original/org.openbravo.loyalty.burn.giftcertificate/src/org/openbravo/loyalty/burn/giftcertificate/process/GenerateGiftCertificateUtils.java Modificado/org.openbravo.loyalty.burn.giftcertificate/src/org/openbravo/loyalty/burn/giftcertificate/process/GenerateGiftCertificateUtils.java --- a/modules/org.openbravo.loyalty.burn.giftcertificate/src/org/openbravo/loyalty/burn/giftcertificate/process/GenerateGiftCertificateUtils.java +++ b/modules/org.openbravo.loyalty.burn.giftcertificate/src/org/openbravo/loyalty/burn/giftcertificate/process/GenerateGiftCertificateUtils.java @@ -66,8 +66,8 @@ BigDecimal customizedAmount) { // Validations Check.isFalse(selectedEarnedPoints.isEmpty(), "OBLPGC_NoLinesSelected"); - final Long totalPoints = BurnRunUtils.getTotalPoints(selectedEarnedPoints); - Check.isTrue(totalPoints >= ruleConfig.getMinpoints(), + final BigDecimal totalPoints = BurnRunUtils.getTotalPoints(selectedEarnedPoints); + Check.isTrue(totalPoints.compareTo(ruleConfig.getMinpoints()) >= 0, getMinPointsErrorMessage(ruleConfig, totalPoints)); // Data final OBLPSubscription subscription = selectedEarnedPoints.get(0).getOblpSubscription(); @@ -106,7 +106,7 @@ OBDal.getInstance().save(payment); OBDal.getInstance().save(giftCardInst); - final Long burnedPoints = BurnRunUtils.getBurnedPoints(amount, conversion); + final BigDecimal burnedPoints = BurnRunUtils.getBurnedPoints(amount, conversion); burnPoints(programBurnRule, subscription, conversion, burnedPoints, selectedEarnedPoints, giftCardInst, ruleConfig.getOblpBurnRunRule(), isManual); return giftCardInst; @@ -131,7 +131,7 @@ private static void burnPoints(final OBLPProgramBurnRule programBurnRule, final OBLPSubscription subscription, final OBLPConversion conversion, - final Long totalBurnedPoints, final List<OBLPEarnedPoints> selectedEarnedPoints, + final BigDecimal totalBurnedPoints, final List<OBLPEarnedPoints> selectedEarnedPoints, final GiftCardInst giftCardInst, final OBLPBurnRunRule oblpBurnRunRule, final boolean isManual) { final OBLPBurnedPoints burnedPoints = BurnRunUtils.burnPoints(programBurnRule, subscription, @@ -141,7 +141,7 @@ } private static String getMinPointsErrorMessage(final OBLPGCGiftCertificateConfig ruleConfig, - final Long totalPoints) { + final BigDecimal totalPoints) { final Map<String, String> params = new HashMap<>(); params.put("totalPoints", totalPoints.toString()); params.put("minPoints", ruleConfig.getMinpoints().toString()); diff -ru Original/org.openbravo.loyalty.burn.giftcertificate/src-db/database/sourcedata/AD_COLUMN.xml Modificado/org.openbravo.loyalty.burn.giftcertificate/src-db/database/sourcedata/AD_COLUMN.xml --- a/modules/org.openbravo.loyalty.burn.giftcertificate/src-db/database/sourcedata/AD_COLUMN.xml +++ b/modules/org.openbravo.loyalty.burn.giftcertificate/src-db/database/sourcedata/AD_COLUMN.xml @@ -607,8 +607,8 @@ If the subscriber has less than the given value, no gift certificate will be created.]]></HELP> <!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <COLUMNNAME><![CDATA[Minpoints]]></COLUMNNAME> <!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <AD_TABLE_ID><![CDATA[DBBEEC6B8B384933A03F9020F13E835E]]></AD_TABLE_ID> -<!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> -<!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <FIELDLENGTH><![CDATA[2]]></FIELDLENGTH> +<!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> +<!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH> <!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <ISKEY><![CDATA[N]]></ISKEY> <!--F2C0AA179F5C480BA6FC78CF76D79ACC--> <ISPARENT><![CDATA[N]]></ISPARENT> diff -ru Original/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/EarnedPointsEventHandler.java Modificado/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/EarnedPointsEventHandler.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/EarnedPointsEventHandler.java +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/EarnedPointsEventHandler.java @@ -9,6 +9,8 @@ package org.openbravo.loyalty.programs.eventhandler; +import java.math.BigDecimal; + import javax.enterprise.event.Observes; import org.openbravo.base.model.Entity; @@ -37,7 +39,7 @@ OBLPEarnedPoints ep = (OBLPEarnedPoints) event.getTargetInstance(); ep.getOblpSubscription() - .setTotalpoints(ep.getOblpSubscription().getTotalpoints() + ep.getAvailablepoints()); + .setTotalpoints(ep.getOblpSubscription().getTotalpoints().add(ep.getAvailablepoints())); } public void onUpdate(@Observes EntityUpdateEvent event) { @@ -49,13 +51,14 @@ final Entity earnedPointsEntity = ModelProvider.getInstance() .getEntity(OBLPEarnedPoints.ENTITY_NAME); - final Long oldPoints = (Long) event.getPreviousState( + final BigDecimal oldPoints = (BigDecimal) event.getPreviousState( earnedPointsEntity.getProperty(OBLPEarnedPoints.PROPERTY_AVAILABLEPOINTS)); - final Long newPoints = (Long) event + final BigDecimal newPoints = (BigDecimal) event .getCurrentState(earnedPointsEntity.getProperty(OBLPEarnedPoints.PROPERTY_AVAILABLEPOINTS)); if (!oldPoints.equals(newPoints)) { ep.getOblpSubscription() - .setTotalpoints(ep.getOblpSubscription().getTotalpoints() + (newPoints - oldPoints)); + .setTotalpoints( + ep.getOblpSubscription().getTotalpoints().add(newPoints.subtract(oldPoints))); } } @@ -67,6 +70,7 @@ OBLPEarnedPoints ep = (OBLPEarnedPoints) event.getTargetInstance(); ep.getOblpSubscription() - .setTotalpoints(ep.getOblpSubscription().getTotalpoints() - ep.getAvailablepoints()); + .setTotalpoints( + ep.getOblpSubscription().getTotalpoints().subtract(ep.getAvailablepoints())); } } diff -ru Original/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/PointsDetailEventHandler.java Modificado/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/PointsDetailEventHandler.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/PointsDetailEventHandler.java +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/PointsDetailEventHandler.java @@ -9,6 +9,8 @@ package org.openbravo.loyalty.programs.eventhandler; +import java.math.BigDecimal; + import javax.enterprise.event.Observes; import org.openbravo.base.model.Entity; @@ -29,7 +31,7 @@ return entities; } - protected void setPointsAndUpdateSubscription(OBLPPointsDetail pointsDetail, Long points) { + protected void setPointsAndUpdateSubscription(OBLPPointsDetail pointsDetail, BigDecimal points) { pointsDetail.getOblpEarnedPoints().setAvailablepoints(points); } @@ -41,7 +43,7 @@ OBLPPointsDetail pd = (OBLPPointsDetail) event.getTargetInstance(); setPointsAndUpdateSubscription(pd, - pd.getOblpEarnedPoints().getAvailablepoints() - pd.getPoints()); + pd.getOblpEarnedPoints().getAvailablepoints().subtract(pd.getPoints())); } @@ -54,14 +56,14 @@ final Entity pointsDetailEntity = ModelProvider.getInstance() .getEntity(OBLPPointsDetail.ENTITY_NAME); - final Long oldPoints = (Long) event + final BigDecimal oldPoints = (BigDecimal) event .getPreviousState(pointsDetailEntity.getProperty(OBLPPointsDetail.PROPERTY_POINTS)); - final Long newPoints = (Long) event + final BigDecimal newPoints = (BigDecimal) event .getCurrentState(pointsDetailEntity.getProperty(OBLPPointsDetail.PROPERTY_POINTS)); if (oldPoints != newPoints) { setPointsAndUpdateSubscription(pd, - pd.getOblpEarnedPoints().getAvailablepoints() - (newPoints - oldPoints)); + pd.getOblpEarnedPoints().getAvailablepoints().subtract(newPoints.subtract(oldPoints))); } } @@ -74,6 +76,6 @@ OBLPPointsDetail pd = (OBLPPointsDetail) event.getTargetInstance(); setPointsAndUpdateSubscription(pd, - pd.getOblpEarnedPoints().getAvailablepoints() + pd.getPoints()); + pd.getOblpEarnedPoints().getAvailablepoints().add(pd.getPoints())); } } diff -ru Original/SubscriptionCategoryPromotionRuleEventHandler.java Modificado/SubscriptionCategoryPromotionRuleEventHandler.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/SubscriptionCategoryPromotionRuleEventHandler.java 2022-03-01 14:28:35.000000000 +0100 +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/eventhandler/SubscriptionCategoryPromotionRuleEventHandler.java 2022-09-14 18:22:55.617047000 +0200 @@ -10,6 +10,8 @@ package org.openbravo.loyalty.programs.eventhandler; +import java.math.BigDecimal; + import javax.enterprise.event.Observes; import org.apache.logging.log4j.LogManager; @@ -56,7 +58,7 @@ subscriptionEntity.getProperty(OBLPSubscription.PROPERTY_TOTALPOINTS)) != event .getPreviousState( subscriptionEntity.getProperty(OBLPSubscription.PROPERTY_TOTALPOINTS))) { - Long totalPoints = (Long) event + BigDecimal totalPoints = (BigDecimal) event .getCurrentState(subscriptionEntity.getProperty(OBLPSubscription.PROPERTY_TOTALPOINTS)); OBLPCategory category = getCategoryBasedOnRulePromotionPoints(totalPoints); if (category != null) { @@ -74,7 +76,7 @@ } } - private OBLPCategory getCategoryBasedOnRulePromotionPoints(Long totalPoints) { + private OBLPCategory getCategoryBasedOnRulePromotionPoints(BigDecimal totalPoints) { //@formatter:off String query = "" + "select cat as category" diff -ru Original/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/GenerateBurnRun.java Modificado/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/GenerateBurnRun.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/GenerateBurnRun.java +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/GenerateBurnRun.java @@ -104,14 +104,15 @@ simulation.setOblpBurnRun(burnRunRule.getOblpBurnRun()); simulation.setSubscription(subscription); simulation.setOblpBurnRunRule(burnRunRule); - simulation.setBurnedpoints(0l); + simulation.setBurnedpoints(BigDecimal.ZERO); OBDal.getInstance().save(simulation); - Long totalAvailableInSimulation = 0l; + BigDecimal totalAvailableInSimulation = BigDecimal.ZERO; for (final OBLPEarnedPoints pointsRecord : getEarnedPoints(burnRunRule, subscription)) { - long availablePoints = pointsRecord.getAvailablepoints() - - simulationPointsCarry.getConsumedPointsInPreviousRulesSimulation(pointsRecord.getId()); - totalAvailableInSimulation += availablePoints; - if (availablePoints > 0) { + BigDecimal availablePoints = pointsRecord.getAvailablepoints() + .subtract(simulationPointsCarry + .getConsumedPointsInPreviousRulesSimulation(pointsRecord.getId())); + totalAvailableInSimulation = totalAvailableInSimulation.add(availablePoints); + if (availablePoints.compareTo(BigDecimal.ZERO) > 0) { final OBLPBurnRunSimTrx simulatedTrx = OBProvider.getInstance() .get(OBLPBurnRunSimTrx.class); simulatedTrx.setClient(subscription.getOblpProgram().getClient()); @@ -125,7 +126,7 @@ } } final BigDecimal amount = BurnRunUtils.getAmount(conversion, totalAvailableInSimulation); - final Long totalBurnedPoints = BurnRunUtils.getBurnedPoints(amount, conversion); + final BigDecimal totalBurnedPoints = BurnRunUtils.getBurnedPoints(amount, conversion); simulation.setBurnedpoints(totalBurnedPoints); OBDal.getInstance().save(simulation); return simulation; diff -ru Original/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionPromoteCategoryEARNRuleHandler.java Modificado/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionPromoteCategoryEARNRuleHandler.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionPromoteCategoryEARNRuleHandler.java +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionPromoteCategoryEARNRuleHandler.java @@ -9,6 +9,7 @@ package org.openbravo.loyalty.programs.process; +import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -60,8 +61,9 @@ final String newCategoryId = ((OBLPCategory) event .getCurrentState(subscriptionEntity.getProperty(OBLPSubscription.PROPERTY_OBLPCATEGORY))) .getId(); - Long points; - if ((points = getPromoteCategoryPoints(subscription, newCategoryId)) > 0l) { + BigDecimal points; + if ((points = getPromoteCategoryPoints(subscription, newCategoryId)) + .compareTo(BigDecimal.ZERO) > 0) { addPoints(event, subscription, points); } } @@ -76,7 +78,8 @@ .getLevel()) < 0; } - private Long getPromoteCategoryPoints(OBLPSubscription subscription, final String newCategoryId) { + private BigDecimal getPromoteCategoryPoints(OBLPSubscription subscription, + final String newCategoryId) { //@formatter:off String query = "" + "select earn.id as id, earn.promotionPoints as promotionPoints" @@ -102,13 +105,13 @@ Tuple result = promotionQuery.uniqueResult(); if (result != null) { earnRuleId = (String) result.get("id"); - return (Long) result.get("promotionPoints"); + return (BigDecimal) result.get("promotionPoints"); } - return 0l; + return BigDecimal.ZERO; } private OBLPEarnedPoints addPoints(EntityUpdateEvent event, OBLPSubscription subscription, - Long points) { + BigDecimal points) { OBLPEarnedPoints newPoints = OBProvider.getInstance().get(OBLPEarnedPoints.class); newPoints.setNewOBObject(true); newPoints.setClient(subscription.getClient()); diff -ru Original/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionWelcomePointsEARNRuleHandler.java Modificado/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionWelcomePointsEARNRuleHandler.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionWelcomePointsEARNRuleHandler.java +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/process/SubscriptionWelcomePointsEARNRuleHandler.java @@ -9,6 +9,7 @@ package org.openbravo.loyalty.programs.process; +import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -55,12 +56,12 @@ } try { OBContext.setAdminMode(false); - Long points; + BigDecimal points; OBLPSubscription subscription = (OBLPSubscription) event.getTargetInstance(); if (!subscription.getOblpStatus().isCanearnpoints()) { return; } - if ((points = getWelcomePoints(subscription)) > 0l) { + if ((points = getWelcomePoints(subscription)).compareTo(BigDecimal.ZERO) > 0) { addPoints(event, subscription, points); } } catch (Exception e) { @@ -70,7 +71,7 @@ } } - private Long getWelcomePoints(OBLPSubscription subscription) { + private BigDecimal getWelcomePoints(OBLPSubscription subscription) { //@formatter:off String query = "" + "select earn.id as id, earn.welcomePoints as welcomePoints" @@ -96,13 +97,13 @@ Tuple result = welcomeQuery.uniqueResult(); if (result != null) { earnRuleId = (String) result.get("id"); - return (Long) result.get("welcomePoints"); + return (BigDecimal) result.get("welcomePoints"); } - return 0l; + return BigDecimal.ZERO; } private OBLPEarnedPoints addPoints(EntityNewEvent event, OBLPSubscription subscription, - Long points) { + BigDecimal points) { OBLPEarnedPoints newPoints = OBProvider.getInstance().get(OBLPEarnedPoints.class); newPoints.setNewOBObject(true); newPoints.setClient(subscription.getClient()); diff -ru Original/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/BurnRunUtils.java Modificado/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/BurnRunUtils.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/BurnRunUtils.java +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/BurnRunUtils.java @@ -212,28 +212,29 @@ /** * Retrieves the available number of points for a list of earned points */ - public static Long getTotalPoints(final List<OBLPEarnedPoints> earnedPoints) { - return earnedPoints.stream() // - .mapToLong(OBLPEarnedPoints::getAvailablepoints) // - .sum(); + public static BigDecimal getTotalPoints(final List<OBLPEarnedPoints> earnedPoints) { + return earnedPoints.stream()// + .map(OBLPEarnedPoints::getAvailablepoints) // + .reduce(BigDecimal.ZERO, BigDecimal::add); } /** * Calculates the price amount of given number of points using the given conversion */ - public static BigDecimal getAmount(final OBLPConversion conversion, final Long totalPoints) { + public static BigDecimal getAmount(final OBLPConversion conversion, + final BigDecimal totalPoints) { return conversion.getNetUnitPrice() - .multiply(new BigDecimal(totalPoints)) + .multiply(totalPoints) .setScale(conversion.getCurrency().getStandardPrecision().intValue(), RoundingMode.HALF_UP); } /** * Calculates the number of burned points for a given amount and conversion */ - public static Long getBurnedPoints(final BigDecimal amount, final OBLPConversion conversion) { + public static BigDecimal getBurnedPoints(final BigDecimal amount, + final OBLPConversion conversion) { return amount.divide(conversion.getNetUnitPrice(), RoundingMode.HALF_UP) - .setScale(0, RoundingMode.HALF_UP) - .longValue(); + .setScale(conversion.getCurrency().getStandardPrecision().intValue(), RoundingMode.HALF_UP); } /** @@ -241,7 +242,7 @@ */ public static OBLPBurnedPoints burnPoints(final OBLPProgramBurnRule programBurnRule, final OBLPSubscription subscription, final OBLPConversion conversion, - final Long totalBurnedPoints, final List<OBLPEarnedPoints> selectedEarnedPoints, + final BigDecimal totalBurnedPoints, final List<OBLPEarnedPoints> selectedEarnedPoints, final OBLPBurnRunRule oblpBurnRunRule, final boolean isManual) { final OBLPBurnedPoints burnedPoints = OBProvider.getInstance().get(OBLPBurnedPoints.class); burnedPoints.setNewOBObject(true); @@ -267,23 +268,23 @@ } private static List<OBLPPointsDetail> addBurningDetails( - final List<OBLPEarnedPoints> selectedEarnedPoints, final Long totalBurnedPoints, + final List<OBLPEarnedPoints> selectedEarnedPoints, final BigDecimal totalBurnedPoints, final OBLPBurnedPoints burnedPoints) { final List<OBLPPointsDetail> result = new ArrayList<>(); - Long remainingPoints = totalBurnedPoints; + BigDecimal remainingPoints = totalBurnedPoints; final List<OBLPEarnedPoints> sortedEarnedPoints = sortedEarnedPoints(selectedEarnedPoints); for (final OBLPEarnedPoints earnedPoints : sortedEarnedPoints) { - if (remainingPoints == 0) { + if (remainingPoints.compareTo(BigDecimal.ZERO) == 0) { break; } - Long pointsToBurn; - if (earnedPoints.getAvailablepoints() < remainingPoints) { + BigDecimal pointsToBurn; + if (earnedPoints.getAvailablepoints().compareTo(remainingPoints) < 0) { pointsToBurn = earnedPoints.getAvailablepoints(); } else { pointsToBurn = remainingPoints; } result.add(getNewPointsDetail(earnedPoints, burnedPoints, pointsToBurn)); - remainingPoints -= pointsToBurn; + remainingPoints = remainingPoints.subtract(pointsToBurn); } return result; } @@ -296,7 +297,7 @@ } private static OBLPPointsDetail getNewPointsDetail(final OBLPEarnedPoints earnedPoints, - final OBLPBurnedPoints burnedPoints, final Long pointsToBurn) { + final OBLPBurnedPoints burnedPoints, final BigDecimal pointsToBurn) { final OBLPPointsDetail result = OBProvider.getInstance().get(OBLPPointsDetail.class); result.setClient(burnedPoints.getClient()); result.setOrganization(burnedPoints.getOrganization()); diff -ru Original/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/SimulationPointsCarry.java Modificado/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/SimulationPointsCarry.java --- a/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/SimulationPointsCarry.java +++ b/modules/org.openbravo.loyalty.programs/src/org/openbravo/loyalty/programs/utils/SimulationPointsCarry.java @@ -9,25 +9,26 @@ package org.openbravo.loyalty.programs.utils; +import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; public class SimulationPointsCarry { - private Map<String, Long> pointsConsumedInSimulation; + private Map<String, BigDecimal> pointsConsumedInSimulation; public SimulationPointsCarry() { - this.pointsConsumedInSimulation = new HashMap<String, Long>(); + this.pointsConsumedInSimulation = new HashMap<String, BigDecimal>(); } - public void addConsumedPointsInSimulation(final String earnPointsId, final Long points) { + public void addConsumedPointsInSimulation(final String earnPointsId, final BigDecimal points) { pointsConsumedInSimulation.put(earnPointsId, - getConsumedPointsInPreviousRulesSimulation(earnPointsId) + points); + getConsumedPointsInPreviousRulesSimulation(earnPointsId).add(points)); } - public Long getConsumedPointsInPreviousRulesSimulation(final String earnPointsId) { - Long consumedPoints = pointsConsumedInSimulation.get(earnPointsId); - return consumedPoints != null ? consumedPoints : 0l; + public BigDecimal getConsumedPointsInPreviousRulesSimulation(final String earnPointsId) { + BigDecimal consumedPoints = pointsConsumedInSimulation.get(earnPointsId); + return consumedPoints != null ? consumedPoints : BigDecimal.ZERO; } } diff -ru Original/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml Modificado/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml --- a/modules/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml +++ b/modules/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml @@ -2905,7 +2905,7 @@ <!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <HELP><![CDATA[Total points of Subscription or the Earn/Burn transactions]]></HELP> <!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <COLUMNNAME><![CDATA[Totalpoints]]></COLUMNNAME> <!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <AD_TABLE_ID><![CDATA[98A5C190D7334D22946487732C008FFF]]></AD_TABLE_ID> -<!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <FIELDLENGTH><![CDATA[12]]></FIELDLENGTH> <!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--3EBB3095ADB84EA48AB2E910E0C1CAD5--> <ISKEY><![CDATA[N]]></ISKEY> @@ -6646,8 +6646,8 @@ <!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <HELP><![CDATA[Points that the Customer has]]></HELP> <!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <COLUMNNAME><![CDATA[Availablepoints]]></COLUMNNAME> <!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <AD_TABLE_ID><![CDATA[5F5AFC6497694643A7426CF2D2489691]]></AD_TABLE_ID> -<!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> -<!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <FIELDLENGTH><![CDATA[2]]></FIELDLENGTH> +<!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> +<!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH> <!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <ISKEY><![CDATA[N]]></ISKEY> <!--9136FBBF1BA2491C9CED2E12F8B94A3D--> <ISPARENT><![CDATA[N]]></ISPARENT> @@ -9067,7 +9067,7 @@ <!--C4FF252000E442C9A4E00310A584B327--> <HELP><![CDATA[Points burned from the related Earned Points transaction]]></HELP> <!--C4FF252000E442C9A4E00310A584B327--> <COLUMNNAME><![CDATA[Points]]></COLUMNNAME> <!--C4FF252000E442C9A4E00310A584B327--> <AD_TABLE_ID><![CDATA[5225F9F0781A4BC7BB491AC2B61E64F7]]></AD_TABLE_ID> -<!--C4FF252000E442C9A4E00310A584B327--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--C4FF252000E442C9A4E00310A584B327--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--C4FF252000E442C9A4E00310A584B327--> <FIELDLENGTH><![CDATA[12]]></FIELDLENGTH> <!--C4FF252000E442C9A4E00310A584B327--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--C4FF252000E442C9A4E00310A584B327--> <ISKEY><![CDATA[N]]></ISKEY> @@ -9265,7 +9265,7 @@ <!--C9B524362ABE4625B4BFA66C42247BE5--> <HELP><![CDATA[Points that the Customer has]]></HELP> <!--C9B524362ABE4625B4BFA66C42247BE5--> <COLUMNNAME><![CDATA[Availablepoints]]></COLUMNNAME> <!--C9B524362ABE4625B4BFA66C42247BE5--> <AD_TABLE_ID><![CDATA[C765D009CF80400186BD57FB494A2DCB]]></AD_TABLE_ID> -<!--C9B524362ABE4625B4BFA66C42247BE5--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--C9B524362ABE4625B4BFA66C42247BE5--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--C9B524362ABE4625B4BFA66C42247BE5--> <FIELDLENGTH><![CDATA[12]]></FIELDLENGTH> <!--C9B524362ABE4625B4BFA66C42247BE5--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--C9B524362ABE4625B4BFA66C42247BE5--> <ISKEY><![CDATA[N]]></ISKEY> @@ -10342,8 +10342,8 @@ <!--DC6C071C7D5044B49522007350604A26--> <HELP><![CDATA[Points that Have Been Burned]]></HELP> <!--DC6C071C7D5044B49522007350604A26--> <COLUMNNAME><![CDATA[Burnedpoints]]></COLUMNNAME> <!--DC6C071C7D5044B49522007350604A26--> <AD_TABLE_ID><![CDATA[DA3021101A754086A303805828AF3C19]]></AD_TABLE_ID> -<!--DC6C071C7D5044B49522007350604A26--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> -<!--DC6C071C7D5044B49522007350604A26--> <FIELDLENGTH><![CDATA[2]]></FIELDLENGTH> +<!--DC6C071C7D5044B49522007350604A26--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> +<!--DC6C071C7D5044B49522007350604A26--> <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH> <!--DC6C071C7D5044B49522007350604A26--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--DC6C071C7D5044B49522007350604A26--> <ISKEY><![CDATA[N]]></ISKEY> <!--DC6C071C7D5044B49522007350604A26--> <ISPARENT><![CDATA[N]]></ISPARENT> @@ -10422,8 +10422,8 @@ <!--DD2D0AC0F8D94353863FAE904E829390--> <HELP><![CDATA[Total points of Subscription or the Earn/Burn transactions]]></HELP> <!--DD2D0AC0F8D94353863FAE904E829390--> <COLUMNNAME><![CDATA[Totalpoints]]></COLUMNNAME> <!--DD2D0AC0F8D94353863FAE904E829390--> <AD_TABLE_ID><![CDATA[5F5AFC6497694643A7426CF2D2489691]]></AD_TABLE_ID> -<!--DD2D0AC0F8D94353863FAE904E829390--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> -<!--DD2D0AC0F8D94353863FAE904E829390--> <FIELDLENGTH><![CDATA[2]]></FIELDLENGTH> +<!--DD2D0AC0F8D94353863FAE904E829390--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> +<!--DD2D0AC0F8D94353863FAE904E829390--> <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH> <!--DD2D0AC0F8D94353863FAE904E829390--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--DD2D0AC0F8D94353863FAE904E829390--> <ISKEY><![CDATA[N]]></ISKEY> <!--DD2D0AC0F8D94353863FAE904E829390--> <ISPARENT><![CDATA[N]]></ISPARENT> @@ -11010,7 +11010,7 @@ <!--E9F6E707468942589792E08330AE0B9D--> <HELP><![CDATA[Total points of Subscription or the Earn/Burn transactions]]></HELP> <!--E9F6E707468942589792E08330AE0B9D--> <COLUMNNAME><![CDATA[Totalpoints]]></COLUMNNAME> <!--E9F6E707468942589792E08330AE0B9D--> <AD_TABLE_ID><![CDATA[5176810700AD4846ADFD7E820E668B79]]></AD_TABLE_ID> -<!--E9F6E707468942589792E08330AE0B9D--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--E9F6E707468942589792E08330AE0B9D--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--E9F6E707468942589792E08330AE0B9D--> <FIELDLENGTH><![CDATA[12]]></FIELDLENGTH> <!--E9F6E707468942589792E08330AE0B9D--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--E9F6E707468942589792E08330AE0B9D--> <ISKEY><![CDATA[N]]></ISKEY> @@ -11247,7 +11247,7 @@ <!--F0900B06B7644D09809D975D3138A7BD--> <HELP><![CDATA[Total points of Subscription or the Earn/Burn transactions]]></HELP> <!--F0900B06B7644D09809D975D3138A7BD--> <COLUMNNAME><![CDATA[Totalpoints]]></COLUMNNAME> <!--F0900B06B7644D09809D975D3138A7BD--> <AD_TABLE_ID><![CDATA[C765D009CF80400186BD57FB494A2DCB]]></AD_TABLE_ID> -<!--F0900B06B7644D09809D975D3138A7BD--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--F0900B06B7644D09809D975D3138A7BD--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--F0900B06B7644D09809D975D3138A7BD--> <FIELDLENGTH><![CDATA[12]]></FIELDLENGTH> <!--F0900B06B7644D09809D975D3138A7BD--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--F0900B06B7644D09809D975D3138A7BD--> <ISKEY><![CDATA[N]]></ISKEY> diff -ru Original/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml Modificado/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml --- a/modules/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml +++ b/modules/org.openbravo.loyalty.programs/src-db/database/sourcedata/AD_COLUMN.xml @@ -1398,7 +1398,7 @@ <!--1B358E66BFDA472693364C405EBB9BF2--> <HELP><![CDATA[Used when Promotion EARN Rule is chosen to determine the amount of points assigned when the category is reached. It just applies when comming from a lower level category. Downgrades are not being cosidered.]]></HELP> <!--1B358E66BFDA472693364C405EBB9BF2--> <COLUMNNAME><![CDATA[PromotionPoints]]></COLUMNNAME> <!--1B358E66BFDA472693364C405EBB9BF2--> <AD_TABLE_ID><![CDATA[18EBF8148B95436395934BF38DC04076]]></AD_TABLE_ID> -<!--1B358E66BFDA472693364C405EBB9BF2--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--1B358E66BFDA472693364C405EBB9BF2--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--1B358E66BFDA472693364C405EBB9BF2--> <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH> <!--1B358E66BFDA472693364C405EBB9BF2--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--1B358E66BFDA472693364C405EBB9BF2--> <ISKEY><![CDATA[N]]></ISKEY> @@ -4055,7 +4055,7 @@ <!--529418B8B40C421DBAD2C5C1CFDCC09E--> <HELP><![CDATA[Used when Welcome EARN Rule is chosen to determine the amount of points assigned when first subscribed.]]></HELP> <!--529418B8B40C421DBAD2C5C1CFDCC09E--> <COLUMNNAME><![CDATA[WelcomePoints]]></COLUMNNAME> <!--529418B8B40C421DBAD2C5C1CFDCC09E--> <AD_TABLE_ID><![CDATA[18EBF8148B95436395934BF38DC04076]]></AD_TABLE_ID> -<!--529418B8B40C421DBAD2C5C1CFDCC09E--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--529418B8B40C421DBAD2C5C1CFDCC09E--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--529418B8B40C421DBAD2C5C1CFDCC09E--> <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH> <!--529418B8B40C421DBAD2C5C1CFDCC09E--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--529418B8B40C421DBAD2C5C1CFDCC09E--> <ISKEY><![CDATA[N]]></ISKEY> @@ -11328,7 +11328,7 @@ <!--F192220AD100428AB04E0A10D07B90A3--> <HELP><![CDATA[Used when Promotion EARN Rule is chosen to determine the amount of points assigned when the category is reached. It just applies when comming from a lower level category. Downgrades are not being cosidered.]]></HELP> <!--F192220AD100428AB04E0A10D07B90A3--> <COLUMNNAME><![CDATA[PromotionPoints]]></COLUMNNAME> <!--F192220AD100428AB04E0A10D07B90A3--> <AD_TABLE_ID><![CDATA[AEBD27F1AC1F4F66885FEA42C6D57041]]></AD_TABLE_ID> -<!--F192220AD100428AB04E0A10D07B90A3--> <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID> +<!--F192220AD100428AB04E0A10D07B90A3--> <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID> <!--F192220AD100428AB04E0A10D07B90A3--> <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH> <!--F192220AD100428AB04E0A10D07B90A3--> <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE> <!--F192220AD100428AB04E0A10D07B90A3--> <ISKEY><![CDATA[N]]></ISKEY> diff -ru Original/org.openbravo.retail.loyalty.burn.giftcertificate/src/org/openbravo/retail/loyalty/burn/giftcertificate/process/CancelGiftCertificateAmount.java Modificado/org.openbravo.retail.loyalty.burn.giftcertificate/src/org/openbravo/retail/loyalty/burn/giftcertificate/process/CancelGiftCertificateAmount.java --- a/modules/org.openbravo.retail.loyalty.burn.giftcertificate/src/org/openbravo/retail/loyalty/burn/giftcertificate/process/CancelGiftCertificateAmount.java +++ b/modules/org.openbravo.retail.loyalty.burn.giftcertificate/src/org/openbravo/retail/loyalty/burn/giftcertificate/process/CancelGiftCertificateAmount.java @@ -74,7 +74,7 @@ BigDecimal amount = giftCardInst.getAmount(); BigDecimal usedConversionPrice = new BigDecimal(jsonsent.getString("conversionPrice")); - Long points = amount.divide(usedConversionPrice, RoundingMode.HALF_UP).longValueExact(); + BigDecimal points = amount.divide(usedConversionPrice, RoundingMode.HALF_UP); OBLPEarnedPoints restoredPoints = OBProvider.getInstance().get(OBLPEarnedPoints.class); restoredPoints.setNewOBObject(true); diff -ru Original/org.openbravo.retail.loyalty.programs/src/org/openbravo/retail/loyalty/programs/process/LoyaltyEarnedPointsLoader.java Modificado/org.openbravo.retail.loyalty.programs/src/org/openbravo/retail/loyalty/programs/process/LoyaltyEarnedPointsLoader.java --- a/modules/org.openbravo.retail.loyalty.programs/src/org/openbravo/retail/loyalty/programs/process/LoyaltyEarnedPointsLoader.java +++ b/modules/org.openbravo.retail.loyalty.programs/src/org/openbravo/retail/loyalty/programs/process/LoyaltyEarnedPointsLoader.java @@ -9,6 +9,7 @@ package org.openbravo.retail.loyalty.programs.process; +import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -83,8 +84,8 @@ String event = jsonRecord.isNull("event") ? "Manual compensation" : jsonRecord.getString("event"); OBLPEarnRule earnRule = getManualEarnRuleOfSubscription(subscription); - long totalPoints = jsonRecord.getLong("totalPoints"); - long availablePoints = jsonRecord.getLong("availablePoints"); + BigDecimal totalPoints = new BigDecimal(jsonRecord.getString("totalPoints")); + BigDecimal availablePoints = new BigDecimal(jsonRecord.getLong("availablePoints")); String isManual = jsonRecord.getString("isManual"); JSONObject approval = new JSONObject(jsonRecord.getString("approval")); | |||||||||||
Relationships [ Relation Graph ] [ Dependency Graph ] | |
Issue History | |||
Date Modified | Username | Field | Change |
2022-09-20 21:59 | axelmercado | New Issue | |
2022-09-20 21:59 | axelmercado | Assigned To | => Retail |
2022-09-20 21:59 | axelmercado | File Added: puntosConDecimales.diff |
Copyright © 2000 - 2009 MantisBT Group |