# HG changeset patch
# User Shivanand Madiwalar <shivanand.madiwalar@promantia.com>
# Date 1474974743 -19800
#      Tue Sep 27 16:42:23 2016 +0530
# Node ID 2ebd087ebfbdaf2bcba9ed511b499280f9afcbf3
# Parent  818cf988e366a59c2c07539e2926c41a31946d82
verifies To Issue 33990 :-ve line gross price in the sales Order when product attribute grouped and scaled are true.

Treat product as non-grouped when the attributes of product grouped&scaled are checked .

diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33990_scaleplusgrouped_considernongrouped.java b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33990_scaleplusgrouped_considernongrouped.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33990_scaleplusgrouped_considernongrouped.java
@@ -0,0 +1,160 @@
+/*
+ *************************************************************************
+ * 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) 2016 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author SMA
+ *
+ */
+package org.openbravo.test.mobile.retail.pack.selenium.tests.discountsandpromotions;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.SeleniumHelper;
+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.common.selenium.utils.OBNumber;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+
+public class I33990_scaleplusgrouped_considernongrouped extends WebPOSTerminalHelper {
+
+  String productName = TestIdPack.BUTTON_SEARCHPRODUCT_WHISTLE.getRowName();
+  String documentno = null;
+  String clientId = null;
+  OBNumber firstLineprice;
+  OBNumber secondLineprice;
+  final String orgId = "0";
+  final String userId = "100";
+  private final String offerId = getUUID();
+
+  @Test
+  public void test() {
+    documentno = BackboneHelper.getDocumentNo();
+    tap(TestIdPack.BUTTON_SEARCH);
+    write(TestIdPack.FIELD_SEARCH_TEXT, TestIdPack.BUTTON_SEARCHPRODUCT_WHISTLE.getRowName());
+    tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
+    verifyHighVolumeTime(TestIdPack.BUTTON_SEARCH_EXECUTE);
+    tap(TestIdPack.BUTTON_SEARCHPRODUCT_WHISTLE);
+    tap(TestIdPack.BUTTON_SEARCHPRODUCT_WHISTLE);
+    tap(TestIdPack.BUTTON_PAY);
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    tap(TestIdPack.BUTTON_PAY_DONE);
+
+  }
+
+  private String getUUID() {
+    String randomUUID = UUID.randomUUID().toString();
+    randomUUID = randomUUID.toUpperCase();
+    return randomUUID.replace("-", "");
+  }
+
+  @Override
+  public void beforeWithReload() {
+    clientId = (String) SeleniumHelper
+        .executeScriptWithReturn("OB.POS.modelterminal.get('terminal').client");
+    final String sqlupdate1 = String.format("update m_product set EM_Obpos_Scale='Y'"
+        + "where name = '%s'", productName);
+    final String sqlupdate2 = String.format("update m_product set EM_Obpos_Groupedproduct='Y'"
+        + "where name = '%s'", productName);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sqlupdate1, 1);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sqlupdate2, 1);
+    insertSampleDiscountPromotionRecord();
+
+  }
+
+  @Override
+  public void afterWithReload() {
+    final String sqlupdate1 = String.format("update m_offer set isactive='N'"
+        + "where m_offer_id = '%s'", offerId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sqlupdate1, 1);
+    verifyNoNegativeLines();
+    deActivateTheInsertedSampleRecord();
+  }
+
+  private void verifyNoNegativeLines() {
+    salesOrdersFirstLInePrice();
+    salesOrdersSecondLInePrice();
+    assertThat(firstLineprice, equalTo(secondLineprice));
+  }
+
+  private void salesOrdersFirstLInePrice() {
+    final String sql = "SELECT gross_unit_price FROM c_orderline  WHERE c_order_id in (select c_order_id from c_order where documentno = '"
+        + documentno + "' and line='10') order by line asc ";
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+
+        firstLineprice = new OBNumber(rs.getBigDecimal("gross_unit_price"));
+      }
+    }.execute(sql, 1);
+
+  }
+
+  private void deActivateTheInsertedSampleRecord() {
+    final String sqlupdate1 = String.format("update m_product set EM_Obpos_Scale='N'"
+        + "where name = '%s'", productName);
+    final String sqlupdate2 = String.format("update m_product set EM_Obpos_Groupedproduct='Y'"
+        + "where name = '%s'", productName);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sqlupdate1, 1);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sqlupdate2, 1);
+    verifyNoNegativeLines();
+  }
+
+  private void insertSampleDiscountPromotionRecord() {
+    final String insertOfferSQL = String.format("INSERT INTO m_offer("
+        + "m_offer_id, ad_client_id, ad_org_id, isactive, created, createdby,"
+        + "updated, updatedby, name, priority, addamt, discount, fixed, "
+        + "datefrom, dateto, bpartner_selection, bp_group_selection, product_selection,"
+        + "prod_cat_selection, description, pricelist_selection, qty_from, "
+        + "qty_to, m_offer_type_id, apply_next, print_name, org_selection, "
+        + "ismultiple, multiple, characteristics_selection, em_obdisc_x, "
+        + "em_obdisc_y, em_obdisc_subtype, em_obdisc_distribute, em_obdisc_price,"
+        + "em_obdisc_c_currency_id, em_obdisc_upc, em_obdisc_image, em_obdisc_amt,"
+        + "em_obdisc_percentage, em_obdisc_role_selection, em_obdisc_approval_required)"
+        + "VALUES ('" + offerId + "','" + clientId + "','" + orgId + "','Y',now(),'" + userId
+        + "',now(),'" + userId + "','TEST',0,0,80,0,"
+        + "now()-1,now()+1,'Y','Y','N','Y',NULL,'Y',0,0,'697A7AB9FD9C4EE0A3E891D3D3CCA0A7',"
+        + "'Y',NULL,'Y','N',0,'Y',0,0,NULL,'N',0,102,NULL,NULL,0,0,'Y','N')");
+    new DatabaseHelperInsertUpdateOrDelete().execute(insertOfferSQL, 1);
+    final String insertOfferProductSQL = String.format("INSERT INTO m_offer_product "
+        + "(m_offer_product_id, ad_client_id, ad_org_id, createdby, updatedby, m_offer_id,"
+        + "m_product_id, em_obdisc_is_gift) " + "VALUES (get_uuid(), '%s', '%s', '%s', '%s', '%s',"
+        + "'C80062135FF7410DAC9924F5030953AC', 'N')", clientId, orgId, userId, userId, offerId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(insertOfferProductSQL, 1);
+  }
+
+  private void salesOrdersSecondLInePrice() {
+    final String sql = "SELECT gross_unit_price FROM c_orderline  WHERE c_order_id in (select c_order_id from c_order where documentno = '"
+        + documentno + "' and line='20') order by line asc ";
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+
+        secondLineprice = new OBNumber(rs.getBigDecimal("gross_unit_price"));
+
+      }
+    }.execute(sql, 1);
+  }
+
+}
