# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1452779330 -19800
# Node ID bdfa359b4ad19eabf266740f27952826dd149459
# Parent  afc83636783659f8c12e3a1c9c423cdbcc354b65
Verifies issue 31877: Added automated test 'I31877_VerifyReturnQtyWithTotalQty'

diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/returns/I31877_VerifyReturnQtyWithTotalQty.java b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/returns/I31877_VerifyReturnQtyWithTotalQty.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/returns/I31877_VerifyReturnQtyWithTotalQty.java
@@ -0,0 +1,86 @@
+/*
+ *************************************************************************
+ * 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) 2015 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.returns;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.javascript.BackboneHelper;
+import org.openbravo.test.mobile.common.selenium.javascript.TestId;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+
+/**
+ * Verifies that the Return Qty should not be greater then Total receipt qty
+ * 
+ */
+
+public class I31877_VerifyReturnQtyWithTotalQty extends WebPOSTerminalHelper {
+
+  @Test
+  public void test() {
+    final String customer = get(TestId.BUTTON_RECEIPT_CUSTOMER);
+
+    // Add Product
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestId.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestId.LABEL_TOTALTOPAY, "150.50");
+    tap(TestId.BUTTON_RECEIPT_ROW1);
+    tap(TestId.BUTTON_KEYPAD_6);
+    tap(TestId.BUTTON_KEYPAD_QUANTITY);
+    verify(TestId.LABEL_TOTALTOPAY, "903.00");
+    final String receiptNo = BackboneHelper.getDocumentNo();
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+
+    // Select Product from Verified Returns and apply with Quantity 2
+    addProductFromVerfiedReturn(receiptNo, customer, "2");
+    verify(TestId.LABEL_TOTALTOPAY, "-301.00");
+
+    // Select Product from Verified Returns and apply with Quantity 3
+    addProductFromVerfiedReturn(receiptNo, customer, "3");
+    verify(TestId.LABEL_TOTALTOPAY, "-752.50");
+
+    // Select Product from Verified Returns and apply with Quantity 1
+    addProductFromVerfiedReturn(receiptNo, customer, "1");
+    verify(TestId.LABEL_TOTALTOPAY, "-903.00");
+
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+  }
+
+  private void addProductFromVerfiedReturn(final String receiptNo, final String customer,
+      final String quantity) {
+    // Open Verified Returns
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_VERIFIEDRETURN);
+    write(TestId.FIELD_SEARCH_RECEIPT, receiptNo);
+    tap(TestId.BUTTON_RECEIPTS_SEARCH);
+    tap(TestId.TABLE_RECEIPTSEARCH, String.format("%s - %s", receiptNo, customer));
+
+    // Select Product and add quantity
+    tap(TestId.BUTTON_VERIFIEDRETURNS_LINES_CHECKROW1);
+    write(TestId.INPUT_VERIFIEDRETURNS_LINES_QTY, quantity);
+    tap(TestId.BUTTON_POPUP_APPLY);
+  }
+}
\ No newline at end of file
