diff --git a/src-test/org/openbravo/test/mobile/common/selenium/javascript/TestId.java b/src-test/org/openbravo/test/mobile/common/selenium/javascript/TestId.java
--- a/src-test/org/openbravo/test/mobile/common/selenium/javascript/TestId.java
+++ b/src-test/org/openbravo/test/mobile/common/selenium/javascript/TestId.java
@@ -402,6 +402,9 @@
   LABEL_CASHUP_STEP4_TITLE("cashToKeep_cashtokeepheader"), //
   LABEL_CASHUP_STEP5_TITLE("postPrintClose_reporttitle"), //
   // Step 2
+  BUTTON_CASHUP_COUNTCASH_001("paymentsList_row1_qtyplus", EnyoKind.BUTTON), //
+  BUTTON_CASHUP_COUNTCASH_002("paymentsList_row2_qtyplus", EnyoKind.BUTTON), //
+  BUTTON_CASHUP_COUNTCASH_005("paymentsList_row3_qtyplus", EnyoKind.BUTTON), //
   BUTTON_CASHUP_COUNTCASH_010("paymentsList_row4_qtyplus", EnyoKind.BUTTON), //
   BUTTON_CASHUP_COUNTCASH_020("paymentsList_row5_qtyplus", EnyoKind.BUTTON), //
   BUTTON_CASHUP_COUNTCASH_050("paymentsList_row6_qtyplus", EnyoKind.BUTTON), //
diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/deleteTicket/DeleteTicketLines.java b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/deleteTicket/DeleteTicketLines.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/deleteTicket/DeleteTicketLines.java
@@ -0,0 +1,369 @@
+/*
+ *************************************************************************
+ * 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 ACA
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.deleteTicket;
+
+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.SeleniumHelper;
+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.javascript.TestId;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+import org.openbravo.test.mobile.common.selenium.testhelpers.WebPOSSnippet;
+import org.openbravo.test.mobile.common.selenium.utils.Constants;
+import org.openbravo.test.mobile.common.selenium.utils.Utils;
+
+/**
+ * This test takes care of checking that, if the OBPOS_remove_ticket preference is set, deleted
+ * lines are tracked in the backend during normal ticket creation. It also checks that the cashup
+ * report is not modified, even if the lines exist in the backend.
+ * 
+ */
+public class DeleteTicketLines extends WebPOSTerminalHelper {
+
+  @Test
+  public void test() {
+
+    // First we need to make sure we are logged in with a user with the
+    // preference to keep deleted lines
+    setPreference();
+
+    String documentno;
+    final String VBS1001Uri = Utils.getCurrentHref();
+    final String PS1Uri = VBS1001Uri.replace("VBS1001", "PS-1");
+
+    WebPOSSnippet.cleanCashup(this);
+
+    // Create a ticket, delete a line, verify database.
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestId.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestId.LABEL_TOTALTOPAY, "150.50");
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_ADHESIVEBODYWARNMERS);
+    verify(TestId.LABEL_TOTALTOPAY, "154.10");
+    tap(TestId.LABEL_RECEIPT_ROW1);
+    tap(TestId.BUTTON_EDIT);
+    tap(TestId.BUTTON_EDIT_DELETELINE);
+    verify(TestId.LABEL_TOTALTOPAY, "3.60");
+    documentno = BackboneHelper.getDocumentNo();
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+    verifyDelete(documentno, "2.98", "3.60");
+
+    // Create a ticket, delete a line with a discount, verify database.
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestId.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestId.LABEL_TOTALTOPAY, "150.50");
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_RECEIPTDISCOUNTS);
+    tap(TestId.BUTTON_RECEIPTDISCOUNTS_CHECKAPPLYALL);
+    tap(TestId.BUTTON_RECEIPTDISCOUNTS_APPLY);
+    verify(TestId.LABEL_TOTALTOPAY, "142.98");
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_ADHESIVEBODYWARNMERS);
+    verify(TestId.LABEL_TOTALTOPAY, "146.58");
+    tap(TestId.LABEL_RECEIPT_ROW1);
+    tap(TestId.BUTTON_EDIT);
+    tap(TestId.BUTTON_EDIT_DELETELINE);
+    verify(TestId.LABEL_TOTALTOPAY, "3.60");
+    documentno = BackboneHelper.getDocumentNo();
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+    verifyDelete(documentno, "2.98", "3.60");
+
+    verifyCashup("VBS1001");
+
+    // navigate to PS to test values with a price list not including taxes
+    changeTerminal(PS1Uri);
+    login("demouser");
+
+    // After logging in with a different user, we need to make sure
+    // the user has the preference set
+    setPreference();
+
+    cleanCashupPS();
+
+    // Create a ticket, delete a line, verify database.
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestId.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestId.LABEL_TOTALTOPAY, "182.11");
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_ADHESIVEBODYWARNMERS);
+    verify(TestId.LABEL_TOTALTOPAY, "186.47");
+    tap(TestId.LABEL_RECEIPT_ROW1);
+    tap(TestId.BUTTON_EDIT);
+    tap(TestId.BUTTON_EDIT_DELETELINE);
+    verify(TestId.LABEL_TOTALTOPAY, "4.36");
+    documentno = BackboneHelper.getDocumentNo();
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+    verifyDelete(documentno, "3.60", "4.36");
+
+    // Create a ticket, delete a line with a discount, verify database.
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestId.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestId.LABEL_TOTALTOPAY, "182.11");
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_RECEIPTDISCOUNTS);
+    tap(TestId.BUTTON_RECEIPTDISCOUNTS_CHECKAPPLYALL);
+    tap(TestId.BUTTON_RECEIPTDISCOUNTS_APPLY);
+    verify(TestId.LABEL_TOTALTOPAY, "173.01");
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_ADHESIVEBODYWARNMERS);
+    verify(TestId.LABEL_TOTALTOPAY, "177.37");
+    tap(TestId.LABEL_RECEIPT_ROW1);
+    tap(TestId.BUTTON_EDIT);
+    tap(TestId.BUTTON_EDIT_DELETELINE);
+    verify(TestId.LABEL_TOTALTOPAY, "4.36");
+    documentno = BackboneHelper.getDocumentNo();
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+    verifyDelete(documentno, "3.60", "4.36");
+
+    verifyCashup("PS-1");
+
+    // return to the initial state
+    changeTerminal(VBS1001Uri);
+    login("vallblanca");
+  }
+
+  private void setPreference() {
+    SeleniumHelper
+        .executeScript("OB.MobileApp.model.get('permissions')['OBPOS_remove_ticket']=true;");
+  }
+
+  private void verifyCashup(String terminal) {
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_CASHUP);
+
+    // step 1 of 5
+    verify(TestId.LABEL_CASHUP_STEP1_TITLE, "Step 1 of 5: Review pending receipts");
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 2 of 5
+    verify(TestId.LABEL_CASHUP_STEP2_TITLE, "Step 2 of 5: Count Cash");
+    if ("VBS1001".equals(terminal)) {
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_5);
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_2);
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_020);
+    } else if ("PS-1".equals(terminal)) {
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_5);
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_2);
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_1);
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_050);
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_020);
+      tap(TestId.BUTTON_CASHUP_COUNTCASH_002);
+      tap(TestId.BUTTON_CASHUP_NEXT);
+      verify(TestId.LABEL_CASHUP_STEP2_TITLE, "Step 2 of 5: Count USA Cash");
+    }
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 3 of 5
+    verify(TestId.LABEL_CASHUP_STEP3_TITLE, "Step 3 of 5: Count Cash");
+    tap(TestId.BUTTON_CASHUP_CARD_OK);
+    if ("VBS1001".equals(terminal)) {
+      tap(TestId.BUTTON_CASHUP_CASHUSA_OK);
+    }
+    tap(TestId.BUTTON_CASHUP_VOUCHER_OK);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 4 of 5
+    // cash
+    verify(TestId.LABEL_CASHUP_STEP4_TITLE, "Step 4 of 5: Select Cash to keep");
+    verify(TestId.LABEL_CASHUP_KEEPNOTHING, "Nothing");
+    tap(TestId.BUTTON_CASHUP_KEEPNOTHING);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+    // usa cash
+    verify(TestId.LABEL_CASHUP_STEP4_TITLE, "Step 4 of 5: Select USA Cash to keep");
+    verify(TestId.LABEL_CASHUP_KEEPNOTHING, "Nothing");
+    tap(TestId.BUTTON_CASHUP_KEEPNOTHING);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+    // voucher
+    verify(TestId.LABEL_CASHUP_STEP4_TITLE, "Step 4 of 5: Select Voucher to keep");
+    verify(TestId.LABEL_CASHUP_KEEPNOTHING, "Nothing");
+    tap(TestId.BUTTON_CASHUP_KEEPNOTHING);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 5 of 5
+    if ("VBS1001".equals(terminal)) {
+      verify(TestId.LABEL_CASHUP_NETSALES_AMOUNT, "5.96");
+      verify(TestId.LABEL_CASHUP_NETSALES_TAX21, "1.24");
+      verify(TestId.LABEL_CASHUP_GROSSSALES_AMOUNT, "7.20");
+      verify(TestId.LABEL_CASHUP_GROSSRETURNS_AMOUNT, "0.00");
+      verify(TestId.LABEL_CASHUP_TOTALTRASACTIONS, "7.20");
+      verify(TestId.LABEL_CASHUP_STARTING_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_WITHDRAWAL_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_DEPOSIT_TOTAL, "7.20");
+      verify(TestId.LABEL_CASHUP_EXPECTED_TOTAL, "7.20");
+      verify(TestId.LABEL_CASHUP_COUNTED_TOTAL, "7.20");
+      verify(TestId.LABEL_CASHUP_DIFFERENCE_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_TOTALTOKEEP_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_TOTALTODEPOSIT_TOTAL, "7.20");
+    } else if ("PS-1".equals(terminal)) {
+      verify(TestId.LABEL_CASHUP_NETSALES_AMOUNT, "7.20");
+      verify(TestId.LABEL_CASHUP_NETSALES_TAX21, "1.52");
+      verify(TestId.LABEL_CASHUP_GROSSSALES_AMOUNT, "8.72");
+      verify(TestId.LABEL_CASHUP_GROSSRETURNS_AMOUNT, "0.00");
+      verify(TestId.LABEL_CASHUP_TOTALTRASACTIONS, "8.72");
+      verify(TestId.LABEL_CASHUP_STARTING_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_WITHDRAWAL_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_DEPOSIT_TOTAL, "8.72");
+      verify(TestId.LABEL_CASHUP_EXPECTED_TOTAL, "8.72");
+      verify(TestId.LABEL_CASHUP_COUNTED_TOTAL, "8.72");
+      verify(TestId.LABEL_CASHUP_DIFFERENCE_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_TOTALTOKEEP_TOTAL, "0.00");
+      verify(TestId.LABEL_CASHUP_TOTALTODEPOSIT_TOTAL, "8.72");
+    }
+
+    verify(TestId.LABEL_CASHUP_STEP5_TITLE, "Step 5 of 5: Post, print and close");
+    verify(TestId.LABEL_CASHUP_POSTPRINTANDCLOSE, "Post, Print & Close");
+    tap(TestId.BUTTON_CASHUP_POSTPRINTANDCLOSE);
+
+    // done
+    verify(TestId.LABEL_POPUP_TITLE, "Good job!");
+    tap(TestId.BUTTON_POPUP_OK);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+  }
+
+  private void verifyDelete(final String documentNo, final String net, final String gross) {
+
+    final String AVALANCHE_TRANSCEIVER = "934E7D7587EC4C7A9E9FF58F0382D450";
+    final String ADHESIVE_WARMERS = "AC79520FEB4743B3AAA379BF70B9B7DA";
+
+    final String sql = "select o.em_obpos_isdeleted headerDeleted, "
+        + "ol.em_obpos_isdeleted lineDeleted, COALESCE(ol.em_obpos_qtydeleted, 0) qtyDeleted,  "
+        + "ol.m_product_id product, o.grandtotal totalgross, o.totallines totalnet, o.docstatus, ol.qtyordered "
+        + "from c_order o, c_orderline ol " + "where o.c_order_id = ol.c_order_id "
+        + "and documentno = '" + documentNo + "'";
+
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        logger.info("Verifying ticket in the backend");
+        final String header = rs.getString("headerDeleted");
+        final String line = rs.getString("lineDeleted");
+        final String product = rs.getString("product");
+        final String qtyDeleted = rs.getString("qtyDeleted");
+        final String qtyOrdered = rs.getString("qtyOrdered");
+        final String totalnet = rs.getString("totalnet");
+        final String totalgross = rs.getString("totalgross");
+        final String docstatus = rs.getString("docstatus");
+
+        assertEquals("N", header);
+        assertEquals(net, totalnet);
+        assertEquals(gross, totalgross);
+        assertEquals("CO", docstatus);
+
+        if (product.equals(ADHESIVE_WARMERS)) {
+          assertEquals("N", line);
+          assertEquals("0", qtyDeleted);
+          assertEquals("1", qtyOrdered);
+        } else if (product.equals(AVALANCHE_TRANSCEIVER)) {
+          assertEquals("Y", line);
+          assertEquals("1", qtyDeleted);
+          assertEquals("0", qtyOrdered);
+        }
+      }
+    }.execute(sql, 2);
+  }
+
+  private void login(final String newUsername) {
+    TestId.LABEL_LOGIN_OPENBRAVOMOBILE.enyoNode().waitUntilIsReady();
+    Utils.pause(Constants.WAIT_AFTERWEBPOSLOGO);
+    write(TestId.FIELD_LOGIN_USERNAME, newUsername);
+    write(TestId.FIELD_LOGIN_PASSWORD, "openbravo");
+    tap(TestId.BUTTON_LOGIN);
+    Utils.pause(Constants.WAIT_AFTERSUCCESSFULLOGIN);
+    TestId.TABLE_PRODUCTS.enyoNode().waitUntilIsReady();
+  }
+
+  private void cleanCashupPS() {
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_CASHUP);
+
+    // step 1 of 5
+    verify(TestId.LABEL_CASHUP_STEP1_TITLE, "Step 1 of 5: Review pending receipts");
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 2 of 5
+    verify(TestId.LABEL_CASHUP_STEP2_TITLE, "Step 2 of 5: Count Cash");
+    tap(TestId.BUTTON_CASHUP_NEXT);
+    verify(TestId.LABEL_CASHUP_STEP2_TITLE, "Step 2 of 5: Count USA Cash");
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 3 of 5
+    verify(TestId.LABEL_CASHUP_STEP3_TITLE, "Step 3 of 5: Count Cash");
+    tap(TestId.BUTTON_CASHUP_CARD_OK);
+    tap(TestId.BUTTON_CASHUP_VOUCHER_OK);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 4 of 5
+    // cash
+    verify(TestId.LABEL_CASHUP_STEP4_TITLE, "Step 4 of 5: Select Cash to keep");
+    verify(TestId.LABEL_CASHUP_KEEPNOTHING, "Nothing");
+    tap(TestId.BUTTON_CASHUP_KEEPNOTHING);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+    // usa cash
+    verify(TestId.LABEL_CASHUP_STEP4_TITLE, "Step 4 of 5: Select USA Cash to keep");
+    verify(TestId.LABEL_CASHUP_KEEPNOTHING, "Nothing");
+    tap(TestId.BUTTON_CASHUP_KEEPNOTHING);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+    // voucher
+    verify(TestId.LABEL_CASHUP_STEP4_TITLE, "Step 4 of 5: Select Voucher to keep");
+    verify(TestId.LABEL_CASHUP_KEEPNOTHING, "Nothing");
+    tap(TestId.BUTTON_CASHUP_KEEPNOTHING);
+    tap(TestId.BUTTON_CASHUP_NEXT);
+
+    // step 5 of 5
+    verify(TestId.LABEL_CASHUP_STEP5_TITLE, "Step 5 of 5: Post, print and close");
+    verify(TestId.LABEL_CASHUP_POSTPRINTANDCLOSE, "Post, Print & Close");
+    tap(TestId.BUTTON_CASHUP_POSTPRINTANDCLOSE);
+
+    // done
+    verify(TestId.LABEL_POPUP_TITLE, "Good job!");
+    tap(TestId.BUTTON_POPUP_OK);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+  }
+}
diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/deleteTicket/DeleteTicketWithDeletedLines.java b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/deleteTicket/DeleteTicketWithDeletedLines.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/deleteTicket/DeleteTicketWithDeletedLines.java
@@ -0,0 +1,119 @@
+/*
+ *************************************************************************
+ * 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 ACA
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.deleteTicket;
+
+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.SeleniumHelper;
+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.javascript.TestId;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+import org.openbravo.test.mobile.common.selenium.testhelpers.WebPOSSnippet;
+
+/**
+ * This test takes care of checking that, if the OBPOS_remove_ticket preference is set, deleted
+ * lines are tracked in the backend even if the ticket is deleted after removing all its lines.
+ * 
+ */
+public class DeleteTicketWithDeletedLines extends WebPOSTerminalHelper {
+
+  @Test
+  public void test() {
+
+    String documentno;
+
+    // First we need to make sure we are logged in with a user with the
+    // preference to keep deleted lines and deleted tickets
+    setPreference();
+
+    WebPOSSnippet.cleanCashup(this);
+
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestId.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestId.LABEL_TOTALTOPAY, "150.50");
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_ADHESIVEBODYWARNMERS);
+    verify(TestId.LABEL_TOTALTOPAY, "154.10");
+
+    documentno = BackboneHelper.getDocumentNo();
+
+    tap(TestId.BUTTON_SCAN);
+    tap(TestId.BUTTON_SCAN_UNDO);
+    verify(TestId.LABEL_TOTALTOPAY, "150.50");
+
+    tap(TestId.LABEL_RECEIPT_ROW1);
+    tap(TestId.BUTTON_EDIT);
+    tap(TestId.BUTTON_EDIT_DELETELINE);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+    tap(TestId.BUTTON_DELETERECEIPT);
+    tap(TestId.BUTTON_DELETERECEIPT_CONFIRM);
+    verifyDelete(documentno);
+
+  }
+
+  private void setPreference() {
+    SeleniumHelper
+        .executeScript("OB.MobileApp.model.get('permissions')['OBPOS_remove_ticket']=true;");
+  }
+
+  private void verifyDelete(final String documentNo) {
+
+    final String sql = "select o.em_obpos_isdeleted headerDeleted, "
+        + "ol.em_obpos_isdeleted lineDeleted, ol.em_obpos_qtydeleted, "
+        + "o.grandtotal, o.totallines, o.docstatus, amtoffer "
+        + "from c_order o, c_orderline ol left join (select sum(amtoffer) amtoffer,olo.c_orderline_id "
+        + "from c_orderline_offer olo group by olo.c_orderline_id) as offer on ol.c_orderline_id = offer.c_orderline_id "
+        + "where o.c_order_id = ol.c_order_id " + "and documentno = '" + documentNo + "'";
+
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        logger.info("Verifying deleted ticket in the backend");
+        final String header = rs.getString("headerDeleted");
+        final String line = rs.getString("lineDeleted");
+        final String qtyDeleted = rs.getString("em_obpos_qtydeleted");
+        final String totlaLines = rs.getString("totallines");
+        final String grandTotal = rs.getString("grandtotal");
+        final String docstatus = rs.getString("docstatus");
+        final String amtOffer = rs.getString("amtoffer");
+
+        assertEquals("Y", header);
+        assertEquals("Y", line);
+        assertEquals("1", qtyDeleted);
+        assertEquals("0", totlaLines);
+        assertEquals("0", grandTotal);
+        assertEquals("CL", docstatus);
+        if (amtOffer != null) {
+          assertEquals("0", amtOffer);
+        }
+      }
+    }.execute(sql, 2);
+  }
+}
