Attached Files | 33390fix.patch [^] (9,895 bytes) 2016-11-16 07:51 [Show Content] [Hide Content]# HG changeset patch
# User Shivanand Madiwalar <shivanand.madiwalar@promantia.com>
# Date 1479122260 -19800
# Mon Nov 14 16:47:40 2016 +0530
# Node ID d00ea58784c9af3ccc93a01c1f446df7eb7dbcf9
# Parent 893bc9cbf8290af3ba08b1f9def517932cdbbc97
Related To Issue 33390 : Promotion Buy X Pay Y implementation For Non-Grouped Products .
Improved the Some Part Of Logic .
diff --git a/web/org.openbravo.retail.discounts/js/promotion-XYsameProduct.js b/web/org.openbravo.retail.discounts/js/promotion-XYsameProduct.js
--- a/web/org.openbravo.retail.discounts/js/promotion-XYsameProduct.js
+++ b/web/org.openbravo.retail.discounts/js/promotion-XYsameProduct.js
@@ -11,12 +11,12 @@
OB.Model.Discounts.discountRules.E08EE3C23EBA49358A881EF06C139D63 = {
async: false,
implementation: function (discountRule, receipt, line) {
- var alerts, qty, x, y, mod, chunks, price, finalPrice, totalQty = 0,
- ttopay = 0,
+ var alerts, qty, x, y, mod;
+ var totalToPay = 0,
+ chunks, price, finalPrice, totalQty = 0,
totalToGift = 0,
- totalChunks, product, appliedNoOfLines = 1,
- discountRulePay, discountRuleGift, topay, togift, totalMod;
-
+ totalChunks, product, lineToApply, isManual = false,
+ discountRulePay, discountRuleGift, topay, togift, totalMod, appliedNoOfLines = 1;
x = discountRule.get('oBDISCX');
y = discountRule.get('oBDISCY');
@@ -27,38 +27,42 @@
mod = qty % x;
- //calculate the totalQty and totaltogift if product is non-grouped to Apply Promotions Each Unit Line Level .
- receipt.get('lines').forEach(function (l) {
- if (line.get('product').id === l.get('product').id && l.get('price') === line.get('price')) {
- totalQty = totalQty + l.get('qty');
- if (totalQty >= x) {
- product = line.get('product');
- totalChunks = Math.floor(totalQty / x);
- totalToGift = (x - y) * totalChunks;
- totalMod = totalQty % x;
+ //calculate the totalQty , totaltogift and totalToPay if product is non-grouped to Apply Promotions Each Unit Line Level .
+ //when ,If Product(Non-Grouped) Enforces To Apply Promotions Each Line Then Find Such Product and Calculate and Apply Promotions To
+ //Each Line which has The same Product till AppliedPromotions Lines Count Reaches The TotalToGift of Respective Product .
+ if (line.get('splitline')) {
+ receipt.get('lines').forEach(function (l) {
+ if (line.get('product').id === l.get('product').id && l.get('price') === line.get('price') && l.get('splitline')) {
+ totalQty = totalQty + l.get('qty');
+ if (totalQty >= x) {
+ lineToApply = l;
+ totalChunks = Math.floor(totalQty / x);
+ totalToGift = (x - y) * totalChunks;
+ totalToPay = y * totalChunks;
+ totalMod = totalQty % x;
+ }
+ if (!OB.UTIL.isNullOrUndefined(l.get('gifted'))) {
+ appliedNoOfLines = appliedNoOfLines + 1;
+ }
+ if (l.get('promotions')) {
+ l.get('promotions').forEach(function (promotion) {
+ if (promotion.manual) {
+ isManual = promotion.manual;
+ }
+ });
+ }
+
}
- if (!OB.UTIL.isNullOrUndefined(l.get('chunks'))) {
- appliedNoOfLines = appliedNoOfLines + 1;
- }
-
- }
- });
- //If Product(Non-Grouped) Enforces To Apply Promotions Each Line Then Find Such Product and Calculate and Apply Promotions To
- //Each Line which has The same Product till AppliedPromotions Lines Count Reaches The TotalToGift of Respective Product .
- if (!OB.UTIL.isNullOrUndefined(product) && !product.get('groupProduct')) {
- if (OB.UTIL.isNullOrUndefined(line.get('chunks'))) {
- line.set('chunks', OB.DEC.toNumber(OB.DEC.toBigDecimal(0)));
- }
- if (OB.DEC.toNumber(OB.DEC.toBigDecimal(appliedNoOfLines)) <= totalToGift && OB.DEC.toNumber(OB.DEC.toBigDecimal(appliedNoOfLines)) !== OB.DEC.toNumber(OB.DEC.toBigDecimal(0))) {
+ });
+ if (qty >= x && !isManual) {
discountRulePay = discountRule.clone();
discountRuleGift = discountRule.clone();
chunks = Math.floor(qty / x);
topay = y * chunks;
togift = (x - y) * chunks;
- if (totalMod !== 0) {
+ if (mod !== 0) {
alerts = OB.I18N.getLabel('OBPOS_DISCAlertXYSameProduct', [x - mod, line.get('product').get('_identifier'), discountRule.get('printName') || discountRule.get('name')]);
}
- var promotionQtyForEachLine = 1;
// Units to pay
discountRulePay.set('qtyOffer', topay);
receipt.addPromotion(line, discountRulePay, {
@@ -71,40 +75,91 @@
price = line.get('discountedLinePrice') || line.get('price');
// note discountedLinePrice is not updated since this rule shouldn't change it
finalPrice = OB.DEC.add(OB.DEC.mul(OB.DEC.mul(chunks, y), price), OB.DEC.mul(mod, price));
- discountRuleGift.set('qtyOffer', togift);
+ discountRuleGift.set('qtyOffer', totalToGift);
receipt.addPromotion(line, discountRuleGift, {
- amt: finalPrice,
- chunks: promotionQtyForEachLine
+ amt: OB.DEC.sub(OB.DEC.mul(qty, price), finalPrice),
+ chunks: chunks
});
- line.set('chunks', OB.DEC.toNumber(OB.DEC.toBigDecimal(appliedNoOfLines)));
}
}
- if (qty >= x) {
- discountRulePay = discountRule.clone();
- discountRuleGift = discountRule.clone();
- chunks = Math.floor(qty / x);
- topay = y * chunks;
- togift = (x - y) * chunks;
- if (mod !== 0) {
- alerts = OB.I18N.getLabel('OBPOS_DISCAlertXYSameProduct', [x - mod, line.get('product').get('_identifier'), discountRule.get('printName') || discountRule.get('name')]);
+ if (!line.get('splitline')) {
+ receipt.get('lines').forEach(function (l) {
+ if (line.get('product').id === l.get('product').id && l.get('price') === line.get('price') && !l.get('splitline')) {
+ totalQty = totalQty + l.get('qty');
+ if (totalQty >= x) {
+ lineToApply = l;
+ totalChunks = Math.floor(totalQty / x);
+ totalToGift = (x - y) * totalChunks;
+ totalToPay = y * totalChunks;
+ totalMod = totalQty % x;
+ }
+ if (!OB.UTIL.isNullOrUndefined(l.get('gifted'))) {
+ appliedNoOfLines = appliedNoOfLines + 1;
+ }
+ if (l.get('promotions')) {
+ l.get('promotions').forEach(function (promotion) {
+ if (promotion.manual) {
+ isManual = promotion.manual;
+ }
+ });
+ }
+
+ }
+ });
+ if (qty >= x) {
+ discountRulePay = discountRule.clone();
+ discountRuleGift = discountRule.clone();
+ chunks = Math.floor(qty / x);
+ topay = y * chunks;
+ togift = (x - y) * chunks;
+ if (mod !== 0) {
+ alerts = OB.I18N.getLabel('OBPOS_DISCAlertXYSameProduct', [x - mod, line.get('product').get('_identifier'), discountRule.get('printName') || discountRule.get('name')]);
+ }
+ // Units to pay
+ discountRulePay.set('qtyOffer', topay);
+ receipt.addPromotion(line, discountRulePay, {
+ amt: 0,
+ hidden: true,
+ preserve: true,
+ chunks: chunks
+ });
+ // Units to gift
+ price = line.get('discountedLinePrice') || line.get('price');
+ // note discountedLinePrice is not updated since this rule shouldn't change it
+ finalPrice = OB.DEC.add(OB.DEC.mul(OB.DEC.mul(chunks, y), price), OB.DEC.mul(mod, price));
+ discountRuleGift.set('qtyOffer', totalToGift);
+ receipt.addPromotion(line, discountRuleGift, {
+ amt: OB.DEC.sub(OB.DEC.mul(qty, price), finalPrice),
+ chunks: chunks
+ });
+ } else if (OB.DEC.toNumber(OB.DEC.toBigDecimal(appliedNoOfLines)) <= totalToGift) {
+
+ if (OB.UTIL.isNullOrUndefined(line.get('gifted'))) {
+ line.set('gifted', OB.DEC.toNumber(OB.DEC.toBigDecimal(0)));
+ }
+ discountRulePay = discountRule.clone();
+ discountRuleGift = discountRule.clone();
+ if (totalMod !== 0) {
+ alerts = OB.I18N.getLabel('OBPOS_DISCAlertXYSameProduct', [x - mod, line.get('product').get('_identifier'), discountRule.get('printName') || discountRule.get('name')]);
+ }
+ // Units to pay
+ discountRulePay.set('qtyOffer', totalToPay);
+ receipt.addPromotion(line, discountRulePay, {
+ amt: 0,
+ hidden: true,
+ preserve: true,
+ chunks: totalChunks
+ });
+ // Units to gift
+ price = line.get('discountedLinePrice') || line.get('price');
+ discountRuleGift.set('qtyOffer', totalToGift);
+ receipt.addPromotion(line, discountRuleGift, {
+ amt: OB.DEC.mul(qty, price),
+ chunks: totalChunks
+ });
+ line.set('gifted', OB.DEC.toNumber(OB.DEC.toBigDecimal(appliedNoOfLines)));
}
- // Units to pay
- discountRulePay.set('qtyOffer', topay);
- receipt.addPromotion(line, discountRulePay, {
- amt: 0,
- hidden: true,
- preserve: true,
- chunks: chunks
- });
- // Units to gift
- price = line.get('discountedLinePrice') || line.get('price');
- // note discountedLinePrice is not updated since this rule shouldn't change it
- finalPrice = OB.DEC.add(OB.DEC.mul(OB.DEC.mul(chunks, y), price), OB.DEC.mul(mod, price));
- discountRuleGift.set('qtyOffer', togift);
- receipt.addPromotion(line, discountRuleGift, {
- amt: OB.DEC.sub(OB.DEC.mul(qty, price), finalPrice),
- chunks: chunks
- });
+
}
return {
alerts: alerts
33390test.patch [^] (4,921 bytes) 2016-11-16 07:51 [Show Content] [Hide Content]# HG changeset patch
# User Shivanand Madiwalar <shivanand.madiwalar@promantia.com>
# Date 1479122299 -19800
# Mon Nov 14 16:48:19 2016 +0530
# Node ID 34cca9370d4ff6e6d851df594f0a4192fc348fa2
# Parent 92e8bd6923043cc017855e5bfedc86bb36fd19aa
Verifies Issue 33390 : Test FOr Buy X Pay Y Logic For The Non-Grouped Product .
SOme Improvement Has Been DOne To Avoid Guessing way Of Verifying The Values .
diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33390_BuyXPayYSameNonGroupProduct.java b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33390_BuyXPayYSameNonGroupProduct.java
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33390_BuyXPayYSameNonGroupProduct.java
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33390_BuyXPayYSameNonGroupProduct.java
@@ -21,8 +21,12 @@
*/
package org.openbravo.test.mobile.retail.pack.selenium.tests.discountsandpromotions;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
import org.junit.Test;
import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
@@ -30,8 +34,12 @@
String productName = TestIdPack.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_SUNCREAMLIPSTICK.getRowName();
private final String discountName = "-- Sun Cream 3x2";
+ private final String discountNameWith2Chunks = "-- (2x) Sun Cream 3x2";
private final String discountAmtRow1 = "-12.50";
private final String discountAmtRow2 = "-12.50";
+ String initialX = null;
+ String initialY = null;
+ String offer_id = null;
@Test
public void test() {
@@ -76,12 +84,12 @@
verify(TestIdPack.LABEL_PRODUCT_BACKPACKSANDTRAVEL_SUNCREAMLIPSTICK_PRICE, "12.50");
verify(TestIdPack.LABEL_RECEIPT_ROW1_TITLE, productName);
verify(TestIdPack.LABEL_RECEIPT_ROW1_QTY, "1");
- verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTNAME, discountName);
+ verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTNAME, discountNameWith2Chunks);
verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, discountAmtRow1);
verify(TestIdPack.LABEL_RECEIPT_ROW2_TITLE, productName);
verify(TestIdPack.LABEL_RECEIPT_ROW2_QTY, "1");
- verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTNAME, discountName);
+ verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTNAME, discountNameWith2Chunks);
verify(TestIdPack.LABEL_RECEIPT_ROW2_DISCOUNTAMOUNT, discountAmtRow2);
verify(TestIdPack.LABEL_TOTALTOPAY, "50.00");
@@ -92,17 +100,40 @@
@Override
public void beforeWithReload() {
- final String sqlupdate1 = String.format("update m_product set EM_Obpos_Groupedproduct='N'"
- + "where name = '%s'", productName);
- new DatabaseHelperInsertUpdateOrDelete().execute(sqlupdate1, 1);
+
+ final String query = String
+ .format("select em_obdisc_x,em_obdisc_y,m.m_offer_id from m_offer m"
+ + " left join m_offer_product mp on mp.m_offer_id=m.m_offer_id"
+ + " where m.m_offer_type_id ='E08EE3C23EBA49358A881EF06C139D63' and mp.m_product_id='288935D96601435BBDE66A231B6E066C'");
+
+ new DatabaseHelperSelect() {
+ @Override
+ protected void yieldResultSet(final ResultSet rs) throws SQLException {
+ initialX = (String) rs.getString("em_obdisc_x");
+ initialY = (String) rs.getString("em_obdisc_y");
+ offer_id = (String) rs.getString("m_offer_id");
+
+ }
+ }.execute(query, 1);
+
+ final String sqlUpdateXYParams = String.format(
+ "update m_offer set em_obdisc_x=3 ,em_obdisc_y=2" + "where m_offer_id = '%s'", offer_id);
+ new DatabaseHelperInsertUpdateOrDelete().execute(sqlUpdateXYParams, 1);
+ final String sqlUpdateProduct = String.format(
+ "update m_product set EM_Obpos_Groupedproduct='N'" + "where name = '%s'", productName);
+ new DatabaseHelperInsertUpdateOrDelete().execute(sqlUpdateProduct, 1);
}
@Override
public void afterWithReload() {
- final String sqlupdate1 = String.format("update m_product set EM_Obpos_Groupedproduct='Y'"
- + "where name = '%s'", productName);
+ final String sqlupdate1 = String.format(
+ "update m_product set EM_Obpos_Groupedproduct='Y', EM_Obpos_Scale='N'"
+ + " where name = '%s'", productName);
new DatabaseHelperInsertUpdateOrDelete().execute(sqlupdate1, 1);
+ final String sqlUpdateXYParams = String.format("update m_offer set em_obdisc_x=" + initialX
+ + ",em_obdisc_y=" + initialY + " where m_offer_id = '%s'", offer_id);
+ new DatabaseHelperInsertUpdateOrDelete().execute(sqlUpdateXYParams, 1);
}
}
|