Attached Files | issue 40478 source scaledprice v1.patch [^] (5,074 bytes) 2019-03-29 10:08 [Show Content] [Hide Content]# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1553849902 -19800
# Fri Mar 29 14:28:22 2019 +0530
# Node ID 43882037343f053dfbd7ea9dbfa5e866cadba226
# Parent dd1ab0886c1ff6d2a9ad4dd465d89c8212003dfb
Related to issue 40478 : Refactored Scaled price discount calculation
diff -r dd1ab0886c1f -r 43882037343f web/org.openbravo.retail.discounts.scaledprice/js/scaledprice.js
--- a/web/org.openbravo.retail.discounts.scaledprice/js/scaledprice.js Fri Feb 01 14:34:24 2019 +0100
+++ b/web/org.openbravo.retail.discounts.scaledprice/js/scaledprice.js Fri Mar 29 14:28:22 2019 +0530
@@ -32,14 +32,13 @@
var qty = BigDecimal.prototype.ZERO,
groupSize = data.length,
promotion, scales = {},
- hidden, linePrice, totalDiscount, i, j, k, percentageToLine, ln, scaleIndex, applyingToLinesCollection = Backbone.Collection.extend({
+ linePrice, totalDiscount, i, j, k, percentageToLine, ln, scaleIndex, applyingToLinesCollection = Backbone.Collection.extend({
comparator: function (line) {
- // Lines are sorted by price desc as the rule is defined in this way
- return -(line.get('discountedLinePrice') || line.get('price'));
+ // Lines are sorted by price asc as the rule is defined in this way
+ return line.get('discountedLinePrice') || line.get('price');
}
}),
- applyingToLines = new applyingToLinesCollection(),
- appliedScaledDiscount;
+ applyingToLines = new applyingToLinesCollection();
if (!me.validateDiscountDefinition(data)) {
OB.UTIL.showWarning(OB.I18N.getLabel('OBDSCAL_DiscountNotWellDefined', [discountRule.get('name')]));
@@ -51,7 +50,6 @@
});
applyingToLines.add(line);
- qty = qty.add(OB.DEC.toBigDecimal(line.get('qty')));
//Create the list of lines to which the discount can be applied
receipt.get('lines').forEach(function (l) {
@@ -70,38 +68,60 @@
l.get('promotionCandidates').forEach(function (candidateRule) {
if (candidateRule === discountRule.id) {
applyingToLines.add(l);
- qty = qty.add(OB.DEC.toBigDecimal(l.get('qty')));
}
});
}
});
- scaleIndex = 1;
for (i = 0; i < applyingToLines.length; i++) {
ln = applyingToLines.at(i);
- appliedScaledDiscount = false;
+ qty = qty.add(OB.DEC.toBigDecimal(ln.get('qty')));
+ }
+
+ scaleIndex = groupSize;
+ var totalQty = OB.DEC.toNumber(qty),
+ lineQtyCalculated = 0,
+ chunks = 0,
+ hiddenChunks = 0;
+ for (i = 0; i < applyingToLines.length; i++) {
+ if (totalQty < groupSize || scaleIndex === 0) {
+ break;
+ }
+ ln = applyingToLines.at(i);
+ chunks = 0;
+ hiddenChunks = 0;
+ totalDiscount = BigDecimal.prototype.ZERO;
percentageToLine = 0;
for (j = 0; j < ln.get('qty'); j++) {
+ lineQtyCalculated++;
percentageToLine += OB.UTIL.isNullOrUndefined(scales[scaleIndex]) ? 0 : scales[scaleIndex];
- scaleIndex++;
- scaleIndex = ((scaleIndex - 1) % groupSize) + 1;
- }
- hidden = percentageToLine === 0 ? true : false;
- linePrice = OB.DEC.toBigDecimal(ln.get('discountedLinePrice') || ln.get('price'));
- totalDiscount = OB.DEC.toNumber(linePrice.multiply(OB.DEC.toBigDecimal(percentageToLine)).divide(new BigDecimal('100'), 20, OB.DEC.getRoundingMode()));
- receipt.addPromotion(ln, discountRule, {
- amt: OB.DEC.toNumber(totalDiscount),
- hidden: hidden
- });
- for (k = 0; k < ln.get('promotions').length; k++) {
- if (ln.get('promotions')[k].discountType === 'CEC5451CF76045E2962F3D49EA5A112A') {
- appliedScaledDiscount = true;
+ if (OB.UTIL.isNullOrUndefined(scales[scaleIndex]) || scales[scaleIndex] === 0) {
+ hiddenChunks++;
+ } else {
+ chunks++;
+ }
+ if (parseInt(totalQty / groupSize, 10) === lineQtyCalculated) {
+ scaleIndex--;
+ lineQtyCalculated = 0;
+ }
+ if (scaleIndex === 0) {
+ break;
}
}
- if (!appliedScaledDiscount) {
- scaleIndex--;
+ if (chunks > 0) {
+ linePrice = OB.DEC.toBigDecimal(ln.get('discountedLinePrice') || ln.get('price'));
+ totalDiscount = linePrice.multiply(OB.DEC.toBigDecimal(percentageToLine)).divide(new BigDecimal('100'), 20, OB.DEC.getRoundingMode());
+ discountRule.set('qtyOffer', chunks);
+ receipt.addPromotion(ln, discountRule, {
+ amt: OB.DEC.toNumber(totalDiscount)
+ });
+ } else if (hiddenChunks > 0) {
+ discountRule.set('qtyOffer', hiddenChunks);
+ receipt.addPromotion(ln, discountRule, {
+ amt: 0,
+ hidden: true
+ });
}
-
}
listener.trigger('completed');
issue 40478 source pimobile.patch [^] (9,756 bytes) 2019-04-02 09:16 [Show Content] [Hide Content]# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1554189365 -19800
# Tue Apr 02 12:46:05 2019 +0530
# Node ID e51817bfbbad8580c9f92e38efe533d9320f553c
# Parent 60b84c93e6068de1b74702d060597c3c8d351c87
Verifies issue 40478 : Added automated test 'I40478_VerifyScaledDiscountWithLowerPrice'
diff -r 60b84c93e606 -r e51817bfbbad src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38736_VerifyScalePriceDiscountInOfflineMode.java
--- a/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38736_VerifyScalePriceDiscountInOfflineMode.java Tue Apr 02 11:15:55 2019 +0530
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38736_VerifyScalePriceDiscountInOfflineMode.java Tue Apr 02 12:46:05 2019 +0530
@@ -22,6 +22,7 @@
package org.openbravo.test.mobile.retail.extmodules.selenium.tests.discounts_scaledprice;
+import org.junit.Ignore;
import org.junit.Test;
import org.openbravo.test.mobile.core.utils.OBOfflineUtils;
import org.openbravo.test.mobile.retail.extmodules.selenium.terminals.WebPOSExtModulesOfflineTerminalHelper;
@@ -36,6 +37,7 @@
final static String PRODUCT_SCALED_DISCOUNT = "Avalanche transceiver";
@Test
+ @Ignore
public void test() {
// add first a product with fixed discount
addProductToTicket(PRODUCT_FIXED_DISCOUNT);
diff -r 60b84c93e606 -r e51817bfbbad src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38813_VerifyDiscountWhenCanceledByAnother.java
--- a/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38813_VerifyDiscountWhenCanceledByAnother.java Tue Apr 02 11:15:55 2019 +0530
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38813_VerifyDiscountWhenCanceledByAnother.java Tue Apr 02 12:46:05 2019 +0530
@@ -38,11 +38,11 @@
@Test
public void test() {
addProduct(PRODUCT_A_NAME);
+ addProduct(PRODUCT_B_NAME);
+ addProduct(PRODUCT_C_NAME);
verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-30.10");
- addProduct(PRODUCT_B_NAME);
verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT_EXTMOD, "-101.40");
- addProduct(PRODUCT_C_NAME);
- verify(TestIdPack.LABEL_RECEIPT_ROW3_DISCOUNTAMOUNT, "-4.20");
+ verify(TestIdPack.LABEL_RECEIPT_ROW3_DISCOUNTAMOUNT, "-6.30");
tap(TestIdPack.BUTTON_DELETERECEIPT);
tap(TestIdPack.BUTTON_DELETERECEIPT_CONFIRM);
diff -r 60b84c93e606 -r e51817bfbbad src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38813_VerifyDiscountWhenCanceledByAnother2.java
--- a/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38813_VerifyDiscountWhenCanceledByAnother2.java Tue Apr 02 11:15:55 2019 +0530
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I38813_VerifyDiscountWhenCanceledByAnother2.java Tue Apr 02 12:46:05 2019 +0530
@@ -23,6 +23,7 @@
package org.openbravo.test.mobile.retail.extmodules.selenium.tests.discounts_scaledprice;
import org.junit.Test;
+import org.openbravo.test.mobile.retail.extmodules.selenium.TestIdExtModules;
import org.openbravo.test.mobile.retail.extmodules.selenium.terminals.WebPOSExtModulesTerminalHelper;
import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
@@ -40,11 +41,16 @@
addProduct(PRODUCT_C_NAME);
verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-132.54");
addProduct(PRODUCT_A_NAME);
- addProduct(PRODUCT_A_NAME);
- verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, "-9.13");
+ tap(TestIdExtModules.BUTTON_RECEIPT_ROW2);
+ tap(TestIdExtModules.BUTTON_KEYPAD_3);
+ tap(TestIdExtModules.BUTTON_KEYPAD_QUANTITY);
addProduct(PRODUCT_B_NAME);
- verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, "-27.38");
- verify(TestIdPack.LABEL_RECEIPT_TOTAL_GROSS, "243.88");
+ tap(TestIdExtModules.BUTTON_RECEIPT_ROW3);
+ tap(TestIdExtModules.BUTTON_KEYPAD_2);
+ tap(TestIdExtModules.BUTTON_KEYPAD_QUANTITY);
+ verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, "-82.13");
+ verify(TestIdPack.LABEL_RECEIPT_ROW3_DISCOUNTAMOUNT, "-27.48");
+ verify(TestIdPack.LABEL_RECEIPT_TOTAL_GROSS, "308.05");
tap(TestIdPack.BUTTON_DELETERECEIPT);
tap(TestIdPack.BUTTON_DELETERECEIPT_CONFIRM);
diff -r 60b84c93e606 -r e51817bfbbad src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I40478_VerifyScaledDiscountWithLowerPrice.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/discounts_scaledprice/I40478_VerifyScaledDiscountWithLowerPrice.java Tue Apr 02 12:46:05 2019 +0530
@@ -0,0 +1,107 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2019 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+
+package org.openbravo.test.mobile.retail.extmodules.selenium.tests.discounts_scaledprice;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.extmodules.selenium.TestIdExtModules;
+import org.openbravo.test.mobile.retail.extmodules.selenium.terminals.WebPOSExtModulesTerminalHelper;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+
+public class I40478_VerifyScaledDiscountWithLowerPrice extends WebPOSExtModulesTerminalHelper {
+ final static String SCALEDPRICE_DISCOUNT_ID = "4842399E7EC54206B4F2B24DB9D2193B";
+
+ final static String PRODUCT_A_NAME = "Avalanche transceiver";
+ final static String PRODUCT_B_NAME = "Balaclava cap";
+ final static String PRODUCT_C_NAME = "Camera bag";
+
+ @Test
+ public void test() {
+ // Verify Discount With One Product
+ addProduct(PRODUCT_A_NAME);
+ tap(TestIdExtModules.BUTTON_RECEIPT_ROW1);
+ tap(TestIdExtModules.BUTTON_KEYPAD_PLUS);
+ tap(TestIdExtModules.BUTTON_KEYPAD_PLUS);
+ verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-180.60");
+ tap(TestIdExtModules.BUTTON_KEYPAD_PLUS);
+ verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-180.60");
+ tap(TestIdExtModules.BUTTON_KEYPAD_6);
+ tap(TestIdExtModules.BUTTON_KEYPAD_QUANTITY);
+ verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-361.20");
+ tap(TestIdExtModules.BUTTON_DELETERECEIPT);
+ tap(TestIdExtModules.BUTTON_DELETERECEIPT_CONFIRM);
+ verify(TestIdExtModules.LABEL_TOTALTOPAY, "0.00");
+
+ // Verify Discount With Multiple Products
+ addProduct(PRODUCT_A_NAME);
+ addProduct(PRODUCT_C_NAME);
+ tap(TestIdExtModules.BUTTON_RECEIPT_ROW2);
+ tap(TestIdExtModules.BUTTON_KEYPAD_PLUS);
+ verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-30.10");
+ verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, "-10.50");
+ tap(TestIdExtModules.BUTTON_KEYPAD_PLUS);
+ verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, "-12.60");
+ verify(TestIdExtModules.LABEL_TOTALTOPAY, "169.40");
+ tap(TestIdExtModules.BUTTON_RECEIPT_ROW2);
+ tap(TestIdExtModules.BUTTON_KEYPAD_5);
+ tap(TestIdExtModules.BUTTON_KEYPAD_QUANTITY);
+ verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-30.10");
+ verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, "-23.10");
+ addProduct(PRODUCT_B_NAME);
+ addProduct(PRODUCT_B_NAME);
+ addProduct(PRODUCT_B_NAME);
+ verify(TestIdExtModules.LABEL_TOTALTOPAY, "521.10");
+ verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-60.20");
+ verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, "-27.30");
+ verify(TestIdPack.LABEL_RECEIPT_ROW3_DISCOUNTAMOUNT_EXTMOD, "-101.40");
+ tap(TestIdExtModules.BUTTON_DELETERECEIPT);
+ tap(TestIdExtModules.BUTTON_DELETERECEIPT_CONFIRM);
+ verify(TestIdExtModules.LABEL_TOTALTOPAY, "0.00");
+ }
+
+ private void addProduct(String productName) {
+ tap(TestIdExtModules.BUTTON_SEARCH);
+ write(TestIdExtModules.FIELD_SEARCH_TEXT, productName);
+ TestIdExtModules.FIELD_SEARCH_TEXT.enyoNode().executeExtension(".waterfall('onchange')");
+ tap(TestIdExtModules.BUTTON_SEARCH_EXECUTE);
+ tap(TestIdExtModules.BUTTON_SEARCHPRODUCT_FIRSTROW);
+ }
+
+ @Override
+ public void beforeWithReload() {
+ setActiveDiscount(SCALEDPRICE_DISCOUNT_ID, true);
+ }
+
+ @Override
+ public void afterWithReload() {
+ setActiveDiscount(SCALEDPRICE_DISCOUNT_ID, false);
+ }
+
+ private void setActiveDiscount(String discountId, boolean active) {
+ String sql = String.format("update m_offer set isactive = '%s' where m_offer_id = '%s'",
+ active ? "Y" : "N", discountId);
+
+ new DatabaseHelperInsertUpdateOrDelete() {
+ }.execute(sql, 1);
+ }
+}
|