# HG changeset patch
# User Silambarasan Sekar <silambarasan@qualiantech.com>
# Date 1473763192 -19800
#      Tue Sep 13 16:09:52 2016 +0530
# Node ID 0152d1ed091fc1d3bf88a3bbfeab634d808615a8
# Parent  ffce906916db130bf4d6e739d0de7f161713f9d7
Verifies issue 33963: Check discount is calculated from Product Tab
when using a product configured with "Price Adjustment List" Discount Rule

Added test I33963_PriceAdjustmentlist.

diff -r ffce906916db -r 0152d1ed091f src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33963_PriceAdjustmentlist.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33963_PriceAdjustmentlist.java	Tue Sep 13 16:09:52 2016 +0530
@@ -0,0 +1,105 @@
+/*
+ *************************************************************************
+ * 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) 2008-2014 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author SIM
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.discountsandpromotions;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.WebPOSTerminalHelper;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.common.selenium.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+
+public class I33963_PriceAdjustmentlist extends WebPOSTerminalHelper {
+
+  public static final String priceAdjustmentListId = "DA83FF27481D4A4E8CB3A56903EC4326";
+
+  @Test
+  public void test() {
+
+    tap(TestIdPack.BUTTON_BROWSE);
+    tap(TestIdPack.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestIdPack.BUTTON_PRODUCT_MOUNTAINEERING_CRAMPONS10POINT);
+    verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTNAME, "-- Price Adjustment List");
+    verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTAMOUNT, "-3.99");
+    verify(TestIdPack.LABEL_TOTALTOPAY, "35.91");
+    final String receiptNo = BackboneHelper.getDocumentNo();
+    tap(TestIdPack.BUTTON_PAY);
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    verifyPromotion(receiptNo);
+
+  }
+
+  private void verifyPromotion(final String receiptNo) {
+    // verifications IV. promotion
+    final String sql = "SELECT"
+        + " c_orderline_offer.line AS line,"
+        + " m_offer.name AS promotion_name,"
+        + " c_orderline_offer.amtoffer AS discountperunit,"
+        + " c_orderline_offer.totalamt AS totalamount"
+        + " FROM c_order"
+        + " INNER JOIN c_orderline ON c_order.c_order_id = c_orderline.c_order_id"
+        + " INNER JOIN c_orderline_offer ON c_orderline.c_orderline_id = c_orderline_offer.c_orderline_id"
+        + " INNER JOIN m_offer ON c_orderline_offer.m_offer_id = m_offer.m_offer_id"
+        + " WHERE c_order.documentno = '" + receiptNo + "'";
+
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        logger.info("Verifying the Sale Promotion in the backend");
+        final int line = rs.getInt("line");
+        final String promotionName = rs.getString("promotion_name");
+        final float discountPerUnit = rs.getFloat("discountperunit");
+        final float totalDiscount = rs.getFloat("totalamount");
+
+        assertEquals(10, line);
+        assertEquals("Price Adjustment List", promotionName);
+        assertEquals(3.99, discountPerUnit, 0.1);
+        assertEquals(3.99, totalDiscount, 0.1);
+      }
+    }.execute(sql, 1);
+  }
+
+  @Override
+  public void beforeWithReload() {
+    final String updateDiscountActive = String.format(
+        "update m_offer set isactive='Y' where m_offer_id='%s'", priceAdjustmentListId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(updateDiscountActive, 1);
+
+  }
+
+  @Override
+  public void afterWithReload() {
+    final String updateDiscountActive = String.format(
+        "update m_offer set isactive='N' where m_offer_id='%s'", priceAdjustmentListId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(updateDiscountActive, 1);
+  }
+
+}
