Related to issue 33544: Move APRM JUnit tests to src-test project
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Tue, 26 Jul 2016 13:54:18 +0200
changeset 30058 c81fc9ae7a27
parent 30057 990a797ec886
child 30059 f5aec4626edb
Related to issue 33544: Move APRM JUnit tests to src-test project
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/AllTests.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/FinancialAccountTest.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentMethodTest.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_01.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_02.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_03.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_04.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_05.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_06.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_07.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_08.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_09.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_10.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_11.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/TestUtility.java
modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/Value.java
src-test/src/org/openbravo/advpaymentmngt/test/AllTests.java
src-test/src/org/openbravo/advpaymentmngt/test/FinancialAccountTest.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentMethodTest.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_01.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_02.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_03.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_04.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_05.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_06.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_07.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_08.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_09.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_10.java
src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_11.java
src-test/src/org/openbravo/advpaymentmngt/test/TestUtility.java
src-test/src/org/openbravo/advpaymentmngt/test/Value.java
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/AllTests.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- *************************************************************************
- * The contents of this file are subject to the Openbravo  Public  License
- * Version  1.1  (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 SLU 
- * All portions are Copyright (C) 2011-2014 Openbravo SLU 
- * All Rights Reserved. 
- * Contributor(s):  ______________________________________.
- ************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.openbravo.advpaymentmngt.test.draft.FinancialAccountTest;
-import org.openbravo.advpaymentmngt.test.draft.PaymentMethodTest;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_01;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_02;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_03;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_04;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_05;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_06;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_07;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_08;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_09;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_10;
-import org.openbravo.advpaymentmngt.test.draft.PaymentTest_11;
-
-/**
- * 
- * Test for org.openbravo.advpaymentmngt
- * 
- */
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
-  
-    // Master Data Configuration
-    FinancialAccountTest.class, //
-    PaymentMethodTest.class,
-    
-    // Payment scenarios
-    PaymentTest_01.class, //
-    PaymentTest_02.class, //
-    PaymentTest_03.class, //
-    PaymentTest_04.class, //
-    PaymentTest_05.class, //
-    PaymentTest_06.class, //
-    PaymentTest_07.class, //
-    PaymentTest_08.class, //
-    PaymentTest_09.class, //
-    PaymentTest_10.class, //
-    PaymentTest_11.class })
-public class AllTests {
-
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/FinancialAccountTest.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import java.math.BigDecimal;
-import java.util.List;
-
-import org.hibernate.criterion.Restrictions;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.dal.service.OBCriteria;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.geography.Location;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.test.base.OBBaseTest;
-
-public class FinancialAccountTest extends OBBaseTest {
-
-  private static final String BANK = "B";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test";
-
-  /**
-   * This before method is named setUpF() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   */
-  @Before
-  public void setUpF() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  @Test
-  public void testAddFinancialAccountValid1() {
-    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_1", STANDARD_DESCRIPTION,
-        getOneInstance(Currency.class), CASH, false, getOneInstance(Location.class),
-        getOneInstance(BusinessPartner.class), null, null, null, null, null, null, null, null,
-        null, BigDecimal.ZERO, BigDecimal.ZERO, null, true, false);
-  }
-
-  // Pre-requisite: at least one Matching Algorithm created
-  @Test
-  public void testAddFinancialAccountValid2() {
-    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_2", STANDARD_DESCRIPTION,
-        getOneInstance(Currency.class), BANK, false, getOneInstance(Location.class),
-        getOneInstance(BusinessPartner.class), "2054", "4321", "1", null, null, null, "123456789",
-        null, null, BigDecimal.ZERO, BigDecimal.ZERO,
-        null/* getOneInstance(MatchingAlgorithm.class) */, true, false);
-  }
-
-  @Test
-  public void testAddFinancialAccountValid3() {
-    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_3", STANDARD_DESCRIPTION,
-        getOneInstance(Currency.class), BANK, false, getOneInstance(Location.class),
-        getOneInstance(BusinessPartner.class), "2054", null, null, null, null, null, null, null,
-        null, BigDecimal.ZERO, BigDecimal.ZERO, null, true, false);
-  }
-
-  /**
-   * Currency is mandatory
-   */
-  @Test
-  public void testAddFinancialAccountNotValid1() {
-    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_4", STANDARD_DESCRIPTION, null,
-        BANK, false, getOneInstance(Location.class), getOneInstance(BusinessPartner.class), "2054",
-        null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null,
-        false, false);
-  }
-
-  /**
-   * Deletes all the Payment Methods created for testing
-   */
-  @Test
-  public void testDeleteFinancialAccounts() {
-    final OBCriteria<FIN_FinancialAccount> obCriteria = OBDal.getInstance().createCriteria(
-        FIN_FinancialAccount.class);
-    obCriteria
-        .add(Restrictions.eq(FIN_FinancialAccount.PROPERTY_DESCRIPTION, STANDARD_DESCRIPTION));
-    final List<FIN_FinancialAccount> finAccs = obCriteria.list();
-    for (FIN_FinancialAccount fa : finAccs) {
-      OBDal.getInstance().remove(fa);
-    }
-  }
-
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentMethodTest.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import java.util.List;
-
-import org.hibernate.criterion.Restrictions;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.dal.service.OBCriteria;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.test.base.OBBaseTest;
-
-public class PaymentMethodTest extends OBBaseTest {
-
-  private static final String AUTOMATIC_EXECUTION = "A";
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test";
-
-  /**
-   * This before method is named setUpP() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   */
-  @Before
-  public void setUpP() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  @Test
-  public void testAddPaymentMethodValid1() {
-    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_1", STANDARD_DESCRIPTION, true, false,
-        false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT,
-        true, false, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT,
-        CLEARED_ACCOUNT, true, false);
-  }
-
-  @Test
-  public void testAddPaymentMethodValid2() {
-    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_2", STANDARD_DESCRIPTION, true, false,
-        false, AUTOMATIC_EXECUTION, null, false, IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT,
-        CLEARED_ACCOUNT, true, false, false, AUTOMATIC_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
-        WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, false);
-  }
-
-  @Test
-  public void testAddPaymentMethodValid3() {
-    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_3", STANDARD_DESCRIPTION, true, false,
-        false, MANUAL_EXECUTION, null, false, null, null, null, true, false, false,
-        MANUAL_EXECUTION, null, false, null, null, null, true, false);
-  }
-
-  @Test
-  public void testAddPaymentMethodValid4() {
-    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_4", STANDARD_DESCRIPTION, true, true,
-        true, MANUAL_EXECUTION, null, false, null, null, null, true, true, true, MANUAL_EXECUTION,
-        null, false, null, null, null, true, false);
-  }
-
-  // Requisite: at least one Execution Process created
-  @Test
-  public void testAddPaymentMethodValid5() {
-    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_5", STANDARD_DESCRIPTION, true, false,
-        false, AUTOMATIC_EXECUTION, /* getOneInstance(PaymentExecutionProcess.class) */null, false,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false,
-        AUTOMATIC_EXECUTION,
-        /* getOneInstance(PaymentExecutionProcess.class) */null, false, IN_TRANSIT_ACCOUNT,
-        WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, false);
-  }
-
-  /**
-   * Deletes all the Payment Methods created for testing
-   */
-  @Test
-  public void testDeletePaymentMethod() {
-    final OBCriteria<FIN_PaymentMethod> obCriteria = OBDal.getInstance().createCriteria(
-        FIN_PaymentMethod.class);
-    obCriteria.add(Restrictions.eq(FIN_PaymentMethod.PROPERTY_DESCRIPTION, STANDARD_DESCRIPTION));
-    final List<FIN_PaymentMethod> paymentMethods = obCriteria.list();
-    for (FIN_PaymentMethod pm : paymentMethods) {
-      OBDal.getInstance().remove(pm);
-    }
-  }
-}
\ No newline at end of file
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_01.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,236 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-public class PaymentTest_01 extends OBBaseTest {
-
-  private static final Logger log = Logger.getLogger(PaymentTest_01.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_01";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   *  
-   * This before method is named setUpP01() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP01() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  @Test
-  public void testRunPayment_01() {
-    boolean exception = false;
-    Invoice invoice = null;
-    FIN_Payment payment = null;
-
-    try {
-
-      // DATA SETUP
-      invoice = dataSetup();
-
-      // PAY COMPLETELY THE INVOICE
-      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-      payment = TestUtility.addPaymentFromInvoice(invoice,
-          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
-          invoice.getGrandTotalAmount(), false);
-
-      // PROCESS THE PAYMENT
-      TestUtility.processPayment(payment, "P");
-
-      // CHECK OUTPUT DATA
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue(
-            "Payment Schedule Outstanding Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) == 0);
-        assertTrue(
-            "Payment Schedule Received Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Deatail Amount != Total Amount", invoice.getGrandTotalAmount()
-            .compareTo(psd.getAmount()) == 0);
-        assertTrue("Payment Schedule Detail Write-off Amount != 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
-        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
-        assertTrue("Payment Line Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(psd.getPaymentDetails().getAmount()) == 0);
-        assertTrue("Payment Line Write-off Amount != 0",
-            BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-      // REACTIVATE
-      TestUtility.processPayment(payment, "R");
-
-      // CHECK OUTPUT DATA AFTER REACTIVATION
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue(
-            "Expected Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
-        assertTrue(
-            "Outstanding Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Received Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Deatail Amount != 0",
-            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
-        assertTrue("Payment Schedule Detail Write-off Amount != 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
-        assertTrue("Status != Awaiting Payment", "RPAP".equals(payment.getStatus()));
-
-        assertTrue("There are Payment Lines for this payment",
-            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
-                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
-    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
-    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
-    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
-    BigDecimal invoicedQuantity = new BigDecimal("5");
-    BigDecimal netUnitPrice = new BigDecimal("2.04");
-    BigDecimal netListPrice = new BigDecimal("2.04");
-    BigDecimal lineNetAmount = new BigDecimal("10.20");
-    BigDecimal priceLimit = new BigDecimal("1");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
-        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
-        null, true, true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
-        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processInvoice(invoice);
-
-    return invoice;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_02.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,238 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-/**
- * The PaymentTest_02 class used to test the partial payment document generation and reactivating
- * the in APRM.
- * 
- */
-public class PaymentTest_02 extends OBBaseTest {
-
-  private static final Logger log = Logger.getLogger(PaymentTest_01.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_02";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP02() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP02() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  public void testRunPayment_02() {
-    boolean exception = false;
-    Invoice invoice = null;
-    FIN_Payment payment = null;
-
-    try {
-
-      // DATA SETUP
-      invoice = dataSetup();
-
-      // PAY PARTIALLY THE INVOICE
-      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-      BigDecimal divisor = new BigDecimal("2.0");
-      BigDecimal paymentAmount = invoice.getGrandTotalAmount().divide(divisor, 2);
-      payment = TestUtility.addPaymentFromInvoice(invoice,
-          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
-          false);
-
-      // PROCESS THE PAYMENT
-      TestUtility.processPayment(payment, "P");
-
-      // CHECK OUTPUT DATA
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue("Payment Schedule Outstanding Amount ("
-            + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
-            + ") != " + paymentAmount.toPlainString(), invoice.getFINPaymentScheduleList().get(0)
-            .getOutstandingAmount().compareTo(paymentAmount) == 0);
-
-        assertTrue(
-            "Payment Schedule Received Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) != 0);
-
-        assertTrue("Payment Schedule Deatail Amount != Total Amount", invoice.getGrandTotalAmount()
-            .compareTo(psd.getAmount()) != 0);
-
-        assertTrue("Payment Schedule Detail Write-off Amount == 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) != 0);
-        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-      // REACTIVATE
-      TestUtility.processPayment(payment, "R");
-
-      // CHECK OUTPUT DATA AFTER REACTIVATION
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue(
-            "Expected Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
-        assertTrue(
-            "Outstanding Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Received Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Detail Amount != 0",
-            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
-        assertTrue("Payment Schedule Detail Write-off Amount == 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
-        assertTrue("Status != Awaiting Payment", "RPAP".equals(payment.getStatus()));
-
-        assertTrue("There are Payment Lines for this payment",
-            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
-                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
-    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
-    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
-    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
-    BigDecimal invoicedQuantity = new BigDecimal("5");
-    BigDecimal netUnitPrice = new BigDecimal("2");
-    BigDecimal netListPrice = new BigDecimal("2");
-    BigDecimal lineNetAmount = new BigDecimal("1");
-    BigDecimal priceLimit = new BigDecimal("1");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
-        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
-        null, true, true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
-        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processInvoice(invoice);
-
-    return invoice;
-  }
-
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_03.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,236 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-/**
- * The PaymentTest_03 class used to test the payment document generation and reactivation with
- * write-off option.
- */
-public class PaymentTest_03 extends OBBaseTest {
-
-  private static final Logger log = Logger.getLogger(PaymentTest_01.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_03";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP03() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP03() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  @Test
-  public void testRunPayment_03() {
-    boolean exception = false;
-    Invoice invoice = null;
-    FIN_Payment payment = null;
-
-    try {
-
-      // DATA SETUP
-      invoice = dataSetup();
-
-      // PAY PARTIALLY THE INVOICE
-      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-      BigDecimal writeOffAmt = new BigDecimal("2.0");
-      BigDecimal paymentAmount = invoice.getGrandTotalAmount().subtract(writeOffAmt);
-      payment = TestUtility.addPaymentFromInvoice(invoice,
-          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
-          true);
-
-      // PROCESS THE PAYMENT
-      TestUtility.processPayment(payment, "P");
-
-      // CHECK OUTPUT DATA
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue("Payment Schedule Outstanding Amount != 0", invoice.getFINPaymentScheduleList()
-            .get(0).getOutstandingAmount().compareTo(psd.getAmount()) != 0);
-
-        assertTrue(
-            "Payment Schedule Received Amount == Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Detail Amount != Total Amount", invoice.getGrandTotalAmount()
-            .compareTo(psd.getAmount()) != 0);
-
-        assertTrue("Payment Schedule Detail Write-off Amount != 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) != 0);
-
-        assertTrue("Payment Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) != 0);
-        assertTrue("Status == Payment Received", "RPR".equals(payment.getStatus()));
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-      // REACTIVATE
-      TestUtility.processPayment(payment, "R");
-
-      // CHECK OUTPUT DATA AFTER REACTIVATION
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue(
-            "Expected Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
-        assertTrue(
-            "Outstanding Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Received Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Detail Amount != 0",
-            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
-        assertTrue("Payment Schedule Detail Write-off Amount == 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
-        assertTrue("Status != Awaiting Payment", "RPAP".equals(payment.getStatus()));
-
-        assertTrue("There are Payment Lines for this payment",
-            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
-                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
-    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
-    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
-    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
-    BigDecimal invoicedQuantity = new BigDecimal("5");
-    BigDecimal netUnitPrice = new BigDecimal("2.04");
-    BigDecimal netListPrice = new BigDecimal("2.04");
-    BigDecimal lineNetAmount = new BigDecimal("10.20");
-    BigDecimal priceLimit = new BigDecimal("1");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
-        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
-        null, true, true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
-        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processInvoice(invoice);
-
-    return invoice;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_04.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,215 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-/**
- * The PaymentTest_04 class used to test the payment document generation with Refund option.
- */
-public class PaymentTest_04 extends OBBaseTest {
-
-  private static final Logger log = Logger.getLogger(PaymentTest_04.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_04";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP04() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP04() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  @Test
-  public void testRunPayment_04() {
-    boolean exception = false;
-    Invoice invoice = null;
-    FIN_Payment payment = null;
-
-    try {
-
-      // DATA SETUP
-      invoice = dataSetup();
-
-      // PAY PARTIALLY THE INVOICE
-      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-      BigDecimal refundAmt = new BigDecimal("20.0");
-      BigDecimal paymentAmount = invoice.getGrandTotalAmount();
-      payment = TestUtility.addPaymentFromInvoice(invoice,
-          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
-          false);
-
-      // PROCESS THE PAYMENT
-      TestUtility.processPayment(payment, "P");
-
-      // REFUNDING THE PAYMENT
-      FIN_Payment refundPayment = TestUtility.createRefundPayment(payment, refundAmt);
-
-      OBContext.setAdminMode();
-      try {
-        // PROCESSING THE REFUND PAYMENT
-        TestUtility.processPayment(refundPayment, "P");
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-      // CHECK OUTPUT DATA
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue("Payment Schedule Outstanding Amount == 0", invoice.getFINPaymentScheduleList()
-            .get(0).getOutstandingAmount().compareTo(psd.getAmount()) != 0);
-
-        assertTrue(
-            "Payment Schedule Received Amount == Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Detail Amount == Total Amount", invoice.getGrandTotalAmount()
-            .compareTo(psd.getAmount()) == 0);
-
-        assertTrue("Payment Schedule Detail Write-off Amount == 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount == Total Amount",
-            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
-        assertTrue("Status == Payment Received", "RPR".equals(payment.getStatus()));
-
-        assertTrue("Payment Amount == Refund Amount",
-            refundAmt.negate().compareTo(refundPayment.getAmount()) == 0);
-
-        assertTrue("Payment Used Credit == Used Credit",
-            refundAmt.compareTo(refundPayment.getUsedCredit()) == 0);
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
-    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
-    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
-    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
-    BigDecimal invoicedQuantity = new BigDecimal("5");
-    BigDecimal netUnitPrice = new BigDecimal("2.04");
-    BigDecimal netListPrice = new BigDecimal("2.04");
-    BigDecimal lineNetAmount = new BigDecimal("10.20");
-    BigDecimal priceLimit = new BigDecimal("1");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
-        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
-        null, true, true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
-        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processInvoice(invoice);
-
-    return invoice;
-  }
-}
\ No newline at end of file
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_05.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,205 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
-import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentProposal;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-/**
- * The PaymentTest_03 class used to test the payment document generation and reactivation with
- * write-off option.
- */
-public class PaymentTest_05 extends OBBaseTest {
-
-  private static final Logger log = Logger.getLogger(PaymentTest_05.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_05";
-
-  private String financialAccountId;
-  private String paymentMethodId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP05() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP05() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  /**
-   * Payment Proposal with two invoices of different business partner partially paid.
-   */
-  @Test
-  public void testRunPayment_05() {
-    String fruitBio = "8A64B71A2B0B2946012B0FE1E45F01B0";
-    String happyDrinks = "8A64B71A2B0B2946012B0FE1E37001AB";
-    String currencyId = "102"; // EUR
-    Invoice inv1;
-    Invoice inv2;
-    AdvPaymentMngtDao dao = new AdvPaymentMngtDao();
-    boolean exception = false;
-
-    try {
-      inv1 = createPurchaseInvoice(fruitBio);
-      inv2 = createPurchaseInvoice(happyDrinks);
-
-      inv1 = OBDal.getInstance().get(Invoice.class, inv1.getId());
-      inv2 = OBDal.getInstance().get(Invoice.class, inv2.getId());
-
-      FIN_PaymentProposal paymentProposal = TestUtility.createNewPaymentProposal(OBContext
-          .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(),
-          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), OBDal
-              .getInstance().get(Currency.class, currencyId),
-          OBDal.getInstance().get(FIN_PaymentMethod.class, paymentMethodId));
-
-      List<FIN_PaymentScheduleDetail> scheduleDetails1 = dao
-          .getInvoicePendingScheduledPaymentDetails(inv1);
-      List<FIN_PaymentScheduleDetail> scheduleDetails2 = dao
-          .getInvoicePendingScheduledPaymentDetails(inv2);
-
-      List<FIN_PaymentScheduleDetail> mergeScheduleDetails = new ArrayList<FIN_PaymentScheduleDetail>();
-      mergeScheduleDetails.add(scheduleDetails1.get(0));
-      mergeScheduleDetails.add(scheduleDetails2.get(0));
-
-      HashMap<String, BigDecimal> amounts = new HashMap<String, BigDecimal>();
-      amounts.put(scheduleDetails1.get(0).getId(), new BigDecimal("5"));
-      amounts.put(scheduleDetails2.get(0).getId(), new BigDecimal("5"));
-
-      OBContext.setAdminMode(true);
-      try {
-        // ORA-01779: cannot modify a column which maps to a non key-preserved table
-        FIN_AddPayment.savePaymentProposal(paymentProposal, new BigDecimal("10"),
-            mergeScheduleDetails, amounts, null);
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-      TestUtility.processPaymentProposal(paymentProposal, "GSP");
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice createPurchaseInvoice(String businessPartnerId) throws Exception {
-
-    // DATA SETUP
-    String priceListId = "8A64B71A2B0B2946012B0BD96C470131"; // Happy Drinks Price List
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
-    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
-    String docTypeId = "71F835BC045742ADAAF5B6856914BB26"; // US AP Invoice
-    BigDecimal invoicedQuantity = new BigDecimal("5");
-    BigDecimal netUnitPrice = new BigDecimal("1.36");
-    BigDecimal netListPrice = new BigDecimal("1.36");
-    BigDecimal lineNetAmount = new BigDecimal("6.80");
-    BigDecimal priceLimit = new BigDecimal("1");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance().get(BusinessPartner.class,
-        businessPartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
-        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
-        null, true, true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
-        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-
-    this.financialAccountId = testAccount.getId();
-    this.paymentMethodId = testPaymentMethod.getId();
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, false);
-
-    TestUtility.processInvoice(invoice);
-
-    return invoice;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_06.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,247 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-/**
- * The PaymentTest_06 class used to test the payment document generation with execution process.
- */
-public class PaymentTest_06 extends OBBaseTest {
-
-  private static final Logger log = Logger.getLogger(PaymentTest_06.class);
-
-  private static final String AUTOMATIC_EXECUTION = "A";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_06";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP06() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP06() throws Exception {
-    TestUtility.setTestContext();
-  }
-
-  @Test
-  public void testRunPayment_06() {
-    boolean exception = false;
-    Invoice invoice = null;
-    FIN_Payment payment = null;
-
-    try {
-
-      // DATA SETUP
-      invoice = dataSetup();
-
-      // PAY COMPLETELY THE INVOICE
-      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-      payment = TestUtility.addPaymentFromInvoice(invoice,
-          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
-          invoice.getGrandTotalAmount(), false);
-
-      // PROCESS THE PAYMENT
-      TestUtility.processPayment(payment, "P");
-
-      // CHECK OUTPUT DATA
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue(
-            "Payment Schedule Outstanding Amount ("
-                + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
-                + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Payment Schedule Received Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Detail Amount != Total Amount", invoice.getGrandTotalAmount()
-            .compareTo(psd.getAmount()) == 0);
-        assertTrue("Payment Schedule Detail Write-off Amount != 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
-        assertTrue("Status != Receivable Payables Awaiting  Execution",
-            "RPAE".equals(payment.getStatus()));
-        assertTrue("Payment Line Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(psd.getPaymentDetails().getAmount()) == 0);
-        assertTrue("Payment Line Write-off Amount != 0",
-            BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-      // REACTIVATE
-      TestUtility.processPayment(payment, "R");
-
-      // CHECK OUTPUT DATA AFTER REACTIVATION
-      OBContext.setAdminMode();
-      try {
-        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                .getFINPaymentScheduleList().get(0)));
-
-        assertTrue(
-            "Expected Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
-        assertTrue(
-            "Outstanding Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Received Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-        assertTrue("Payment Schedule Deatail Amount != 0",
-            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
-        assertTrue("Payment Schedule Detail Write-off Amount != 0",
-            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
-        assertTrue("Status != Receivable Payment Awaiting Payment",
-            "RPAP".equals(payment.getStatus()));
-
-        assertTrue("There are Payment Lines for this payment",
-            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
-                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
-    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
-    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
-    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
-    BigDecimal invoicedQuantity = new BigDecimal("5");
-    BigDecimal netUnitPrice = new BigDecimal("2.04");
-    BigDecimal netListPrice = new BigDecimal("2.04");
-    BigDecimal lineNetAmount = new BigDecimal("10.20");
-    BigDecimal priceLimit = new BigDecimal("1");
-    String executionProcessId = "717D521D5F454FAD9199B831001BB4E0"; // Simple Execution Process
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-    PaymentExecutionProcess pmtExecProcess = OBDal.getInstance().get(PaymentExecutionProcess.class,
-        executionProcessId);
-
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_02",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
-        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
-        null, true, true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_02",
-        STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION, pmtExecProcess, true,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false,
-        AUTOMATIC_EXECUTION, pmtExecProcess, true, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT,
-        CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processInvoice(invoice);
-
-    return invoice;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_07.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,338 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2011-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.process.FIN_ExecutePayment;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.utility.OBError;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.enterprise.Warehouse;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.invoice.InvoiceLine;
-import org.openbravo.model.common.order.Order;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-public class PaymentTest_07 extends OBBaseTest {
-
-  // 1) Create an order with discount
-  // 2) Add a partial payment but do not execute it
-  // 3) Invoice the complete order (without discount) using an automatic receipt payment method
-  // 4) Review payment info
-  // 5) Execute payment
-  // 6) Review payment info
-
-  private static final Logger log = Logger.getLogger(PaymentTest_07.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String AUTOMATIC_EXECUTION = "A";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_07";
-  private static final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP07() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP07() throws Exception {
-    TestUtility.setTestContextSpain();
-  }
-
-  @Test
-  public void testRunPayment_07() {
-    boolean exception = false;
-    try {
-      OBContext.setAdminMode();
-      try {
-        // DATA SETUP
-        Invoice invoice = dataSetup();
-        FIN_Payment payment = null;
-        for (FIN_PaymentScheduleDetail psd : invoice.getFINPaymentScheduleList().get(0)
-            .getFINPaymentScheduleDetailInvoicePaymentScheduleList()) {
-          if ("RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
-            payment = psd.getPaymentDetails().getFinPayment();
-          }
-        }
-        FIN_ExecutePayment executePayment = new FIN_ExecutePayment();
-        List<FIN_Payment> payments = new ArrayList<FIN_Payment>();
-        payments.add(payment);
-        executePayment.init("OTHER",
-            OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS),
-            payments, null, payment.getOrganization());
-        OBError result = executePayment.execute();
-        // CHECK PAYMENT EXECUTION
-        assertTrue("Payment error while executing", !"Error".equals(result.getType()));
-
-        Order order = invoice.getSalesOrder();
-        // CHECK OUTPUT DATA ORDER
-        assertTrue(
-            "Order Payment Schedule Outstanding Amount ("
-                + order.getFINPaymentScheduleList().get(0).getOutstandingAmount() + ") != 0",
-            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) == 0);
-        assertTrue(
-            "Order Payment Schedule Received Amount ("
-                + getPaidAmount(order.getFINPaymentScheduleList()).toPlainString()
-                + ") != Total Amount (" + order.getGrandTotalAmount().toPlainString(),
-            order.getGrandTotalAmount().compareTo(getPaidAmount(order.getFINPaymentScheduleList())) == 0);
-        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
-        // CHECK OUTPUT DATA INVOICE
-        assertTrue(
-            "Invoice Payment Schedule Outstanding Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) == 0);
-        assertTrue("Invoice remains not paid", invoice.isPaymentComplete());
-        assertTrue(
-            "Invoice Payment Schedule Received Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
-        // CHECK OUTPUT DATA PAYMENT
-        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E8B50200"; // Alimentos y Supermercados, S.A.
-    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
-    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
-    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
-    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
-    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
-
-    // Process
-    BigDecimal quantity = new BigDecimal("10");
-    BigDecimal invoicedQuantity = new BigDecimal("10");
-    BigDecimal netUnitPrice = new BigDecimal("10");
-    BigDecimal netListPrice = new BigDecimal("10");
-    BigDecimal lineNetAmount = new BigDecimal("100");
-    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
-    BigDecimal priceLimit = new BigDecimal("10");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-    DocumentType testOrderDocumentType = OBDal.getInstance()
-        .get(DocumentType.class, orderDocTypeId);
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_07",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
-        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
-        true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_07",
-        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
-        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
-    testBusinessPartner.setAccount(testAccount);
-    OBDal.getInstance().save(testBusinessPartner);
-
-    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
-    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
-        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
-        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processOrder(order);
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
-              .getFINPaymentScheduleList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount == 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount == 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
-        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
-        order.getGrandTotalAmount(), false);
-
-    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
-        "APRM_PM_PAYMENT_07_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
-        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
-        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
-
-    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
-    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
-    payment.setPaymentMethod(awaitingExecutionPM);
-    OBDal.getInstance().save(payment);
-    // PROCESS THE PAYMENT
-    TestUtility.processPayment(payment, "P");
-    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
-      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment
-              .getFINPaymentDetailList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount != Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount != 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount != Total Amount", order.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount != 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
-      assertTrue("Payment Line Write-off Amount != 0",
-          BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    // This created order is invoiced
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
-    OBDal.getInstance().refresh(invoice);
-    // Order is associated both to header and lines
-    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
-    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
-
-    OBDal.getInstance().save(invoiceLine);
-
-    invoice.setSalesOrder(order);
-
-    OBDal.getInstance().save(invoice);
-
-    TestUtility.processInvoice(invoice);
-    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-    return invoice;
-  }
-
-  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
-    BigDecimal amount = BigDecimal.ZERO;
-    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
-      boolean isInvoice = ps.getInvoice() != null;
-      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
-          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
-          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
-        if (psd.getPaymentDetails() != null
-            && psd.getPaymentDetails().getFinPayment().isProcessed()
-            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
-          amount = amount.add(psd.getAmount());
-        }
-      }
-    }
-    return amount;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_08.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,317 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2011-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.base.provider.OBProvider;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.enterprise.Warehouse;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.invoice.InvoiceDiscount;
-import org.openbravo.model.common.invoice.InvoiceLine;
-import org.openbravo.model.common.order.Order;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-public class PaymentTest_08 extends OBBaseTest {
-
-  // 1) Create an order
-  // 2) Add a partial payment but do not execute it
-  // 3) Invoice the order partially using an automatic receipt payment method
-  // 4)Review payment info
-
-  private static final Logger log = Logger.getLogger(PaymentTest_08.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String AUTOMATIC_EXECUTION = "A";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_08";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP08() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP08() throws Exception {
-    TestUtility.setTestContextSpain();
-  }
-
-  @Test
-  public void testRunPayment_08() {
-    boolean exception = false;
-    try {
-      // DATA SETUP
-      Invoice invoice = dataSetup();
-      Order order = invoice.getSalesOrder();
-      // CHECK OUTPUT DATA
-      OBContext.setAdminMode();
-      try {
-        assertTrue(
-            "Invoice Payment Schedule Outstanding Amount == 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) != 0);
-        assertTrue("Invoice Payment Schedule  not Total Pending", invoice.getGrandTotalAmount()
-            .compareTo(invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Invoice Payment Schedule Paid Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-        assertTrue(
-            "Order Payment Schedule Outstanding Amount == 0",
-            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) != 0);
-        assertTrue("Order Payment Schedule not Total Pending", invoice.getGrandTotalAmount()
-            .compareTo(invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Order Payment Schedule Paid Amount != 0",
-            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E8B50200"; // Alimentos y Supermercados, S.A.
-    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
-    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
-    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
-    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
-    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
-    final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0"; // Simple Execution
-    // Process
-    BigDecimal quantity = new BigDecimal("10");
-    BigDecimal invoicedQuantity = new BigDecimal("5");
-    BigDecimal netUnitPrice = new BigDecimal("10");
-    BigDecimal netListPrice = new BigDecimal("10");
-    BigDecimal lineNetAmount = new BigDecimal("100");
-    BigDecimal invoiceLineNetAmount = new BigDecimal("50");
-    BigDecimal priceLimit = new BigDecimal("10");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-    DocumentType testOrderDocumentType = OBDal.getInstance()
-        .get(DocumentType.class, orderDocTypeId);
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_08",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
-        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
-        true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_08",
-        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
-        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
-    testBusinessPartner.setAccount(testAccount);
-    OBDal.getInstance().save(testBusinessPartner);
-
-    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
-    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
-        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
-        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processOrder(order);
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
-              .getFINPaymentScheduleList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount == 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount == 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
-        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
-        order.getGrandTotalAmount(), false);
-
-    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
-        "APRM_PM_PAYMENT_08_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
-        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
-        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
-
-    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
-    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
-    payment.setPaymentMethod(awaitingExecutionPM);
-    OBDal.getInstance().save(payment);
-    // PROCESS THE PAYMENT
-    TestUtility.processPayment(payment, "P");
-    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
-      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
-              .getFINPaymentScheduleList().get(0)));
-      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount == 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount == 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    // This created order is PARTIALLY invoiced
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
-    OBDal.getInstance().refresh(invoice);
-    // Order is associated both to header and lines
-    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
-    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
-
-    OBDal.getInstance().save(invoiceLine);
-
-    invoice.setSalesOrder(order);
-
-    OBDal.getInstance().save(invoice);
-
-    // Add invoice Discount
-    InvoiceDiscount invoiceDiscount = OBProvider.getInstance().get(InvoiceDiscount.class);
-    invoiceDiscount.setInvoice(invoice);
-    invoiceDiscount.setLineNo(10l);
-    invoiceDiscount.setDiscount(order.getOrderDiscountList().get(0).getDiscount());
-    OBDal.getInstance().save(invoiceDiscount);
-
-    TestUtility.processInvoice(invoice);
-    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-    // CHECK OUTPUT DATA FOR INVOICE
-    OBContext.setAdminMode();
-    try {
-      // CHECK OUTPUT DATA FOR INVOICE
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-              .getFINPaymentScheduleList().get(0)));
-      assertTrue(
-          "Payment Schedule Outstanding Amount == Order amount",
-          invoice.getGrandTotalAmount().compareTo(
-              invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue(
-          "Payment Schedule Received Amount == 0",
-          BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount == Total Amount", invoice.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount == 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    return invoice;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_09.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,349 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2011-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.process.FIN_ExecutePayment;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.base.provider.OBProvider;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.utility.OBError;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.enterprise.Warehouse;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.invoice.InvoiceDiscount;
-import org.openbravo.model.common.invoice.InvoiceLine;
-import org.openbravo.model.common.order.Order;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.discount.Discount;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-public class PaymentTest_09 extends OBBaseTest {
-
-  // 1) Create an order without discount
-  // 2) Add a partial payment but do not execute it
-  // 3) Invoice the complete order (with discount) using an automatic receipt payment method
-  // 4) Review payment info
-  // 5) Execute payment
-  // 6) Review payment info
-
-  private static final Logger log = Logger.getLogger(PaymentTest_09.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String AUTOMATIC_EXECUTION = "A";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_09";
-  private static final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP09() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP09() throws Exception {
-    TestUtility.setTestContextSpain();
-  }
-
-  @Test
-  public void testRunPayment_09() {
-    boolean exception = false;
-    try {
-      OBContext.setAdminMode();
-      try {
-        // DATA SETUP
-        Invoice invoice = dataSetup();
-        FIN_Payment payment = null;
-        for (FIN_PaymentScheduleDetail psd : invoice.getFINPaymentScheduleList().get(0)
-            .getFINPaymentScheduleDetailInvoicePaymentScheduleList()) {
-          if ("RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
-            payment = psd.getPaymentDetails().getFinPayment();
-          }
-        }
-        FIN_ExecutePayment executePayment = new FIN_ExecutePayment();
-        List<FIN_Payment> payments = new ArrayList<FIN_Payment>();
-        payments.add(payment);
-        executePayment.init("OTHER",
-            OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS),
-            payments, null, payment.getOrganization());
-        OBError result = executePayment.execute();
-
-        // CHECK PAYMENT EXECUTION
-        assertTrue("Payment error while executing", !"Error".equals(result.getType()));
-        Order order = invoice.getSalesOrder();
-        // CHECK OUTPUT DATA ORDER
-        assertTrue(
-            "Order Payment Schedule Outstanding Amount ("
-                + order.getFINPaymentScheduleList().get(0).getOutstandingAmount() + ")!= 0",
-            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) == 0);
-        // CHECK OUTPUT DATA INVOICE
-        assertTrue(
-            "Invoice Payment Schedule Outstanding Amount ("
-                + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount() + ") != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) == 0);
-        assertTrue("Invoice remains not paid", invoice.isPaymentComplete());
-        assertTrue(
-            "Invoice Payment Schedule Received Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
-        // CHECK OUTPUT DATA PAYMENT
-        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E86301FA"; // Hoteles Buenas Noches, S.A.
-    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
-    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
-    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
-    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
-    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
-    String discountId = "831A7639FBE348B1A06EA3C0B0616B75"; // Descuento 10%
-
-    // Process
-    BigDecimal quantity = new BigDecimal("10");
-    BigDecimal invoicedQuantity = new BigDecimal("10");
-    BigDecimal netUnitPrice = new BigDecimal("10");
-    BigDecimal netListPrice = new BigDecimal("10");
-    BigDecimal lineNetAmount = new BigDecimal("100");
-    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
-    BigDecimal paymentAmount = new BigDecimal("50");
-    BigDecimal priceLimit = new BigDecimal("10");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-    DocumentType testOrderDocumentType = OBDal.getInstance()
-        .get(DocumentType.class, orderDocTypeId);
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_09",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
-        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
-        true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_09",
-        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
-        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
-    testBusinessPartner.setAccount(testAccount);
-    OBDal.getInstance().save(testBusinessPartner);
-
-    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
-    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
-        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
-        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    // OrderDiscount oDiscount = order.getOrderDiscountList().get(0);
-    // Discount discount = oDiscount.getDiscount();
-    // order.setOrderDiscountList(null);
-    // OBDal.getInstance().remove(oDiscount);
-    // OBDal.getInstance().save(order);
-
-    TestUtility.processOrder(order);
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
-              .getFINPaymentScheduleList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount == 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount == 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
-        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
-        false);
-
-    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
-        "APRM_PM_PAYMENT_09_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
-        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
-        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
-
-    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
-    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
-    payment.setPaymentMethod(awaitingExecutionPM);
-    OBDal.getInstance().save(payment);
-    // PROCESS THE PAYMENT
-    TestUtility.processPayment(payment, "P");
-    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
-    order = OBDal.getInstance().get(Order.class, order.getId());
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
-      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment
-              .getFINPaymentDetailList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount != Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount != 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Detail Write-off Amount != 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
-      assertTrue("Payment Line Write-off Amount != 0",
-          BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    // This created order is invoiced
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
-    OBDal.getInstance().refresh(invoice);
-    // Order is associated both to header and lines
-    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
-    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
-
-    OBDal.getInstance().save(invoiceLine);
-
-    invoice.setSalesOrder(order);
-
-    OBDal.getInstance().save(invoice);
-
-    // Add invoice Discount
-    Discount discount = OBDal.getInstance().get(Discount.class, discountId);
-    InvoiceDiscount invoiceDiscount = OBProvider.getInstance().get(InvoiceDiscount.class);
-    invoiceDiscount.setInvoice(invoice);
-    invoiceDiscount.setLineNo(10l);
-    invoiceDiscount.setDiscount(discount);
-    OBDal.getInstance().save(invoiceDiscount);
-
-    TestUtility.processInvoice(invoice);
-    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-    return invoice;
-  }
-
-  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
-    BigDecimal amount = BigDecimal.ZERO;
-    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
-      boolean isInvoice = ps.getInvoice() != null;
-      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
-          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
-          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
-        if (psd.getPaymentDetails() != null
-            && psd.getPaymentDetails().getFinPayment().isProcessed()
-            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
-          amount = amount.add(psd.getAmount());
-        }
-      }
-    }
-    return amount;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_10.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,348 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2011-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.process.FIN_ExecutePayment;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.base.provider.OBProvider;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.utility.OBError;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.enterprise.Warehouse;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.invoice.InvoiceDiscount;
-import org.openbravo.model.common.invoice.InvoiceLine;
-import org.openbravo.model.common.order.Order;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.discount.Discount;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-public class PaymentTest_10 extends OBBaseTest {
-
-  // 1) Create an order without discount
-  // 2) Add a partial payment but do not execute it
-  // 3) Invoice the complete order (with discount) using an automatic receipt payment method
-  // 4) Review payment info
-  // 5) Execute payment
-  // 6) Review payment info
-
-  private static final Logger log = Logger.getLogger(PaymentTest_10.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String AUTOMATIC_EXECUTION = "A";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_10";
-  private static final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP10() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP10() throws Exception {
-    TestUtility.setTestContextSpain();
-  }
-
-  @Test
-  public void testRunPayment_10() {
-    boolean exception = false;
-    try {
-      OBContext.setAdminMode();
-      try {
-        // DATA SETUP
-        Invoice invoice = dataSetup();
-        FIN_Payment payment = null;
-        for (FIN_PaymentScheduleDetail psd : invoice.getFINPaymentScheduleList().get(0)
-            .getFINPaymentScheduleDetailInvoicePaymentScheduleList()) {
-          if ("RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
-            payment = psd.getPaymentDetails().getFinPayment();
-          }
-        }
-
-        FIN_ExecutePayment executePayment = new FIN_ExecutePayment();
-        List<FIN_Payment> payments = new ArrayList<FIN_Payment>();
-        payments.add(payment);
-        executePayment.init("OTHER",
-            OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS),
-            payments, null, payment.getOrganization());
-        OBError result = executePayment.execute();
-        // CHECK PAYMENT EXECUTION
-        assertTrue("Payment error while executing", !"Error".equals(result.getType()));
-
-        Order order = invoice.getSalesOrder();
-        // CHECK OUTPUT DATA ORDER
-        assertTrue(
-            "Order Payment Schedule Outstanding Amount != 0",
-            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) == 0);
-        assertTrue(
-            "Invoice: " + invoice.getDocumentNo() + " Order Payment Schedule Received Amount ("
-                + order.getGrandTotalAmount().toPlainString() + ") != Total Amount ("
-                + getPaidAmount(order.getFINPaymentScheduleList()).toPlainString() + ")",
-            order.getGrandTotalAmount().compareTo(getPaidAmount(order.getFINPaymentScheduleList())) == 0);
-        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
-        // CHECK OUTPUT DATA INVOICE
-        assertTrue(
-            "Invoice Payment Schedule Outstanding Amount != 0",
-            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
-                .getOutstandingAmount()) == 0);
-        assertTrue("Invoice remains not paid", invoice.isPaymentComplete());
-        assertTrue(
-            "Invoice Payment Schedule Received Amount != Total Amount",
-            invoice.getGrandTotalAmount().compareTo(
-                getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
-        // CHECK OUTPUT DATA PAYMENT
-        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E86301FA"; // Hoteles Buenas Noches, S.A.
-    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
-    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
-    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
-    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
-    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
-    String discountId = "831A7639FBE348B1A06EA3C0B0616B75"; // Descuento 10%
-
-    // Process
-    BigDecimal quantity = new BigDecimal("10");
-    BigDecimal invoicedQuantity = new BigDecimal("10");
-    BigDecimal netUnitPrice = new BigDecimal("10");
-    BigDecimal netListPrice = new BigDecimal("10");
-    BigDecimal lineNetAmount = new BigDecimal("100");
-    BigDecimal paymentAmount = new BigDecimal("50");
-    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
-    BigDecimal priceLimit = new BigDecimal("10");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-    DocumentType testOrderDocumentType = OBDal.getInstance()
-        .get(DocumentType.class, orderDocTypeId);
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_10",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
-        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
-        true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_10",
-        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
-        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
-    testBusinessPartner.setAccount(testAccount);
-    OBDal.getInstance().save(testBusinessPartner);
-
-    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
-    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
-        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
-        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processOrder(order);
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
-              .getFINPaymentScheduleList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount == 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount == 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
-        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
-        false);
-
-    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
-        "APRM_PM_PAYMENT_10_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
-        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
-        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
-
-    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
-    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
-    payment.setPaymentMethod(awaitingExecutionPM);
-    OBDal.getInstance().save(payment);
-    // PROCESS THE PAYMENT
-    TestUtility.processPayment(payment, "P");
-    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment
-              .getFINPaymentDetailList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount != Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount != 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount != 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
-      assertTrue("Payment Line Write-off Amount != 0",
-          BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    // This created order is invoiced
-
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
-    OBDal.getInstance().refresh(invoice);
-    // Order is associated both to header and lines
-    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
-    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
-
-    OBDal.getInstance().save(invoiceLine);
-
-    invoice.setSalesOrder(order);
-
-    OBDal.getInstance().save(invoice);
-
-    // Add invoice Discount
-    Discount discount = OBDal.getInstance().get(Discount.class, discountId);
-    InvoiceDiscount invoiceDiscount = OBProvider.getInstance().get(InvoiceDiscount.class);
-    invoiceDiscount.setInvoice(invoice);
-    invoiceDiscount.setLineNo(10l);
-    invoiceDiscount.setDiscount(discount);
-    OBDal.getInstance().save(invoiceDiscount);
-
-    TestUtility.processInvoice(invoice);
-    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-
-    return invoice;
-  }
-
-  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
-    BigDecimal amount = BigDecimal.ZERO;
-    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
-      boolean isInvoice = ps.getInvoice() != null;
-      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
-          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
-          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
-        if (psd.getPaymentDetails() != null
-            && psd.getPaymentDetails().getFinPayment().isProcessed()
-            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
-          amount = amount.add(psd.getAmount());
-        }
-      }
-    }
-    return amount;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/PaymentTest_11.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,306 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2011-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.businesspartner.Location;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.enterprise.Warehouse;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.invoice.InvoiceLine;
-import org.openbravo.model.common.order.Order;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.test.base.OBBaseTest;
-
-public class PaymentTest_11 extends OBBaseTest {
-
-  // 1) Create an order without discount
-  // 2) Invoice the complete order (without discount)
-  // 3) Review payment plan info
-  // 4) Receive and process a payment against the invoice for the full amount
-  // 5) Review payment info
-
-  private static final Logger log = Logger.getLogger(PaymentTest_10.class);
-
-  private static final String MANUAL_EXECUTION = "M";
-  private static final String CLEARED_ACCOUNT = "CLE";
-  private static final String IN_TRANSIT_ACCOUNT = "INT";
-  private static final String WITHDRAWN_ACCOUNT = "WIT";
-  private static final String DEPOSIT_ACCOUNT = "DEP";
-  private static final String CASH = "C";
-  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_10";
-
-  private String financialAccountId;
-
-  /**
-   * Initial Set up.
-   * 
-   * This before method is named setUpP11() to avoid overwriting the super 
-   * setUp method that is invoke automatically before this one.
-   * 
-   */
-  @Before
-  public void setUpP11() throws Exception {
-    TestUtility.setTestContextSpain();
-  }
-
-  @Test
-  public void testRunPayment_11() {
-    boolean exception = false;
-    FIN_Payment payment = null;
-    try {
-      OBContext.setAdminMode();
-      try {
-        // DATA SETUP
-        Invoice invoice = dataSetup();
-        Order order = invoice.getSalesOrder();
-
-        // CHECK OUTPUT DATA ORDER
-        assertTrue(
-            "Order Payment Schedule Outstanding Amount ("
-                + order.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
-                + ") != Total Amount (" + order.getGrandTotalAmount().toPlainString() + ")",
-            order.getGrandTotalAmount().compareTo(
-                order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue(
-            "Order Payment Schedule Received Amount ("
-                + getPaidAmount(order.getFINPaymentScheduleList()).toPlainString() + ") != 0",
-            BigDecimal.ZERO.compareTo(getPaidAmount(order.getFINPaymentScheduleList())) == 0);
-
-        // CHECK OUTPUT DATA INVOICE
-        assertTrue(
-            "Invoice Payment Schedule Outstanding Amount ("
-                + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
-                + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
-            invoice.getGrandTotalAmount().compareTo(
-                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-        assertTrue("Invoice is paid", !invoice.isPaymentComplete());
-        assertTrue(
-            "Invoice Payment Schedule Received Amount "
-                + getPaidAmount(invoice.getFINPaymentScheduleList()) + " != 0",
-            BigDecimal.ZERO.compareTo(getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
-
-        payment = TestUtility.addPaymentFromInvoice(invoice,
-            OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
-            invoice.getGrandTotalAmount(), false);
-        TestUtility.processPayment(payment, "P");
-
-        // CHECK OUTPUT DATA PAYMENT
-        OBContext.setAdminMode();
-        try {
-          FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(
-              FIN_PaymentScheduleDetail.class, new Value(
-                  FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
-                      .getFINPaymentScheduleList().get(0)));
-
-          assertTrue(
-              "Payment Schedule Outstanding Amount ("
-                  + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()
-                      .toPlainString() + ") != 0",
-              BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
-                  .getOutstandingAmount()) == 0);
-
-          assertTrue(
-              "Payment Schedule Received Amount ("
-                  + invoice.getFINPaymentScheduleList().get(0).getPaidAmount().toPlainString()
-                  + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
-              invoice.getGrandTotalAmount().compareTo(
-                  invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-          assertTrue("Payment Schedule Detail Amount (" + psd.getAmount().toPlainString()
-              + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
-              invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
-
-          assertTrue("Payment Schedule Detail Write-off Amount ("
-              + psd.getWriteoffAmount().toPlainString() + ") != 0",
-              BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-
-          assertTrue("Payment Amount (" + payment.getAmount().toPlainString()
-              + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
-              invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
-
-          assertTrue("Status (" + payment.getStatus() + ") != Payment Received",
-              "RPR".equals(payment.getStatus()));
-
-        } finally {
-          OBContext.restorePreviousMode();
-        }
-
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      log.error(FIN_Utility.getExceptionMessage(e));
-      exception = true;
-    }
-
-    assertFalse(exception);
-
-  }
-
-  private Invoice dataSetup() throws Exception {
-
-    // DATA SETUP
-    String bpartnerId = "8A64B71A2B0B2946012B0FE1E86301FA"; // Hoteles Buenas Noches, S.A.
-    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
-    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
-    String currencyId = "102"; // EUR
-    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
-    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
-    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
-    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
-    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
-    // Process
-    BigDecimal quantity = new BigDecimal("10");
-    BigDecimal invoicedQuantity = new BigDecimal("10");
-    BigDecimal netUnitPrice = new BigDecimal("10");
-    BigDecimal netListPrice = new BigDecimal("10");
-    BigDecimal lineNetAmount = new BigDecimal("100");
-    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
-    BigDecimal priceLimit = new BigDecimal("10");
-
-    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
-    BusinessPartner testBusinessPartner = OBDal.getInstance()
-        .get(BusinessPartner.class, bpartnerId);
-    Location location = TestUtility.getOneInstance(Location.class, new Value(
-        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
-    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
-    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
-    Product testProduct = OBDal.getInstance().get(Product.class, productId);
-    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
-        .getUOM().getName()));
-    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
-    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
-    DocumentType testOrderDocumentType = OBDal.getInstance()
-        .get(DocumentType.class, orderDocTypeId);
-    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_11",
-        STANDARD_DESCRIPTION, testCurrency, CASH, false,
-        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
-        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
-        true);
-
-    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_11",
-        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
-        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
-        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
-
-    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
-        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
-            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
-
-    if (existAssociation == null)
-      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
-    this.financialAccountId = testAccount.getId();
-
-    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
-    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
-        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
-        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
-
-    TestUtility.processOrder(order);
-    order = OBDal.getInstance().get(Order.class, order.getId());
-
-    // CHECK OUTPUT DATA FOR ORDER
-    OBContext.setAdminMode();
-    try {
-      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
-          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
-              .getFINPaymentScheduleList().get(0)));
-
-      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
-          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
-      assertTrue("Payment Schedule Received Amount == 0",
-          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
-
-      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
-          .compareTo(psd.getAmount()) == 0);
-      assertTrue("Payment Schedule Detail Write-off Amount == 0",
-          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-
-    // This created order is invoiced
-    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
-        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
-        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
-        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
-        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
-    OBDal.getInstance().refresh(invoice);
-    // Order is associated both to header and lines
-    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
-    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
-
-    OBDal.getInstance().save(invoiceLine);
-
-    invoice.setSalesOrder(order);
-
-    OBDal.getInstance().save(invoice);
-
-    TestUtility.processInvoice(invoice);
-    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
-    return invoice;
-  }
-
-  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
-    BigDecimal amount = BigDecimal.ZERO;
-    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
-      boolean isInvoice = ps.getInvoice() != null;
-      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
-          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
-          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
-        if (psd.getPaymentDetails() != null
-            && psd.getPaymentDetails().getFinPayment().isProcessed()
-            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
-          amount = amount.add(psd.getAmount());
-        }
-      }
-    }
-    return amount;
-  }
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/TestUtility.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,567 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.hibernate.criterion.Restrictions;
-import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
-import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
-import org.openbravo.advpaymentmngt.utility.FIN_Utility;
-import org.openbravo.base.provider.OBConfigFileProvider;
-import org.openbravo.base.provider.OBProvider;
-import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.base.structure.BaseOBObject;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBCriteria;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.database.ConnectionProvider;
-import org.openbravo.database.ConnectionProviderImpl;
-import org.openbravo.exception.PoolNotFoundException;
-import org.openbravo.model.ad.process.ProcessInstance;
-import org.openbravo.model.ad.system.Client;
-import org.openbravo.model.ad.ui.Process;
-import org.openbravo.model.common.businesspartner.BusinessPartner;
-import org.openbravo.model.common.currency.Currency;
-import org.openbravo.model.common.enterprise.DocumentType;
-import org.openbravo.model.common.enterprise.Organization;
-import org.openbravo.model.common.enterprise.Warehouse;
-import org.openbravo.model.common.geography.Location;
-import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.invoice.InvoiceLine;
-import org.openbravo.model.common.order.Order;
-import org.openbravo.model.common.order.OrderLine;
-import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.uom.UOM;
-import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
-import org.openbravo.model.financialmgmt.payment.FIN_Payment;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentProposal;
-import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
-import org.openbravo.model.financialmgmt.payment.MatchingAlgorithm;
-import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
-import org.openbravo.model.financialmgmt.payment.PaymentTerm;
-import org.openbravo.model.financialmgmt.tax.TaxRate;
-import org.openbravo.model.pricing.pricelist.PriceList;
-import org.openbravo.service.db.CallProcess;
-import org.openbravo.test.base.OBBaseTest;
-
-public class TestUtility extends OBBaseTest {
-
-  private static final Logger log = Logger.getLogger(TestUtility.class);
-
-  public static FIN_FinancialAccount insertFinancialAccount(String name, String description,
-      Currency currency, String type, boolean isDefault, Location location,
-      BusinessPartner businessPartner, String bankCode, String branchCode, String bankControlDigit,
-      String iNeNo, String swiftCode, String accountControlDigit, String partialAccNo,
-      String accountNo, String iban, BigDecimal currentBalance, BigDecimal creditLimit,
-      MatchingAlgorithm matchingAlgorithm, boolean isValid, boolean checkIfExist) {
-
-    if (checkIfExist) {
-      final OBCriteria<FIN_FinancialAccount> obc = OBDal.getInstance().createCriteria(
-          FIN_FinancialAccount.class);
-      obc.add(Restrictions.eq(FIN_FinancialAccount.PROPERTY_NAME, name));
-      if (obc.list() != null && obc.list().size() > 0) {
-        return obc.list().get(0);
-      }
-    }
-
-    FIN_FinancialAccount finAcc = OBProvider.getInstance().get(FIN_FinancialAccount.class);
-
-    finAcc.setName(name);
-    finAcc.setDescription(description);
-    finAcc.setCurrency(currency);
-    finAcc.setType(type);
-    finAcc.setDefault(isDefault);
-    finAcc.setLocationAddress(location);
-    finAcc.setBusinessPartner(businessPartner);
-
-    // Bank
-    finAcc.setBankCode(bankCode);
-    finAcc.setBranchCode(branchCode);
-    finAcc.setBankDigitcontrol(bankControlDigit);
-    finAcc.setINENo(iNeNo);
-    finAcc.setSwiftCode(swiftCode);
-
-    // Bank Account
-    finAcc.setAccountDigitcontrol(accountControlDigit);
-    finAcc.setPartialAccountNo(partialAccNo);
-    finAcc.setAccountNo(accountNo);
-    finAcc.setIBAN(iban);
-
-    // Amounts
-    finAcc.setCurrentBalance(currentBalance);
-    finAcc.setCreditLimit(creditLimit);
-    finAcc.setMatchingAlgorithm(matchingAlgorithm);
-
-    boolean exception = false;
-    try {
-      // force dal commit to throw exception
-      OBDal.getInstance().save(finAcc);
-      OBDal.getInstance().flush();
-      OBDal.getInstance().commitAndClose();
-    } catch (Exception e) {
-      log.error(e);
-      exception = true;
-      OBDal.getInstance().rollbackAndClose();
-    }
-
-    if (isValid)
-      assertFalse("Not inserted a valid financial account:" + name, exception);
-    else
-      assertTrue("Inserted a non-valid financial account:" + name, exception);
-
-    if (exception)
-      return null;
-    else
-      return finAcc;
-  }
-
-  public static FIN_PaymentMethod insertPaymentMethod(String name, String description,
-      boolean isPayInAllowed, boolean isAutomaticReceipt, boolean isAutomaticDeposit,
-      String payInExecutionType, PaymentExecutionProcess payInExecutionProcess,
-      boolean isPayinDeferred, String uponReceiptUse, String uponDepositUse,
-      String inUponClearingUse, boolean isPayOutAllowed, boolean isAutomaticPayment,
-      boolean isAutomaticWithdrawn, String payOutExecutionType,
-      PaymentExecutionProcess payOutExecutionProcess, boolean isPayoutDeferred,
-      String uponPaymentUse, String uponWithdrawalUse, String outUponClearingUse, boolean isValid,
-      boolean checkIfExist) {
-
-    if (checkIfExist) {
-      final OBCriteria<FIN_PaymentMethod> obc = OBDal.getInstance().createCriteria(
-          FIN_PaymentMethod.class);
-      obc.add(Restrictions.eq(FIN_PaymentMethod.PROPERTY_NAME, name));
-      if (obc.list() != null && obc.list().size() > 0) {
-        return obc.list().get(0);
-      }
-    }
-
-    FIN_PaymentMethod paymentMethod = OBProvider.getInstance().get(FIN_PaymentMethod.class);
-
-    paymentMethod.setName(name);
-    paymentMethod.setDescription(description);
-
-    // Payment IN
-    paymentMethod.setPayinAllow(isPayInAllowed);
-    paymentMethod.setAutomaticReceipt(isAutomaticReceipt);
-    paymentMethod.setAutomaticDeposit(isAutomaticDeposit);
-
-    paymentMethod.setPayinExecutionType(payInExecutionType);
-    paymentMethod.setPayinExecutionProcess(payInExecutionProcess);
-    paymentMethod.setPayinDeferred(isPayinDeferred);
-    paymentMethod.setUponReceiptUse(uponReceiptUse);
-    paymentMethod.setUponDepositUse(uponDepositUse);
-    paymentMethod.setINUponClearingUse(inUponClearingUse);
-
-    // Payment OUT
-    paymentMethod.setPayoutAllow(isPayOutAllowed);
-    paymentMethod.setAutomaticPayment(isAutomaticPayment);
-    paymentMethod.setAutomaticWithdrawn(isAutomaticWithdrawn);
-
-    paymentMethod.setPayoutExecutionType(payOutExecutionType);
-    paymentMethod.setPayoutExecutionProcess(payOutExecutionProcess);
-    paymentMethod.setPayoutDeferred(isPayoutDeferred);
-
-    paymentMethod.setUponPaymentUse(uponPaymentUse);
-    paymentMethod.setUponWithdrawalUse(uponWithdrawalUse);
-    paymentMethod.setOUTUponClearingUse(outUponClearingUse);
-
-    OBDal.getInstance().save(paymentMethod);
-
-    boolean exception = false;
-    try {
-      // force dal commit to throw exception
-      OBDal.getInstance().flush();
-      OBDal.getInstance().commitAndClose();
-    } catch (Exception e) {
-      log.error(e);
-      exception = true;
-      OBDal.getInstance().rollbackAndClose();
-    }
-
-    if (isValid)
-      assertFalse("Not inserted a valid payment method:" + name, exception);
-    else
-      assertTrue("Inserted a non-valid payment method:" + name, exception);
-
-    if (exception)
-      return null;
-    else
-      return paymentMethod;
-  }
-
-  public static FinAccPaymentMethod associatePaymentMethod(FIN_FinancialAccount account,
-      FIN_PaymentMethod paymentMethod) {
-    FinAccPaymentMethod accountPay = OBProvider.getInstance().get(FinAccPaymentMethod.class);
-    accountPay.setAccount(account);
-    accountPay.setPaymentMethod(paymentMethod);
-
-    accountPay.setPayoutAllow(paymentMethod.isPayoutAllow());
-    accountPay.setPayoutDeferred(paymentMethod.isPayoutDeferred());
-    accountPay.setPayoutExecutionProcess(paymentMethod.getPayoutExecutionProcess());
-    accountPay.setPayoutExecutionType(paymentMethod.getPayoutExecutionType());
-    accountPay.setAutomaticReceipt(paymentMethod.isAutomaticReceipt());
-    accountPay.setAutomaticDeposit(paymentMethod.isAutomaticDeposit());
-    accountPay.setUponReceiptUse(paymentMethod.getUponReceiptUse());
-    accountPay.setUponDepositUse(paymentMethod.getUponDepositUse());
-    accountPay.setOUTUponClearingUse(paymentMethod.getOUTUponClearingUse());
-
-    accountPay.setPayinAllow(paymentMethod.isPayinAllow());
-    accountPay.setPayinDeferred(paymentMethod.isPayinDeferred());
-    accountPay.setPayinExecutionProcess(paymentMethod.getPayinExecutionProcess());
-    accountPay.setPayinExecutionType(paymentMethod.getPayinExecutionType());
-    accountPay.setAutomaticPayment(paymentMethod.isAutomaticPayment());
-    accountPay.setAutomaticWithdrawn(paymentMethod.isAutomaticWithdrawn());
-    accountPay.setUponPaymentUse(paymentMethod.getUponPaymentUse());
-    accountPay.setUponWithdrawalUse(paymentMethod.getUponWithdrawalUse());
-    accountPay.setINUponClearingUse(paymentMethod.getINUponClearingUse());
-
-    boolean exception = false;
-    try {
-      // force dal commit to throw exception
-      OBDal.getInstance().save(accountPay);
-      OBDal.getInstance().flush();
-    } catch (org.hibernate.exception.GenericJDBCException e) {
-      log.error(e);
-      exception = true;
-      OBDal.getInstance().rollbackAndClose();
-    }
-
-    assertFalse("Not associated a valid payment method to the financial account", exception);
-
-    if (exception)
-      return null;
-    else
-      return accountPay;
-
-  }
-
-  public static Order createNewOrder(Client client, Organization org, Date orderDate,
-      Date accountingDate, Date taxDate, DocumentType documentType, BusinessPartner bp,
-      org.openbravo.model.common.businesspartner.Location loc, Warehouse warehouse,
-      String invoiceTerm, PriceList priceList, Currency currency, FIN_PaymentMethod paymentMethod,
-      PaymentTerm paymentTerm, Product product, UOM uom, BigDecimal orderedQuantity,
-      BigDecimal netUnitPrice, BigDecimal netListPrice, BigDecimal priceLimit, TaxRate taxRate,
-      BigDecimal lineNetAmount, boolean isReceipt) throws Exception {
-
-    // Create header
-    Order order = OBProvider.getInstance().get(Order.class);
-    order.setOrganization(org);
-    order.setClient(client);
-    order.setDocumentType(documentType);
-    order.setTransactionDocument(documentType);
-    order.setDocumentNo(FIN_Utility.getDocumentNo(org, "SOO", "C_Order"));
-    order.setAccountingDate(accountingDate);
-    order.setOrderDate(orderDate);
-    order.setWarehouse(warehouse);
-    if (!"".equals(invoiceTerm)) {
-      order.setInvoiceTerms(invoiceTerm);
-    }
-    // order.setTaxDate(taxDate);
-    order.setBusinessPartner(bp);
-    order.setPartnerAddress(loc);
-    order.setPriceList(priceList);
-    order.setCurrency(currency);
-    order.setSummedLineAmount(BigDecimal.ZERO);
-    order.setGrandTotalAmount(BigDecimal.ZERO);
-    // order.setWithholdingamount(BigDecimal.ZERO);
-    order.setSalesTransaction(isReceipt);
-    order.setPaymentMethod(paymentMethod);
-    order.setPaymentTerms(paymentTerm);
-
-    OBDal.getInstance().save(order);
-    OBDal.getInstance().flush();
-
-    // Create one line
-    OrderLine orderLine = OBProvider.getInstance().get(OrderLine.class);
-    orderLine.setOrganization(org);
-    orderLine.setClient(client);
-    orderLine.setSalesOrder(order);
-    orderLine.setOrderDate(orderDate);
-    orderLine.setWarehouse(warehouse);
-    orderLine.setCurrency(currency);
-    orderLine.setLineNo(new Long("10"));
-    orderLine.setProduct(product);
-    orderLine.setUOM(uom);
-    orderLine.setInvoicedQuantity(BigDecimal.ZERO);
-    orderLine.setOrderedQuantity(orderedQuantity);
-    orderLine.setUnitPrice(netUnitPrice);
-    orderLine.setListPrice(netListPrice);
-    orderLine.setPriceLimit(priceLimit);
-    orderLine.setTax(taxRate);
-    orderLine.setLineNetAmount(lineNetAmount);
-
-    OBDal.getInstance().save(orderLine);
-    OBDal.getInstance().flush();
-
-    return order;
-  }
-
-  public static boolean processOrder(Order order) throws Exception {
-    OBContext.setAdminMode();
-    Process process = null;
-    try {
-      process = OBDal.getInstance().get(Process.class, "104");
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    final ProcessInstance pinstance = CallProcess.getInstance().call(process, order.getId(), null);
-    OBDal.getInstance().save(order);
-    OBDal.getInstance().flush();
-    OBDal.getInstance().commitAndClose();
-    return (pinstance.getResult() == 0L);
-  }
-
-  public static Invoice createNewInvoice(Client client, Organization org, Date invoiceDate,
-      Date accountingDate, Date taxDate, DocumentType documentType, BusinessPartner bp,
-      org.openbravo.model.common.businesspartner.Location loc, PriceList priceList,
-      Currency currency, FIN_PaymentMethod paymentMethod, PaymentTerm paymentTerm, Product product,
-      UOM uom, BigDecimal invoicedQuantity, BigDecimal netUnitPrice, BigDecimal netListPrice,
-      BigDecimal priceLimit, TaxRate taxRate, BigDecimal lineNetAmount, boolean isReceipt)
-      throws Exception {
-
-    // Create header
-    Invoice invoice = OBProvider.getInstance().get(Invoice.class);
-    invoice.setOrganization(org);
-    invoice.setClient(client);
-    invoice.setDocumentType(documentType);
-    invoice.setTransactionDocument(documentType);
-    invoice.setDocumentNo(FIN_Utility.getDocumentNo(org, "ARI", "C_Invoice"));
-    invoice.setAccountingDate(accountingDate);
-    invoice.setInvoiceDate(invoiceDate);
-    invoice.setTaxDate(taxDate);
-    invoice.setBusinessPartner(bp);
-    invoice.setPartnerAddress(loc);
-    invoice.setPriceList(priceList);
-    invoice.setCurrency(currency);
-    invoice.setSummedLineAmount(BigDecimal.ZERO);
-    invoice.setGrandTotalAmount(BigDecimal.ZERO);
-    invoice.setWithholdingamount(BigDecimal.ZERO);
-    invoice.setSalesTransaction(isReceipt);
-    invoice.setPaymentMethod(paymentMethod);
-    invoice.setPaymentTerms(paymentTerm);
-
-    OBDal.getInstance().save(invoice);
-    OBDal.getInstance().flush();
-
-    // Create one line
-    InvoiceLine invoiceLine = OBProvider.getInstance().get(InvoiceLine.class);
-    invoiceLine.setOrganization(org);
-    invoiceLine.setClient(client);
-    invoiceLine.setInvoice(invoice);
-    invoiceLine.setLineNo(new Long("10"));
-    invoiceLine.setProduct(product);
-    invoiceLine.setUOM(uom);
-    invoiceLine.setInvoicedQuantity(invoicedQuantity);
-    invoiceLine.setUnitPrice(netUnitPrice);
-    invoiceLine.setListPrice(netListPrice);
-    invoiceLine.setPriceLimit(priceLimit);
-    invoiceLine.setTax(taxRate);
-    invoiceLine.setLineNetAmount(lineNetAmount);
-
-    OBDal.getInstance().save(invoiceLine);
-    OBDal.getInstance().flush();
-
-    return invoice;
-  }
-
-  public static boolean processInvoice(Invoice invoice) throws Exception {
-    OBContext.setAdminMode();
-    Process process = null;
-    try {
-      process = OBDal.getInstance().get(Process.class, "111");
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    final ProcessInstance pinstance = CallProcess.getInstance()
-        .call(process, invoice.getId(), null);
-    OBDal.getInstance().save(invoice);
-    OBDal.getInstance().flush();
-    OBDal.getInstance().commitAndClose();
-    return (pinstance.getResult() == 0L);
-  }
-
-  public static FIN_Payment addPaymentFromInvoice(Invoice invoice, FIN_FinancialAccount account,
-      BigDecimal amount, boolean isWriteOff) throws Exception {
-    AdvPaymentMngtDao dao = new AdvPaymentMngtDao();
-
-    OBDal.getInstance().getSession().refresh(invoice);
-    List<FIN_PaymentScheduleDetail> scheduleDetails = dao
-        .getInvoicePendingScheduledPaymentDetails(invoice);
-
-    HashMap<String, BigDecimal> paidAmount = new HashMap<String, BigDecimal>();
-    paidAmount.put(scheduleDetails.get(0).getId(), amount);
-
-    FIN_Payment payment = FIN_AddPayment
-        .savePayment(null, invoice.isSalesTransaction(),
-            FIN_Utility.getDocumentType(invoice.getOrganization(), "ARR"),
-            FIN_Utility.getDocumentNo(invoice.getOrganization(), "APP", "FIN_Payment"),
-            invoice.getBusinessPartner(), invoice.getPaymentMethod(), account, amount.toString(),
-            new Date(), invoice.getOrganization(), null, scheduleDetails, paidAmount, isWriteOff,
-            false);
-
-    return payment;
-  }
-
-  public static FIN_Payment addPaymentFromOrder(Order order, FIN_FinancialAccount account,
-      BigDecimal amount, boolean isWriteOff) throws Exception {
-    AdvPaymentMngtDao dao = new AdvPaymentMngtDao();
-
-    OBDal.getInstance().getSession().refresh(order);
-    List<FIN_PaymentScheduleDetail> scheduleDetails = dao
-        .getOrderPendingScheduledPaymentDetails(order);
-
-    HashMap<String, BigDecimal> paidAmount = new HashMap<String, BigDecimal>();
-    paidAmount.put(scheduleDetails.get(0).getId(), amount);
-
-    FIN_Payment payment = FIN_AddPayment.savePayment(null, order.isSalesTransaction(),
-        FIN_Utility.getDocumentType(order.getOrganization(), "ARR"),
-        FIN_Utility.getDocumentNo(order.getOrganization(), "APP", "FIN_Payment"),
-        order.getBusinessPartner(), order.getPaymentMethod(), account, amount.toString(),
-        new Date(), order.getOrganization(), null, scheduleDetails, paidAmount, isWriteOff, false);
-
-    return payment;
-  }
-
-  public static void processPayment(FIN_Payment payment, String strDocAction) throws Exception {
-    VariablesSecureApp vars = new VariablesSecureApp(OBContext.getOBContext().getUser().getId(),
-        OBContext.getOBContext().getCurrentClient().getId(), OBContext.getOBContext()
-            .getCurrentOrganization().getId(), OBContext.getOBContext().getRole().getId());
-
-    FIN_AddPayment.processPayment(vars, getConnectionProviderMy(), strDocAction, payment);
-  }
-
-  /**
-   * Method used to generating payment document with refund amount.
-   * 
-   * @param payment
-   *          Created Payment.
-   * @param refundAmount
-   *          Refund Amount need to transfer to the customer.
-   * @return Created FIN_Payment object.
-   * @throws Exception
-   *           In case of executing invalid data.
-   */
-  public static FIN_Payment createRefundPayment(FIN_Payment payment, BigDecimal refundAmount)
-      throws Exception {
-    OBContext.setAdminMode();
-    FIN_Payment refundPayment = null;
-    try {
-      VariablesSecureApp vars = new VariablesSecureApp(OBContext.getOBContext().getUser().getId(),
-          OBContext.getOBContext().getCurrentClient().getId(), OBContext.getOBContext()
-              .getCurrentOrganization().getId(), OBContext.getOBContext().getRole().getId());
-      refundPayment = FIN_AddPayment.createRefundPayment(getConnectionProviderMy(), vars, payment,
-          refundAmount.negate());
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-    return refundPayment;
-  }
-
-  public static void processPaymentProposal(FIN_PaymentProposal paymentProposal, String strDocAction)
-      throws Exception {
-    VariablesSecureApp vars = new VariablesSecureApp(OBContext.getOBContext().getUser().getId(),
-        OBContext.getOBContext().getCurrentClient().getId(), OBContext.getOBContext()
-            .getCurrentOrganization().getId(), OBContext.getOBContext().getRole().getId());
-
-    FIN_AddPayment.processPaymentProposal(vars, getConnectionProviderMy(), strDocAction,
-        paymentProposal.getId());
-  }
-
-  public static FIN_PaymentProposal createNewPaymentProposal(Client client, Organization org,
-      FIN_FinancialAccount account, Currency currency, FIN_PaymentMethod paymentMethod) {
-    FIN_PaymentProposal pp = OBProvider.getInstance().get(FIN_PaymentProposal.class);
-    pp.setOrganization(org);
-    pp.setClient(client);
-    pp.setAccount(account);
-    pp.setAmount(BigDecimal.ZERO);
-    pp.setBusinessPartner(null);
-    pp.setCurrency(currency);
-    pp.setDocumentNo(FIN_Utility.getDocumentNo(org, "APPP", "FIN_PaymentProposal"));
-    pp.setDocumentType(FIN_Utility.getDocumentType(org, "APPP"));
-    pp.setPaymentMethod(paymentMethod);
-    pp.setDuedate(null);
-    pp.setPaymentDate(new Date());
-    pp.setReceipt(false);
-    pp.setWriteoffAmount(BigDecimal.ZERO);
-    OBDal.getInstance().save(pp);
-    OBDal.getInstance().flush();
-
-    return pp;
-  }
-
-  public static <T extends BaseOBObject> T getOneInstance(Class<T> clazz, Value... values) {
-
-    // create an OBCriteria object and add a filter
-    final OBCriteria<T> obCriteria = OBDal.getInstance().createCriteria(clazz);
-
-    for (Value value : values) {
-      if (value.getValue() == null) {
-        obCriteria.add(Restrictions.isNull(value.getField()));
-      } else {
-        obCriteria.add(Restrictions.eq(value.getField(), value.getValue()));
-      }
-    }
-
-    final List<T> listt = obCriteria.list();
-    if (listt != null && listt.size() > 0) {
-      return listt.get(0);
-    } else {
-      return null;
-    }
-  }
-
-  public static void setTestContext() {
-    // User = Openbravo
-    // Role = F&B International Group Admin
-    // Client = F&B International Group
-    // Org = F&B US, Inc.
-    OBContext.setOBContext("100", "FF8080812AFBCB14012AFBD3E4340031",
-        "FF8080812AFBCB14012AFBD3E373001F", "B9C7088AB859483A9B1FB342AC2BE17A");
-  }
-
-  public static void setTestContextSpain() {
-    // User = Openbravo
-    // Role = F&B International Group Admin
-    // Client = F&B International Group
-    // Org = F&B US, Inc.
-    OBContext.setOBContext("100", "FF8080812AFBCB14012AFBD3E4340031",
-        "FF8080812AFBCB14012AFBD3E373001F", "4F68EB1C1B734E79B27DE9D2DF56089F");
-  }
-
-  private static ConnectionProvider getConnectionProviderMy() {
-    try {
-      final String propFile = OBConfigFileProvider.getInstance().getFileLocation();
-      final ConnectionProvider conn = new ConnectionProviderImpl(propFile + "/Openbravo.properties");
-      return conn;
-    } catch (PoolNotFoundException e) {
-      throw new IllegalStateException(e);
-    }
-  }
-
-}
--- a/modules/org.openbravo.advpaymentmngt/src-test/org/openbravo/advpaymentmngt/test/draft/Value.java	Tue Aug 02 10:54:05 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
- *************************************************************************
- * 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 SLU
- * All portions are Copyright (C) 2010 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- *************************************************************************
- */
-
-package org.openbravo.advpaymentmngt.test.draft;
-
-public class Value {
-  private String field;
-  private Object value;
-
-  public Value(String field, Object value) {
-    this.field = field;
-    this.value = value;
-  }
-
-  public String getField() {
-    return field;
-  }
-
-  public Object getValue() {
-    return value;
-  }
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/AllTests.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,52 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (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 SLU 
+ * All portions are Copyright (C) 2011-2014 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * 
+ * Test for org.openbravo.advpaymentmngt
+ * 
+ */
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+
+// Master Data Configuration
+    FinancialAccountTest.class, //
+    PaymentMethodTest.class,
+
+    // Payment scenarios
+    PaymentTest_01.class, //
+    PaymentTest_02.class, //
+    PaymentTest_03.class, //
+    PaymentTest_04.class, //
+    PaymentTest_05.class, //
+    PaymentTest_06.class, //
+    PaymentTest_07.class, //
+    PaymentTest_08.class, //
+    PaymentTest_09.class, //
+    PaymentTest_10.class, //
+    PaymentTest_11.class })
+public class AllTests {
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/FinancialAccountTest.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,103 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+import org.hibernate.criterion.Restrictions;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.geography.Location;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.test.base.OBBaseTest;
+
+public class FinancialAccountTest extends OBBaseTest {
+
+  private static final String BANK = "B";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test";
+
+  /**
+   * This before method is named setUpF() to avoid overwriting the super setUp method that is invoke
+   * automatically before this one.
+   */
+  @Before
+  public void setUpF() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  @Test
+  public void testAddFinancialAccountValid1() {
+    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_1", STANDARD_DESCRIPTION,
+        getOneInstance(Currency.class), CASH, false, getOneInstance(Location.class),
+        getOneInstance(BusinessPartner.class), null, null, null, null, null, null, null, null,
+        null, BigDecimal.ZERO, BigDecimal.ZERO, null, true, false);
+  }
+
+  // Pre-requisite: at least one Matching Algorithm created
+  @Test
+  public void testAddFinancialAccountValid2() {
+    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_2", STANDARD_DESCRIPTION,
+        getOneInstance(Currency.class), BANK, false, getOneInstance(Location.class),
+        getOneInstance(BusinessPartner.class), "2054", "4321", "1", null, null, null, "123456789",
+        null, null, BigDecimal.ZERO, BigDecimal.ZERO,
+        null/* getOneInstance(MatchingAlgorithm.class) */, true, false);
+  }
+
+  @Test
+  public void testAddFinancialAccountValid3() {
+    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_3", STANDARD_DESCRIPTION,
+        getOneInstance(Currency.class), BANK, false, getOneInstance(Location.class),
+        getOneInstance(BusinessPartner.class), "2054", null, null, null, null, null, null, null,
+        null, BigDecimal.ZERO, BigDecimal.ZERO, null, true, false);
+  }
+
+  /**
+   * Currency is mandatory
+   */
+  @Test
+  public void testAddFinancialAccountNotValid1() {
+    TestUtility.insertFinancialAccount("APRM_FINANCIAL_ACCOUNT_4", STANDARD_DESCRIPTION, null,
+        BANK, false, getOneInstance(Location.class), getOneInstance(BusinessPartner.class), "2054",
+        null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null,
+        false, false);
+  }
+
+  /**
+   * Deletes all the Payment Methods created for testing
+   */
+  @Test
+  public void testDeleteFinancialAccounts() {
+    final OBCriteria<FIN_FinancialAccount> obCriteria = OBDal.getInstance().createCriteria(
+        FIN_FinancialAccount.class);
+    obCriteria
+        .add(Restrictions.eq(FIN_FinancialAccount.PROPERTY_DESCRIPTION, STANDARD_DESCRIPTION));
+    final List<FIN_FinancialAccount> finAccs = obCriteria.list();
+    for (FIN_FinancialAccount fa : finAccs) {
+      OBDal.getInstance().remove(fa);
+    }
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentMethodTest.java	Tue Jul 26 13:54:18 2016 +0200
@@ -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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import java.util.List;
+
+import org.hibernate.criterion.Restrictions;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.test.base.OBBaseTest;
+
+public class PaymentMethodTest extends OBBaseTest {
+
+  private static final String AUTOMATIC_EXECUTION = "A";
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test";
+
+  /**
+   * This before method is named setUpP() to avoid overwriting the super setUp method that is invoke
+   * automatically before this one.
+   */
+  @Before
+  public void setUpP() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  @Test
+  public void testAddPaymentMethodValid1() {
+    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_1", STANDARD_DESCRIPTION, true, false,
+        false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT,
+        true, false, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT,
+        CLEARED_ACCOUNT, true, false);
+  }
+
+  @Test
+  public void testAddPaymentMethodValid2() {
+    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_2", STANDARD_DESCRIPTION, true, false,
+        false, AUTOMATIC_EXECUTION, null, false, IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT,
+        CLEARED_ACCOUNT, true, false, false, AUTOMATIC_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
+        WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, false);
+  }
+
+  @Test
+  public void testAddPaymentMethodValid3() {
+    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_3", STANDARD_DESCRIPTION, true, false,
+        false, MANUAL_EXECUTION, null, false, null, null, null, true, false, false,
+        MANUAL_EXECUTION, null, false, null, null, null, true, false);
+  }
+
+  @Test
+  public void testAddPaymentMethodValid4() {
+    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_4", STANDARD_DESCRIPTION, true, true,
+        true, MANUAL_EXECUTION, null, false, null, null, null, true, true, true, MANUAL_EXECUTION,
+        null, false, null, null, null, true, false);
+  }
+
+  // Requisite: at least one Execution Process created
+  @Test
+  public void testAddPaymentMethodValid5() {
+    TestUtility.insertPaymentMethod("APRM_PAYMENT_METHOD_5", STANDARD_DESCRIPTION, true, false,
+        false, AUTOMATIC_EXECUTION, /* getOneInstance(PaymentExecutionProcess.class) */null, false,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false,
+        AUTOMATIC_EXECUTION,
+        /* getOneInstance(PaymentExecutionProcess.class) */null, false, IN_TRANSIT_ACCOUNT,
+        WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, false);
+  }
+
+  /**
+   * Deletes all the Payment Methods created for testing
+   */
+  @Test
+  public void testDeletePaymentMethod() {
+    final OBCriteria<FIN_PaymentMethod> obCriteria = OBDal.getInstance().createCriteria(
+        FIN_PaymentMethod.class);
+    obCriteria.add(Restrictions.eq(FIN_PaymentMethod.PROPERTY_DESCRIPTION, STANDARD_DESCRIPTION));
+    final List<FIN_PaymentMethod> paymentMethods = obCriteria.list();
+    for (FIN_PaymentMethod pm : paymentMethods) {
+      OBDal.getInstance().remove(pm);
+    }
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_01.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,236 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+public class PaymentTest_01 extends OBBaseTest {
+
+  private static final Logger log = Logger.getLogger(PaymentTest_01.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_01";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP01() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP01() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  @Test
+  public void testRunPayment_01() {
+    boolean exception = false;
+    Invoice invoice = null;
+    FIN_Payment payment = null;
+
+    try {
+
+      // DATA SETUP
+      invoice = dataSetup();
+
+      // PAY COMPLETELY THE INVOICE
+      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+      payment = TestUtility.addPaymentFromInvoice(invoice,
+          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
+          invoice.getGrandTotalAmount(), false);
+
+      // PROCESS THE PAYMENT
+      TestUtility.processPayment(payment, "P");
+
+      // CHECK OUTPUT DATA
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue(
+            "Payment Schedule Outstanding Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) == 0);
+        assertTrue(
+            "Payment Schedule Received Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Deatail Amount != Total Amount", invoice.getGrandTotalAmount()
+            .compareTo(psd.getAmount()) == 0);
+        assertTrue("Payment Schedule Detail Write-off Amount != 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
+        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
+        assertTrue("Payment Line Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(psd.getPaymentDetails().getAmount()) == 0);
+        assertTrue("Payment Line Write-off Amount != 0",
+            BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+      // REACTIVATE
+      TestUtility.processPayment(payment, "R");
+
+      // CHECK OUTPUT DATA AFTER REACTIVATION
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue(
+            "Expected Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
+        assertTrue(
+            "Outstanding Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Received Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Deatail Amount != 0",
+            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
+        assertTrue("Payment Schedule Detail Write-off Amount != 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
+        assertTrue("Status != Awaiting Payment", "RPAP".equals(payment.getStatus()));
+
+        assertTrue("There are Payment Lines for this payment",
+            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
+                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
+    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
+    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
+    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
+    BigDecimal invoicedQuantity = new BigDecimal("5");
+    BigDecimal netUnitPrice = new BigDecimal("2.04");
+    BigDecimal netListPrice = new BigDecimal("2.04");
+    BigDecimal lineNetAmount = new BigDecimal("10.20");
+    BigDecimal priceLimit = new BigDecimal("1");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
+        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
+        null, true, true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
+        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processInvoice(invoice);
+
+    return invoice;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_02.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,238 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * The PaymentTest_02 class used to test the partial payment document generation and reactivating
+ * the in APRM.
+ * 
+ */
+public class PaymentTest_02 extends OBBaseTest {
+
+  private static final Logger log = Logger.getLogger(PaymentTest_01.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_02";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP02() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP02() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  public void testRunPayment_02() {
+    boolean exception = false;
+    Invoice invoice = null;
+    FIN_Payment payment = null;
+
+    try {
+
+      // DATA SETUP
+      invoice = dataSetup();
+
+      // PAY PARTIALLY THE INVOICE
+      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+      BigDecimal divisor = new BigDecimal("2.0");
+      BigDecimal paymentAmount = invoice.getGrandTotalAmount().divide(divisor, 2);
+      payment = TestUtility.addPaymentFromInvoice(invoice,
+          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
+          false);
+
+      // PROCESS THE PAYMENT
+      TestUtility.processPayment(payment, "P");
+
+      // CHECK OUTPUT DATA
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue("Payment Schedule Outstanding Amount ("
+            + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
+            + ") != " + paymentAmount.toPlainString(), invoice.getFINPaymentScheduleList().get(0)
+            .getOutstandingAmount().compareTo(paymentAmount) == 0);
+
+        assertTrue(
+            "Payment Schedule Received Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) != 0);
+
+        assertTrue("Payment Schedule Deatail Amount != Total Amount", invoice.getGrandTotalAmount()
+            .compareTo(psd.getAmount()) != 0);
+
+        assertTrue("Payment Schedule Detail Write-off Amount == 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) != 0);
+        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+      // REACTIVATE
+      TestUtility.processPayment(payment, "R");
+
+      // CHECK OUTPUT DATA AFTER REACTIVATION
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue(
+            "Expected Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
+        assertTrue(
+            "Outstanding Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Received Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Detail Amount != 0",
+            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
+        assertTrue("Payment Schedule Detail Write-off Amount == 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
+        assertTrue("Status != Awaiting Payment", "RPAP".equals(payment.getStatus()));
+
+        assertTrue("There are Payment Lines for this payment",
+            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
+                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
+    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
+    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
+    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
+    BigDecimal invoicedQuantity = new BigDecimal("5");
+    BigDecimal netUnitPrice = new BigDecimal("2");
+    BigDecimal netListPrice = new BigDecimal("2");
+    BigDecimal lineNetAmount = new BigDecimal("1");
+    BigDecimal priceLimit = new BigDecimal("1");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
+        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
+        null, true, true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
+        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processInvoice(invoice);
+
+    return invoice;
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_03.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,236 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * The PaymentTest_03 class used to test the payment document generation and reactivation with
+ * write-off option.
+ */
+public class PaymentTest_03 extends OBBaseTest {
+
+  private static final Logger log = Logger.getLogger(PaymentTest_01.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_03";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP03() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP03() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  @Test
+  public void testRunPayment_03() {
+    boolean exception = false;
+    Invoice invoice = null;
+    FIN_Payment payment = null;
+
+    try {
+
+      // DATA SETUP
+      invoice = dataSetup();
+
+      // PAY PARTIALLY THE INVOICE
+      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+      BigDecimal writeOffAmt = new BigDecimal("2.0");
+      BigDecimal paymentAmount = invoice.getGrandTotalAmount().subtract(writeOffAmt);
+      payment = TestUtility.addPaymentFromInvoice(invoice,
+          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
+          true);
+
+      // PROCESS THE PAYMENT
+      TestUtility.processPayment(payment, "P");
+
+      // CHECK OUTPUT DATA
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue("Payment Schedule Outstanding Amount != 0", invoice.getFINPaymentScheduleList()
+            .get(0).getOutstandingAmount().compareTo(psd.getAmount()) != 0);
+
+        assertTrue(
+            "Payment Schedule Received Amount == Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Detail Amount != Total Amount", invoice.getGrandTotalAmount()
+            .compareTo(psd.getAmount()) != 0);
+
+        assertTrue("Payment Schedule Detail Write-off Amount != 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) != 0);
+
+        assertTrue("Payment Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) != 0);
+        assertTrue("Status == Payment Received", "RPR".equals(payment.getStatus()));
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+      // REACTIVATE
+      TestUtility.processPayment(payment, "R");
+
+      // CHECK OUTPUT DATA AFTER REACTIVATION
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue(
+            "Expected Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
+        assertTrue(
+            "Outstanding Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Received Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Detail Amount != 0",
+            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
+        assertTrue("Payment Schedule Detail Write-off Amount == 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
+        assertTrue("Status != Awaiting Payment", "RPAP".equals(payment.getStatus()));
+
+        assertTrue("There are Payment Lines for this payment",
+            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
+                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
+    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
+    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
+    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
+    BigDecimal invoicedQuantity = new BigDecimal("5");
+    BigDecimal netUnitPrice = new BigDecimal("2.04");
+    BigDecimal netListPrice = new BigDecimal("2.04");
+    BigDecimal lineNetAmount = new BigDecimal("10.20");
+    BigDecimal priceLimit = new BigDecimal("1");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
+        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
+        null, true, true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
+        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processInvoice(invoice);
+
+    return invoice;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_04.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,215 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * The PaymentTest_04 class used to test the payment document generation with Refund option.
+ */
+public class PaymentTest_04 extends OBBaseTest {
+
+  private static final Logger log = Logger.getLogger(PaymentTest_04.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_04";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP04() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP04() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  @Test
+  public void testRunPayment_04() {
+    boolean exception = false;
+    Invoice invoice = null;
+    FIN_Payment payment = null;
+
+    try {
+
+      // DATA SETUP
+      invoice = dataSetup();
+
+      // PAY PARTIALLY THE INVOICE
+      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+      BigDecimal refundAmt = new BigDecimal("20.0");
+      BigDecimal paymentAmount = invoice.getGrandTotalAmount();
+      payment = TestUtility.addPaymentFromInvoice(invoice,
+          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
+          false);
+
+      // PROCESS THE PAYMENT
+      TestUtility.processPayment(payment, "P");
+
+      // REFUNDING THE PAYMENT
+      FIN_Payment refundPayment = TestUtility.createRefundPayment(payment, refundAmt);
+
+      OBContext.setAdminMode();
+      try {
+        // PROCESSING THE REFUND PAYMENT
+        TestUtility.processPayment(refundPayment, "P");
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+      // CHECK OUTPUT DATA
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue("Payment Schedule Outstanding Amount == 0", invoice.getFINPaymentScheduleList()
+            .get(0).getOutstandingAmount().compareTo(psd.getAmount()) != 0);
+
+        assertTrue(
+            "Payment Schedule Received Amount == Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Detail Amount == Total Amount", invoice.getGrandTotalAmount()
+            .compareTo(psd.getAmount()) == 0);
+
+        assertTrue("Payment Schedule Detail Write-off Amount == 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount == Total Amount",
+            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
+        assertTrue("Status == Payment Received", "RPR".equals(payment.getStatus()));
+
+        assertTrue("Payment Amount == Refund Amount",
+            refundAmt.negate().compareTo(refundPayment.getAmount()) == 0);
+
+        assertTrue("Payment Used Credit == Used Credit",
+            refundAmt.compareTo(refundPayment.getUsedCredit()) == 0);
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
+    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
+    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
+    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
+    BigDecimal invoicedQuantity = new BigDecimal("5");
+    BigDecimal netUnitPrice = new BigDecimal("2.04");
+    BigDecimal netListPrice = new BigDecimal("2.04");
+    BigDecimal lineNetAmount = new BigDecimal("10.20");
+    BigDecimal priceLimit = new BigDecimal("1");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
+        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
+        null, true, true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
+        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processInvoice(invoice);
+
+    return invoice;
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_05.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,205 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
+import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentProposal;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * The PaymentTest_03 class used to test the payment document generation and reactivation with
+ * write-off option.
+ */
+public class PaymentTest_05 extends OBBaseTest {
+
+  private static final Logger log = Logger.getLogger(PaymentTest_05.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_05";
+
+  private String financialAccountId;
+  private String paymentMethodId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP05() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP05() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  /**
+   * Payment Proposal with two invoices of different business partner partially paid.
+   */
+  @Test
+  public void testRunPayment_05() {
+    String fruitBio = "8A64B71A2B0B2946012B0FE1E45F01B0";
+    String happyDrinks = "8A64B71A2B0B2946012B0FE1E37001AB";
+    String currencyId = "102"; // EUR
+    Invoice inv1;
+    Invoice inv2;
+    AdvPaymentMngtDao dao = new AdvPaymentMngtDao();
+    boolean exception = false;
+
+    try {
+      inv1 = createPurchaseInvoice(fruitBio);
+      inv2 = createPurchaseInvoice(happyDrinks);
+
+      inv1 = OBDal.getInstance().get(Invoice.class, inv1.getId());
+      inv2 = OBDal.getInstance().get(Invoice.class, inv2.getId());
+
+      FIN_PaymentProposal paymentProposal = TestUtility.createNewPaymentProposal(OBContext
+          .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(),
+          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), OBDal
+              .getInstance().get(Currency.class, currencyId),
+          OBDal.getInstance().get(FIN_PaymentMethod.class, paymentMethodId));
+
+      List<FIN_PaymentScheduleDetail> scheduleDetails1 = dao
+          .getInvoicePendingScheduledPaymentDetails(inv1);
+      List<FIN_PaymentScheduleDetail> scheduleDetails2 = dao
+          .getInvoicePendingScheduledPaymentDetails(inv2);
+
+      List<FIN_PaymentScheduleDetail> mergeScheduleDetails = new ArrayList<FIN_PaymentScheduleDetail>();
+      mergeScheduleDetails.add(scheduleDetails1.get(0));
+      mergeScheduleDetails.add(scheduleDetails2.get(0));
+
+      HashMap<String, BigDecimal> amounts = new HashMap<String, BigDecimal>();
+      amounts.put(scheduleDetails1.get(0).getId(), new BigDecimal("5"));
+      amounts.put(scheduleDetails2.get(0).getId(), new BigDecimal("5"));
+
+      OBContext.setAdminMode(true);
+      try {
+        // ORA-01779: cannot modify a column which maps to a non key-preserved table
+        FIN_AddPayment.savePaymentProposal(paymentProposal, new BigDecimal("10"),
+            mergeScheduleDetails, amounts, null);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+      TestUtility.processPaymentProposal(paymentProposal, "GSP");
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice createPurchaseInvoice(String businessPartnerId) throws Exception {
+
+    // DATA SETUP
+    String priceListId = "8A64B71A2B0B2946012B0BD96C470131"; // Happy Drinks Price List
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
+    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
+    String docTypeId = "71F835BC045742ADAAF5B6856914BB26"; // US AP Invoice
+    BigDecimal invoicedQuantity = new BigDecimal("5");
+    BigDecimal netUnitPrice = new BigDecimal("1.36");
+    BigDecimal netListPrice = new BigDecimal("1.36");
+    BigDecimal lineNetAmount = new BigDecimal("6.80");
+    BigDecimal priceLimit = new BigDecimal("1");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance().get(BusinessPartner.class,
+        businessPartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_01",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
+        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
+        null, true, true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_01",
+        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+
+    this.financialAccountId = testAccount.getId();
+    this.paymentMethodId = testPaymentMethod.getId();
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, false);
+
+    TestUtility.processInvoice(invoice);
+
+    return invoice;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_06.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,247 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * The PaymentTest_06 class used to test the payment document generation with execution process.
+ */
+public class PaymentTest_06 extends OBBaseTest {
+
+  private static final Logger log = Logger.getLogger(PaymentTest_06.class);
+
+  private static final String AUTOMATIC_EXECUTION = "A";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_06";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP06() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP06() throws Exception {
+    TestUtility.setTestContext();
+  }
+
+  @Test
+  public void testRunPayment_06() {
+    boolean exception = false;
+    Invoice invoice = null;
+    FIN_Payment payment = null;
+
+    try {
+
+      // DATA SETUP
+      invoice = dataSetup();
+
+      // PAY COMPLETELY THE INVOICE
+      invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+      payment = TestUtility.addPaymentFromInvoice(invoice,
+          OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
+          invoice.getGrandTotalAmount(), false);
+
+      // PROCESS THE PAYMENT
+      TestUtility.processPayment(payment, "P");
+
+      // CHECK OUTPUT DATA
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue(
+            "Payment Schedule Outstanding Amount ("
+                + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
+                + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Payment Schedule Received Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Detail Amount != Total Amount", invoice.getGrandTotalAmount()
+            .compareTo(psd.getAmount()) == 0);
+        assertTrue("Payment Schedule Detail Write-off Amount != 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
+        assertTrue("Status != Receivable Payables Awaiting  Execution",
+            "RPAE".equals(payment.getStatus()));
+        assertTrue("Payment Line Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(psd.getPaymentDetails().getAmount()) == 0);
+        assertTrue("Payment Line Write-off Amount != 0",
+            BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+      // REACTIVATE
+      TestUtility.processPayment(payment, "R");
+
+      // CHECK OUTPUT DATA AFTER REACTIVATION
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+            new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                .getFINPaymentScheduleList().get(0)));
+
+        assertTrue(
+            "Expected Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getAmount()) == 0);
+        assertTrue(
+            "Outstanding Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Received Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+        assertTrue("Payment Schedule Deatail Amount != 0",
+            invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
+        assertTrue("Payment Schedule Detail Write-off Amount != 0",
+            BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+        assertTrue("Payment Amount != 0", BigDecimal.ZERO.compareTo(payment.getAmount()) == 0);
+        assertTrue("Status != Receivable Payment Awaiting Payment",
+            "RPAP".equals(payment.getStatus()));
+
+        assertTrue("There are Payment Lines for this payment",
+            TestUtility.getOneInstance(FIN_PaymentDetail.class, new Value(
+                FIN_PaymentDetail.PROPERTY_FINPAYMENT, payment)) == null);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E51401C1"; // Sleep Well Hotel
+    String priceListId = "8A64B71A2B0B2946012B0BD96E850150"; // General Sales
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC4345000FB"; // Ale Beer
+    String taxId = "1FE610D3A8844F85B17CA32525C15353"; // NY Sales Tax
+    String docTypeId = "C99C4AE941E1460B91BC97665BE5D141"; // AR Invoice
+    BigDecimal invoicedQuantity = new BigDecimal("5");
+    BigDecimal netUnitPrice = new BigDecimal("2.04");
+    BigDecimal netListPrice = new BigDecimal("2.04");
+    BigDecimal lineNetAmount = new BigDecimal("10.20");
+    BigDecimal priceLimit = new BigDecimal("1");
+    String executionProcessId = "717D521D5F454FAD9199B831001BB4E0"; // Simple Execution Process
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+    PaymentExecutionProcess pmtExecProcess = OBDal.getInstance().get(PaymentExecutionProcess.class,
+        executionProcessId);
+
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_02",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), testBusinessPartner,
+        null, null, null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO,
+        null, true, true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_02",
+        STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION, pmtExecProcess, true,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false,
+        AUTOMATIC_EXECUTION, pmtExecProcess, true, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT,
+        CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processInvoice(invoice);
+
+    return invoice;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_07.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,338 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2011-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.process.FIN_ExecutePayment;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.enterprise.Warehouse;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+public class PaymentTest_07 extends OBBaseTest {
+
+  // 1) Create an order with discount
+  // 2) Add a partial payment but do not execute it
+  // 3) Invoice the complete order (without discount) using an automatic receipt payment method
+  // 4) Review payment info
+  // 5) Execute payment
+  // 6) Review payment info
+
+  private static final Logger log = Logger.getLogger(PaymentTest_07.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String AUTOMATIC_EXECUTION = "A";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_07";
+  private static final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP07() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP07() throws Exception {
+    TestUtility.setTestContextSpain();
+  }
+
+  @Test
+  public void testRunPayment_07() {
+    boolean exception = false;
+    try {
+      OBContext.setAdminMode();
+      try {
+        // DATA SETUP
+        Invoice invoice = dataSetup();
+        FIN_Payment payment = null;
+        for (FIN_PaymentScheduleDetail psd : invoice.getFINPaymentScheduleList().get(0)
+            .getFINPaymentScheduleDetailInvoicePaymentScheduleList()) {
+          if ("RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
+            payment = psd.getPaymentDetails().getFinPayment();
+          }
+        }
+        FIN_ExecutePayment executePayment = new FIN_ExecutePayment();
+        List<FIN_Payment> payments = new ArrayList<FIN_Payment>();
+        payments.add(payment);
+        executePayment.init("OTHER",
+            OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS),
+            payments, null, payment.getOrganization());
+        OBError result = executePayment.execute();
+        // CHECK PAYMENT EXECUTION
+        assertTrue("Payment error while executing", !"Error".equals(result.getType()));
+
+        Order order = invoice.getSalesOrder();
+        // CHECK OUTPUT DATA ORDER
+        assertTrue(
+            "Order Payment Schedule Outstanding Amount ("
+                + order.getFINPaymentScheduleList().get(0).getOutstandingAmount() + ") != 0",
+            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) == 0);
+        assertTrue(
+            "Order Payment Schedule Received Amount ("
+                + getPaidAmount(order.getFINPaymentScheduleList()).toPlainString()
+                + ") != Total Amount (" + order.getGrandTotalAmount().toPlainString(),
+            order.getGrandTotalAmount().compareTo(getPaidAmount(order.getFINPaymentScheduleList())) == 0);
+        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
+        // CHECK OUTPUT DATA INVOICE
+        assertTrue(
+            "Invoice Payment Schedule Outstanding Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) == 0);
+        assertTrue("Invoice remains not paid", invoice.isPaymentComplete());
+        assertTrue(
+            "Invoice Payment Schedule Received Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
+        // CHECK OUTPUT DATA PAYMENT
+        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E8B50200"; // Alimentos y Supermercados, S.A.
+    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
+    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
+    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
+    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
+    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
+
+    // Process
+    BigDecimal quantity = new BigDecimal("10");
+    BigDecimal invoicedQuantity = new BigDecimal("10");
+    BigDecimal netUnitPrice = new BigDecimal("10");
+    BigDecimal netListPrice = new BigDecimal("10");
+    BigDecimal lineNetAmount = new BigDecimal("100");
+    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
+    BigDecimal priceLimit = new BigDecimal("10");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+    DocumentType testOrderDocumentType = OBDal.getInstance()
+        .get(DocumentType.class, orderDocTypeId);
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_07",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
+        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
+        true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_07",
+        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
+        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
+    testBusinessPartner.setAccount(testAccount);
+    OBDal.getInstance().save(testBusinessPartner);
+
+    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
+    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
+        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
+        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processOrder(order);
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
+              .getFINPaymentScheduleList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount == 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount == 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
+        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
+        order.getGrandTotalAmount(), false);
+
+    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
+        "APRM_PM_PAYMENT_07_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
+        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
+        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
+
+    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
+    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
+    payment.setPaymentMethod(awaitingExecutionPM);
+    OBDal.getInstance().save(payment);
+    // PROCESS THE PAYMENT
+    TestUtility.processPayment(payment, "P");
+    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
+      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment
+              .getFINPaymentDetailList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount != Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount != 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount != Total Amount", order.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount != 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
+      assertTrue("Payment Line Write-off Amount != 0",
+          BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    // This created order is invoiced
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
+    OBDal.getInstance().refresh(invoice);
+    // Order is associated both to header and lines
+    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
+    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
+
+    OBDal.getInstance().save(invoiceLine);
+
+    invoice.setSalesOrder(order);
+
+    OBDal.getInstance().save(invoice);
+
+    TestUtility.processInvoice(invoice);
+    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+    return invoice;
+  }
+
+  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
+    BigDecimal amount = BigDecimal.ZERO;
+    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
+      boolean isInvoice = ps.getInvoice() != null;
+      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
+          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
+          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
+        if (psd.getPaymentDetails() != null
+            && psd.getPaymentDetails().getFinPayment().isProcessed()
+            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
+          amount = amount.add(psd.getAmount());
+        }
+      }
+    }
+    return amount;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_08.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,317 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2011-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.enterprise.Warehouse;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.invoice.InvoiceDiscount;
+import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+public class PaymentTest_08 extends OBBaseTest {
+
+  // 1) Create an order
+  // 2) Add a partial payment but do not execute it
+  // 3) Invoice the order partially using an automatic receipt payment method
+  // 4)Review payment info
+
+  private static final Logger log = Logger.getLogger(PaymentTest_08.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String AUTOMATIC_EXECUTION = "A";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_08";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP08() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP08() throws Exception {
+    TestUtility.setTestContextSpain();
+  }
+
+  @Test
+  public void testRunPayment_08() {
+    boolean exception = false;
+    try {
+      // DATA SETUP
+      Invoice invoice = dataSetup();
+      Order order = invoice.getSalesOrder();
+      // CHECK OUTPUT DATA
+      OBContext.setAdminMode();
+      try {
+        assertTrue(
+            "Invoice Payment Schedule Outstanding Amount == 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) != 0);
+        assertTrue("Invoice Payment Schedule  not Total Pending", invoice.getGrandTotalAmount()
+            .compareTo(invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Invoice Payment Schedule Paid Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+        assertTrue(
+            "Order Payment Schedule Outstanding Amount == 0",
+            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) != 0);
+        assertTrue("Order Payment Schedule not Total Pending", invoice.getGrandTotalAmount()
+            .compareTo(invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Order Payment Schedule Paid Amount != 0",
+            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E8B50200"; // Alimentos y Supermercados, S.A.
+    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
+    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
+    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
+    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
+    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
+    final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0"; // Simple Execution
+    // Process
+    BigDecimal quantity = new BigDecimal("10");
+    BigDecimal invoicedQuantity = new BigDecimal("5");
+    BigDecimal netUnitPrice = new BigDecimal("10");
+    BigDecimal netListPrice = new BigDecimal("10");
+    BigDecimal lineNetAmount = new BigDecimal("100");
+    BigDecimal invoiceLineNetAmount = new BigDecimal("50");
+    BigDecimal priceLimit = new BigDecimal("10");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+    DocumentType testOrderDocumentType = OBDal.getInstance()
+        .get(DocumentType.class, orderDocTypeId);
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_08",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
+        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
+        true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_08",
+        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
+        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
+    testBusinessPartner.setAccount(testAccount);
+    OBDal.getInstance().save(testBusinessPartner);
+
+    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
+    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
+        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
+        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processOrder(order);
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
+              .getFINPaymentScheduleList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount == 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount == 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
+        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
+        order.getGrandTotalAmount(), false);
+
+    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
+        "APRM_PM_PAYMENT_08_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
+        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
+        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
+
+    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
+    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
+    payment.setPaymentMethod(awaitingExecutionPM);
+    OBDal.getInstance().save(payment);
+    // PROCESS THE PAYMENT
+    TestUtility.processPayment(payment, "P");
+    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
+      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
+              .getFINPaymentScheduleList().get(0)));
+      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount == 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount == 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    // This created order is PARTIALLY invoiced
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
+    OBDal.getInstance().refresh(invoice);
+    // Order is associated both to header and lines
+    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
+    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
+
+    OBDal.getInstance().save(invoiceLine);
+
+    invoice.setSalesOrder(order);
+
+    OBDal.getInstance().save(invoice);
+
+    // Add invoice Discount
+    InvoiceDiscount invoiceDiscount = OBProvider.getInstance().get(InvoiceDiscount.class);
+    invoiceDiscount.setInvoice(invoice);
+    invoiceDiscount.setLineNo(10l);
+    invoiceDiscount.setDiscount(order.getOrderDiscountList().get(0).getDiscount());
+    OBDal.getInstance().save(invoiceDiscount);
+
+    TestUtility.processInvoice(invoice);
+    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+    // CHECK OUTPUT DATA FOR INVOICE
+    OBContext.setAdminMode();
+    try {
+      // CHECK OUTPUT DATA FOR INVOICE
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+              .getFINPaymentScheduleList().get(0)));
+      assertTrue(
+          "Payment Schedule Outstanding Amount == Order amount",
+          invoice.getGrandTotalAmount().compareTo(
+              invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue(
+          "Payment Schedule Received Amount == 0",
+          BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount == Total Amount", invoice.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount == 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return invoice;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_09.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,349 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2011-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.process.FIN_ExecutePayment;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.enterprise.Warehouse;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.invoice.InvoiceDiscount;
+import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.discount.Discount;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+public class PaymentTest_09 extends OBBaseTest {
+
+  // 1) Create an order without discount
+  // 2) Add a partial payment but do not execute it
+  // 3) Invoice the complete order (with discount) using an automatic receipt payment method
+  // 4) Review payment info
+  // 5) Execute payment
+  // 6) Review payment info
+
+  private static final Logger log = Logger.getLogger(PaymentTest_09.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String AUTOMATIC_EXECUTION = "A";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_09";
+  private static final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP09() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP09() throws Exception {
+    TestUtility.setTestContextSpain();
+  }
+
+  @Test
+  public void testRunPayment_09() {
+    boolean exception = false;
+    try {
+      OBContext.setAdminMode();
+      try {
+        // DATA SETUP
+        Invoice invoice = dataSetup();
+        FIN_Payment payment = null;
+        for (FIN_PaymentScheduleDetail psd : invoice.getFINPaymentScheduleList().get(0)
+            .getFINPaymentScheduleDetailInvoicePaymentScheduleList()) {
+          if ("RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
+            payment = psd.getPaymentDetails().getFinPayment();
+          }
+        }
+        FIN_ExecutePayment executePayment = new FIN_ExecutePayment();
+        List<FIN_Payment> payments = new ArrayList<FIN_Payment>();
+        payments.add(payment);
+        executePayment.init("OTHER",
+            OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS),
+            payments, null, payment.getOrganization());
+        OBError result = executePayment.execute();
+
+        // CHECK PAYMENT EXECUTION
+        assertTrue("Payment error while executing", !"Error".equals(result.getType()));
+        Order order = invoice.getSalesOrder();
+        // CHECK OUTPUT DATA ORDER
+        assertTrue(
+            "Order Payment Schedule Outstanding Amount ("
+                + order.getFINPaymentScheduleList().get(0).getOutstandingAmount() + ")!= 0",
+            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) == 0);
+        // CHECK OUTPUT DATA INVOICE
+        assertTrue(
+            "Invoice Payment Schedule Outstanding Amount ("
+                + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount() + ") != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) == 0);
+        assertTrue("Invoice remains not paid", invoice.isPaymentComplete());
+        assertTrue(
+            "Invoice Payment Schedule Received Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
+        // CHECK OUTPUT DATA PAYMENT
+        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E86301FA"; // Hoteles Buenas Noches, S.A.
+    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
+    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
+    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
+    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
+    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
+    String discountId = "831A7639FBE348B1A06EA3C0B0616B75"; // Descuento 10%
+
+    // Process
+    BigDecimal quantity = new BigDecimal("10");
+    BigDecimal invoicedQuantity = new BigDecimal("10");
+    BigDecimal netUnitPrice = new BigDecimal("10");
+    BigDecimal netListPrice = new BigDecimal("10");
+    BigDecimal lineNetAmount = new BigDecimal("100");
+    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
+    BigDecimal paymentAmount = new BigDecimal("50");
+    BigDecimal priceLimit = new BigDecimal("10");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+    DocumentType testOrderDocumentType = OBDal.getInstance()
+        .get(DocumentType.class, orderDocTypeId);
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_09",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
+        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
+        true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_09",
+        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
+        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
+    testBusinessPartner.setAccount(testAccount);
+    OBDal.getInstance().save(testBusinessPartner);
+
+    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
+    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
+        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
+        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    // OrderDiscount oDiscount = order.getOrderDiscountList().get(0);
+    // Discount discount = oDiscount.getDiscount();
+    // order.setOrderDiscountList(null);
+    // OBDal.getInstance().remove(oDiscount);
+    // OBDal.getInstance().save(order);
+
+    TestUtility.processOrder(order);
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
+              .getFINPaymentScheduleList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount == 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount == 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
+        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
+        false);
+
+    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
+        "APRM_PM_PAYMENT_09_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
+        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
+        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
+
+    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
+    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
+    payment.setPaymentMethod(awaitingExecutionPM);
+    OBDal.getInstance().save(payment);
+    // PROCESS THE PAYMENT
+    TestUtility.processPayment(payment, "P");
+    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
+    order = OBDal.getInstance().get(Order.class, order.getId());
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
+      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment
+              .getFINPaymentDetailList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount != Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount != 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Detail Write-off Amount != 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
+      assertTrue("Payment Line Write-off Amount != 0",
+          BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    // This created order is invoiced
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
+    OBDal.getInstance().refresh(invoice);
+    // Order is associated both to header and lines
+    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
+    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
+
+    OBDal.getInstance().save(invoiceLine);
+
+    invoice.setSalesOrder(order);
+
+    OBDal.getInstance().save(invoice);
+
+    // Add invoice Discount
+    Discount discount = OBDal.getInstance().get(Discount.class, discountId);
+    InvoiceDiscount invoiceDiscount = OBProvider.getInstance().get(InvoiceDiscount.class);
+    invoiceDiscount.setInvoice(invoice);
+    invoiceDiscount.setLineNo(10l);
+    invoiceDiscount.setDiscount(discount);
+    OBDal.getInstance().save(invoiceDiscount);
+
+    TestUtility.processInvoice(invoice);
+    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+    return invoice;
+  }
+
+  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
+    BigDecimal amount = BigDecimal.ZERO;
+    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
+      boolean isInvoice = ps.getInvoice() != null;
+      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
+          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
+          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
+        if (psd.getPaymentDetails() != null
+            && psd.getPaymentDetails().getFinPayment().isProcessed()
+            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
+          amount = amount.add(psd.getAmount());
+        }
+      }
+    }
+    return amount;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_10.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,348 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2011-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.process.FIN_ExecutePayment;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.enterprise.Warehouse;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.invoice.InvoiceDiscount;
+import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.discount.Discount;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+public class PaymentTest_10 extends OBBaseTest {
+
+  // 1) Create an order without discount
+  // 2) Add a partial payment but do not execute it
+  // 3) Invoice the complete order (with discount) using an automatic receipt payment method
+  // 4) Review payment info
+  // 5) Execute payment
+  // 6) Review payment info
+
+  private static final Logger log = Logger.getLogger(PaymentTest_10.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String AUTOMATIC_EXECUTION = "A";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_10";
+  private static final String SIMPLE_EXECUTION_PROCESS = "717D521D5F454FAD9199B831001BB4E0";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP10() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP10() throws Exception {
+    TestUtility.setTestContextSpain();
+  }
+
+  @Test
+  public void testRunPayment_10() {
+    boolean exception = false;
+    try {
+      OBContext.setAdminMode();
+      try {
+        // DATA SETUP
+        Invoice invoice = dataSetup();
+        FIN_Payment payment = null;
+        for (FIN_PaymentScheduleDetail psd : invoice.getFINPaymentScheduleList().get(0)
+            .getFINPaymentScheduleDetailInvoicePaymentScheduleList()) {
+          if ("RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
+            payment = psd.getPaymentDetails().getFinPayment();
+          }
+        }
+
+        FIN_ExecutePayment executePayment = new FIN_ExecutePayment();
+        List<FIN_Payment> payments = new ArrayList<FIN_Payment>();
+        payments.add(payment);
+        executePayment.init("OTHER",
+            OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS),
+            payments, null, payment.getOrganization());
+        OBError result = executePayment.execute();
+        // CHECK PAYMENT EXECUTION
+        assertTrue("Payment error while executing", !"Error".equals(result.getType()));
+
+        Order order = invoice.getSalesOrder();
+        // CHECK OUTPUT DATA ORDER
+        assertTrue(
+            "Order Payment Schedule Outstanding Amount != 0",
+            BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) == 0);
+        assertTrue(
+            "Invoice: " + invoice.getDocumentNo() + " Order Payment Schedule Received Amount ("
+                + order.getGrandTotalAmount().toPlainString() + ") != Total Amount ("
+                + getPaidAmount(order.getFINPaymentScheduleList()).toPlainString() + ")",
+            order.getGrandTotalAmount().compareTo(getPaidAmount(order.getFINPaymentScheduleList())) == 0);
+        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
+        // CHECK OUTPUT DATA INVOICE
+        assertTrue(
+            "Invoice Payment Schedule Outstanding Amount != 0",
+            BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
+                .getOutstandingAmount()) == 0);
+        assertTrue("Invoice remains not paid", invoice.isPaymentComplete());
+        assertTrue(
+            "Invoice Payment Schedule Received Amount != Total Amount",
+            invoice.getGrandTotalAmount().compareTo(
+                getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
+        // CHECK OUTPUT DATA PAYMENT
+        assertTrue("Status != Payment Received", "RPR".equals(payment.getStatus()));
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E86301FA"; // Hoteles Buenas Noches, S.A.
+    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
+    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
+    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
+    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
+    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
+    String discountId = "831A7639FBE348B1A06EA3C0B0616B75"; // Descuento 10%
+
+    // Process
+    BigDecimal quantity = new BigDecimal("10");
+    BigDecimal invoicedQuantity = new BigDecimal("10");
+    BigDecimal netUnitPrice = new BigDecimal("10");
+    BigDecimal netListPrice = new BigDecimal("10");
+    BigDecimal lineNetAmount = new BigDecimal("100");
+    BigDecimal paymentAmount = new BigDecimal("50");
+    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
+    BigDecimal priceLimit = new BigDecimal("10");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+    DocumentType testOrderDocumentType = OBDal.getInstance()
+        .get(DocumentType.class, orderDocTypeId);
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_10",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
+        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
+        true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_10",
+        STANDARD_DESCRIPTION, true, true, false, MANUAL_EXECUTION, null, false, IN_TRANSIT_ACCOUNT,
+        DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    // UPDATE BPARTNER AND ASSOCIATED NEW FINANCIAL ACCOUNT
+    testBusinessPartner.setAccount(testAccount);
+    OBDal.getInstance().save(testBusinessPartner);
+
+    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
+    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
+        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
+        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processOrder(order);
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
+              .getFINPaymentScheduleList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount == 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount == 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    FIN_Payment payment = TestUtility.addPaymentFromOrder(order,
+        OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId), paymentAmount,
+        false);
+
+    FIN_PaymentMethod awaitingExecutionPM = TestUtility.insertPaymentMethod(
+        "APRM_PM_PAYMENT_10_AWE", STANDARD_DESCRIPTION, true, false, false, AUTOMATIC_EXECUTION,
+        OBDal.getInstance().get(PaymentExecutionProcess.class, SIMPLE_EXECUTION_PROCESS), true,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class, new Value(
+        FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+        FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, awaitingExecutionPM));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, awaitingExecutionPM);
+
+    // SET NEW PAYMENT METHOD FOR CREATED PAYMENT: AWAITING EXECUTION
+    // NO PAYMENT INFO SHOULD BE UPDATED AS PAYMENT HAS NOT BEEN EXECUTED YET
+    payment.setPaymentMethod(awaitingExecutionPM);
+    OBDal.getInstance().save(payment);
+    // PROCESS THE PAYMENT
+    TestUtility.processPayment(payment, "P");
+    payment = OBDal.getInstance().get(FIN_Payment.class, payment.getId());
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      // CHECK OUTPUT DATA FOR ORDER AGAIN NO CHANGE SHOULD HAPPEN AS PAYMENT REMAINS AWE
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment
+              .getFINPaymentDetailList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount != Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount != 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount != 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+      assertTrue("Status != Awaiting Execution", "RPAE".equals(payment.getStatus()));
+      assertTrue("Payment Line Write-off Amount != 0",
+          BigDecimal.ZERO.compareTo(psd.getPaymentDetails().getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    // This created order is invoiced
+
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
+    OBDal.getInstance().refresh(invoice);
+    // Order is associated both to header and lines
+    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
+    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
+
+    OBDal.getInstance().save(invoiceLine);
+
+    invoice.setSalesOrder(order);
+
+    OBDal.getInstance().save(invoice);
+
+    // Add invoice Discount
+    Discount discount = OBDal.getInstance().get(Discount.class, discountId);
+    InvoiceDiscount invoiceDiscount = OBProvider.getInstance().get(InvoiceDiscount.class);
+    invoiceDiscount.setInvoice(invoice);
+    invoiceDiscount.setLineNo(10l);
+    invoiceDiscount.setDiscount(discount);
+    OBDal.getInstance().save(invoiceDiscount);
+
+    TestUtility.processInvoice(invoice);
+    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+
+    return invoice;
+  }
+
+  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
+    BigDecimal amount = BigDecimal.ZERO;
+    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
+      boolean isInvoice = ps.getInvoice() != null;
+      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
+          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
+          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
+        if (psd.getPaymentDetails() != null
+            && psd.getPaymentDetails().getFinPayment().isProcessed()
+            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
+          amount = amount.add(psd.getAmount());
+        }
+      }
+    }
+    return amount;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/PaymentTest_11.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,306 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2011-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.enterprise.Warehouse;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.test.base.OBBaseTest;
+
+public class PaymentTest_11 extends OBBaseTest {
+
+  // 1) Create an order without discount
+  // 2) Invoice the complete order (without discount)
+  // 3) Review payment plan info
+  // 4) Receive and process a payment against the invoice for the full amount
+  // 5) Review payment info
+
+  private static final Logger log = Logger.getLogger(PaymentTest_10.class);
+
+  private static final String MANUAL_EXECUTION = "M";
+  private static final String CLEARED_ACCOUNT = "CLE";
+  private static final String IN_TRANSIT_ACCOUNT = "INT";
+  private static final String WITHDRAWN_ACCOUNT = "WIT";
+  private static final String DEPOSIT_ACCOUNT = "DEP";
+  private static final String CASH = "C";
+  private static final String STANDARD_DESCRIPTION = "JUnit Test Payment_10";
+
+  private String financialAccountId;
+
+  /**
+   * Initial Set up.
+   * 
+   * This before method is named setUpP11() to avoid overwriting the super setUp method that is
+   * invoke automatically before this one.
+   * 
+   */
+  @Before
+  public void setUpP11() throws Exception {
+    TestUtility.setTestContextSpain();
+  }
+
+  @Test
+  public void testRunPayment_11() {
+    boolean exception = false;
+    FIN_Payment payment = null;
+    try {
+      OBContext.setAdminMode();
+      try {
+        // DATA SETUP
+        Invoice invoice = dataSetup();
+        Order order = invoice.getSalesOrder();
+
+        // CHECK OUTPUT DATA ORDER
+        assertTrue(
+            "Order Payment Schedule Outstanding Amount ("
+                + order.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
+                + ") != Total Amount (" + order.getGrandTotalAmount().toPlainString() + ")",
+            order.getGrandTotalAmount().compareTo(
+                order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue(
+            "Order Payment Schedule Received Amount ("
+                + getPaidAmount(order.getFINPaymentScheduleList()).toPlainString() + ") != 0",
+            BigDecimal.ZERO.compareTo(getPaidAmount(order.getFINPaymentScheduleList())) == 0);
+
+        // CHECK OUTPUT DATA INVOICE
+        assertTrue(
+            "Invoice Payment Schedule Outstanding Amount ("
+                + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount().toPlainString()
+                + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
+            invoice.getGrandTotalAmount().compareTo(
+                invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+        assertTrue("Invoice is paid", !invoice.isPaymentComplete());
+        assertTrue(
+            "Invoice Payment Schedule Received Amount "
+                + getPaidAmount(invoice.getFINPaymentScheduleList()) + " != 0",
+            BigDecimal.ZERO.compareTo(getPaidAmount(invoice.getFINPaymentScheduleList())) == 0);
+
+        payment = TestUtility.addPaymentFromInvoice(invoice,
+            OBDal.getInstance().get(FIN_FinancialAccount.class, financialAccountId),
+            invoice.getGrandTotalAmount(), false);
+        TestUtility.processPayment(payment, "P");
+
+        // CHECK OUTPUT DATA PAYMENT
+        OBContext.setAdminMode();
+        try {
+          FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(
+              FIN_PaymentScheduleDetail.class, new Value(
+                  FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE, invoice
+                      .getFINPaymentScheduleList().get(0)));
+
+          assertTrue(
+              "Payment Schedule Outstanding Amount ("
+                  + invoice.getFINPaymentScheduleList().get(0).getOutstandingAmount()
+                      .toPlainString() + ") != 0",
+              BigDecimal.ZERO.compareTo(invoice.getFINPaymentScheduleList().get(0)
+                  .getOutstandingAmount()) == 0);
+
+          assertTrue(
+              "Payment Schedule Received Amount ("
+                  + invoice.getFINPaymentScheduleList().get(0).getPaidAmount().toPlainString()
+                  + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
+              invoice.getGrandTotalAmount().compareTo(
+                  invoice.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+          assertTrue("Payment Schedule Detail Amount (" + psd.getAmount().toPlainString()
+              + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
+              invoice.getGrandTotalAmount().compareTo(psd.getAmount()) == 0);
+
+          assertTrue("Payment Schedule Detail Write-off Amount ("
+              + psd.getWriteoffAmount().toPlainString() + ") != 0",
+              BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+
+          assertTrue("Payment Amount (" + payment.getAmount().toPlainString()
+              + ") != Total Amount (" + invoice.getGrandTotalAmount().toPlainString() + ")",
+              invoice.getGrandTotalAmount().compareTo(payment.getAmount()) == 0);
+
+          assertTrue("Status (" + payment.getStatus() + ") != Payment Received",
+              "RPR".equals(payment.getStatus()));
+
+        } finally {
+          OBContext.restorePreviousMode();
+        }
+
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(FIN_Utility.getExceptionMessage(e));
+      exception = true;
+    }
+
+    assertFalse(exception);
+
+  }
+
+  private Invoice dataSetup() throws Exception {
+
+    // DATA SETUP
+    String bpartnerId = "8A64B71A2B0B2946012B0FE1E86301FA"; // Hoteles Buenas Noches, S.A.
+    String priceListId = "8A64B71A2B0B2946012B0BD97324018A"; // Precios de Venta
+    String paymentTermId = "3F22D83730EE4FD5AE42542A2839DAC4"; // 30 days
+    String currencyId = "102"; // EUR
+    String productId = "8A64B71A2B0B2946012B0BC438410118"; // Vino Tinto 0,75L
+    String taxId = "F27A37C66749487A876F4DA0EF7467E3"; // Ventas Exentas
+    String docTypeId = "40EE9B1CD3B345FABEFDA62B407B407F"; // AR Invoice
+    String orderDocTypeId = "CB6EEA256BBC41109911215C5A14D39B"; // Standard Order
+    String warehouseId = "71B43F2AAE3641CA849B131960BCEFF4";
+    // Process
+    BigDecimal quantity = new BigDecimal("10");
+    BigDecimal invoicedQuantity = new BigDecimal("10");
+    BigDecimal netUnitPrice = new BigDecimal("10");
+    BigDecimal netListPrice = new BigDecimal("10");
+    BigDecimal lineNetAmount = new BigDecimal("100");
+    BigDecimal invoiceLineNetAmount = new BigDecimal("100");
+    BigDecimal priceLimit = new BigDecimal("10");
+
+    PriceList testPriceList = OBDal.getInstance().get(PriceList.class, priceListId);
+    BusinessPartner testBusinessPartner = OBDal.getInstance()
+        .get(BusinessPartner.class, bpartnerId);
+    Location location = TestUtility.getOneInstance(Location.class, new Value(
+        Location.PROPERTY_BUSINESSPARTNER, testBusinessPartner));
+    PaymentTerm testPaymentTerm = OBDal.getInstance().get(PaymentTerm.class, paymentTermId);
+    Currency testCurrency = OBDal.getInstance().get(Currency.class, currencyId);
+    Product testProduct = OBDal.getInstance().get(Product.class, productId);
+    UOM uom = TestUtility.getOneInstance(UOM.class, new Value(UOM.PROPERTY_NAME, testProduct
+        .getUOM().getName()));
+    TaxRate testTaxRate = OBDal.getInstance().get(TaxRate.class, taxId);
+    DocumentType testDocumentType = OBDal.getInstance().get(DocumentType.class, docTypeId);
+    DocumentType testOrderDocumentType = OBDal.getInstance()
+        .get(DocumentType.class, orderDocTypeId);
+    FIN_FinancialAccount testAccount = TestUtility.insertFinancialAccount("APRM_FINACC_PAYMENT_11",
+        STANDARD_DESCRIPTION, testCurrency, CASH, false,
+        getOneInstance(org.openbravo.model.common.geography.Location.class), null, null, null,
+        null, null, null, null, null, null, null, BigDecimal.ZERO, BigDecimal.ZERO, null, true,
+        true);
+
+    FIN_PaymentMethod testPaymentMethod = TestUtility.insertPaymentMethod("APRM_PM_PAYMENT_11",
+        STANDARD_DESCRIPTION, true, false, false, MANUAL_EXECUTION, null, false,
+        IN_TRANSIT_ACCOUNT, DEPOSIT_ACCOUNT, CLEARED_ACCOUNT, true, false, false, MANUAL_EXECUTION,
+        null, false, IN_TRANSIT_ACCOUNT, WITHDRAWN_ACCOUNT, CLEARED_ACCOUNT, true, true);
+
+    FinAccPaymentMethod existAssociation = TestUtility.getOneInstance(FinAccPaymentMethod.class,
+        new Value(FinAccPaymentMethod.PROPERTY_ACCOUNT, testAccount), new Value(
+            FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, testPaymentMethod));
+
+    if (existAssociation == null)
+      TestUtility.associatePaymentMethod(testAccount, testPaymentMethod);
+    this.financialAccountId = testAccount.getId();
+
+    Warehouse warehouse = OBDal.getInstance().get(Warehouse.class, warehouseId);
+    Order order = TestUtility.createNewOrder(OBContext.getOBContext().getCurrentClient(), OBContext
+        .getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testOrderDocumentType, testBusinessPartner, location, warehouse, "I", testPriceList,
+        testCurrency, testPaymentMethod, testPaymentTerm, testProduct, uom, quantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, lineNetAmount, true);
+
+    TestUtility.processOrder(order);
+    order = OBDal.getInstance().get(Order.class, order.getId());
+
+    // CHECK OUTPUT DATA FOR ORDER
+    OBContext.setAdminMode();
+    try {
+      FIN_PaymentScheduleDetail psd = TestUtility.getOneInstance(FIN_PaymentScheduleDetail.class,
+          new Value(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, order
+              .getFINPaymentScheduleList().get(0)));
+
+      assertTrue("Payment Schedule Outstanding Amount == Order amount", order.getGrandTotalAmount()
+          .compareTo(order.getFINPaymentScheduleList().get(0).getOutstandingAmount()) == 0);
+      assertTrue("Payment Schedule Received Amount == 0",
+          BigDecimal.ZERO.compareTo(order.getFINPaymentScheduleList().get(0).getPaidAmount()) == 0);
+
+      assertTrue("Payment Schedule Deatail Amount == Total Amount", order.getGrandTotalAmount()
+          .compareTo(psd.getAmount()) == 0);
+      assertTrue("Payment Schedule Detail Write-off Amount == 0",
+          BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+
+    // This created order is invoiced
+    Invoice invoice = TestUtility.createNewInvoice(OBContext.getOBContext().getCurrentClient(),
+        OBContext.getOBContext().getCurrentOrganization(), new Date(), new Date(), new Date(),
+        testDocumentType, testBusinessPartner, location, testPriceList, testCurrency,
+        testPaymentMethod, testPaymentTerm, testProduct, uom, invoicedQuantity, netUnitPrice,
+        netListPrice, priceLimit, testTaxRate, invoiceLineNetAmount, true);
+    OBDal.getInstance().refresh(invoice);
+    // Order is associated both to header and lines
+    InvoiceLine invoiceLine = invoice.getInvoiceLineList().get(0);
+    invoiceLine.setSalesOrderLine(order.getOrderLineList().get(0));
+
+    OBDal.getInstance().save(invoiceLine);
+
+    invoice.setSalesOrder(order);
+
+    OBDal.getInstance().save(invoice);
+
+    TestUtility.processInvoice(invoice);
+    invoice = OBDal.getInstance().get(Invoice.class, invoice.getId());
+    return invoice;
+  }
+
+  BigDecimal getPaidAmount(List<FIN_PaymentSchedule> finPaymentScheduleList) {
+    BigDecimal amount = BigDecimal.ZERO;
+    for (FIN_PaymentSchedule ps : finPaymentScheduleList) {
+      boolean isInvoice = ps.getInvoice() != null;
+      for (FIN_PaymentScheduleDetail psd : isInvoice ? ps
+          .getFINPaymentScheduleDetailInvoicePaymentScheduleList() : ps
+          .getFINPaymentScheduleDetailOrderPaymentScheduleList()) {
+        if (psd.getPaymentDetails() != null
+            && psd.getPaymentDetails().getFinPayment().isProcessed()
+            && !"RPAE".equals(psd.getPaymentDetails().getFinPayment().getStatus())) {
+          amount = amount.add(psd.getAmount());
+        }
+      }
+    }
+    return amount;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/TestUtility.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,567 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
+import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.base.provider.OBConfigFileProvider;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.database.ConnectionProviderImpl;
+import org.openbravo.exception.PoolNotFoundException;
+import org.openbravo.model.ad.process.ProcessInstance;
+import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.ad.ui.Process;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.enterprise.Warehouse;
+import org.openbravo.model.common.geography.Location;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.model.common.order.OrderLine;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.uom.UOM;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentProposal;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.financialmgmt.payment.MatchingAlgorithm;
+import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcess;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.tax.TaxRate;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.service.db.CallProcess;
+import org.openbravo.test.base.OBBaseTest;
+
+public class TestUtility extends OBBaseTest {
+
+  private static final Logger log = Logger.getLogger(TestUtility.class);
+
+  public static FIN_FinancialAccount insertFinancialAccount(String name, String description,
+      Currency currency, String type, boolean isDefault, Location location,
+      BusinessPartner businessPartner, String bankCode, String branchCode, String bankControlDigit,
+      String iNeNo, String swiftCode, String accountControlDigit, String partialAccNo,
+      String accountNo, String iban, BigDecimal currentBalance, BigDecimal creditLimit,
+      MatchingAlgorithm matchingAlgorithm, boolean isValid, boolean checkIfExist) {
+
+    if (checkIfExist) {
+      final OBCriteria<FIN_FinancialAccount> obc = OBDal.getInstance().createCriteria(
+          FIN_FinancialAccount.class);
+      obc.add(Restrictions.eq(FIN_FinancialAccount.PROPERTY_NAME, name));
+      if (obc.list() != null && obc.list().size() > 0) {
+        return obc.list().get(0);
+      }
+    }
+
+    FIN_FinancialAccount finAcc = OBProvider.getInstance().get(FIN_FinancialAccount.class);
+
+    finAcc.setName(name);
+    finAcc.setDescription(description);
+    finAcc.setCurrency(currency);
+    finAcc.setType(type);
+    finAcc.setDefault(isDefault);
+    finAcc.setLocationAddress(location);
+    finAcc.setBusinessPartner(businessPartner);
+
+    // Bank
+    finAcc.setBankCode(bankCode);
+    finAcc.setBranchCode(branchCode);
+    finAcc.setBankDigitcontrol(bankControlDigit);
+    finAcc.setINENo(iNeNo);
+    finAcc.setSwiftCode(swiftCode);
+
+    // Bank Account
+    finAcc.setAccountDigitcontrol(accountControlDigit);
+    finAcc.setPartialAccountNo(partialAccNo);
+    finAcc.setAccountNo(accountNo);
+    finAcc.setIBAN(iban);
+
+    // Amounts
+    finAcc.setCurrentBalance(currentBalance);
+    finAcc.setCreditLimit(creditLimit);
+    finAcc.setMatchingAlgorithm(matchingAlgorithm);
+
+    boolean exception = false;
+    try {
+      // force dal commit to throw exception
+      OBDal.getInstance().save(finAcc);
+      OBDal.getInstance().flush();
+      OBDal.getInstance().commitAndClose();
+    } catch (Exception e) {
+      log.error(e);
+      exception = true;
+      OBDal.getInstance().rollbackAndClose();
+    }
+
+    if (isValid)
+      assertFalse("Not inserted a valid financial account:" + name, exception);
+    else
+      assertTrue("Inserted a non-valid financial account:" + name, exception);
+
+    if (exception)
+      return null;
+    else
+      return finAcc;
+  }
+
+  public static FIN_PaymentMethod insertPaymentMethod(String name, String description,
+      boolean isPayInAllowed, boolean isAutomaticReceipt, boolean isAutomaticDeposit,
+      String payInExecutionType, PaymentExecutionProcess payInExecutionProcess,
+      boolean isPayinDeferred, String uponReceiptUse, String uponDepositUse,
+      String inUponClearingUse, boolean isPayOutAllowed, boolean isAutomaticPayment,
+      boolean isAutomaticWithdrawn, String payOutExecutionType,
+      PaymentExecutionProcess payOutExecutionProcess, boolean isPayoutDeferred,
+      String uponPaymentUse, String uponWithdrawalUse, String outUponClearingUse, boolean isValid,
+      boolean checkIfExist) {
+
+    if (checkIfExist) {
+      final OBCriteria<FIN_PaymentMethod> obc = OBDal.getInstance().createCriteria(
+          FIN_PaymentMethod.class);
+      obc.add(Restrictions.eq(FIN_PaymentMethod.PROPERTY_NAME, name));
+      if (obc.list() != null && obc.list().size() > 0) {
+        return obc.list().get(0);
+      }
+    }
+
+    FIN_PaymentMethod paymentMethod = OBProvider.getInstance().get(FIN_PaymentMethod.class);
+
+    paymentMethod.setName(name);
+    paymentMethod.setDescription(description);
+
+    // Payment IN
+    paymentMethod.setPayinAllow(isPayInAllowed);
+    paymentMethod.setAutomaticReceipt(isAutomaticReceipt);
+    paymentMethod.setAutomaticDeposit(isAutomaticDeposit);
+
+    paymentMethod.setPayinExecutionType(payInExecutionType);
+    paymentMethod.setPayinExecutionProcess(payInExecutionProcess);
+    paymentMethod.setPayinDeferred(isPayinDeferred);
+    paymentMethod.setUponReceiptUse(uponReceiptUse);
+    paymentMethod.setUponDepositUse(uponDepositUse);
+    paymentMethod.setINUponClearingUse(inUponClearingUse);
+
+    // Payment OUT
+    paymentMethod.setPayoutAllow(isPayOutAllowed);
+    paymentMethod.setAutomaticPayment(isAutomaticPayment);
+    paymentMethod.setAutomaticWithdrawn(isAutomaticWithdrawn);
+
+    paymentMethod.setPayoutExecutionType(payOutExecutionType);
+    paymentMethod.setPayoutExecutionProcess(payOutExecutionProcess);
+    paymentMethod.setPayoutDeferred(isPayoutDeferred);
+
+    paymentMethod.setUponPaymentUse(uponPaymentUse);
+    paymentMethod.setUponWithdrawalUse(uponWithdrawalUse);
+    paymentMethod.setOUTUponClearingUse(outUponClearingUse);
+
+    OBDal.getInstance().save(paymentMethod);
+
+    boolean exception = false;
+    try {
+      // force dal commit to throw exception
+      OBDal.getInstance().flush();
+      OBDal.getInstance().commitAndClose();
+    } catch (Exception e) {
+      log.error(e);
+      exception = true;
+      OBDal.getInstance().rollbackAndClose();
+    }
+
+    if (isValid)
+      assertFalse("Not inserted a valid payment method:" + name, exception);
+    else
+      assertTrue("Inserted a non-valid payment method:" + name, exception);
+
+    if (exception)
+      return null;
+    else
+      return paymentMethod;
+  }
+
+  public static FinAccPaymentMethod associatePaymentMethod(FIN_FinancialAccount account,
+      FIN_PaymentMethod paymentMethod) {
+    FinAccPaymentMethod accountPay = OBProvider.getInstance().get(FinAccPaymentMethod.class);
+    accountPay.setAccount(account);
+    accountPay.setPaymentMethod(paymentMethod);
+
+    accountPay.setPayoutAllow(paymentMethod.isPayoutAllow());
+    accountPay.setPayoutDeferred(paymentMethod.isPayoutDeferred());
+    accountPay.setPayoutExecutionProcess(paymentMethod.getPayoutExecutionProcess());
+    accountPay.setPayoutExecutionType(paymentMethod.getPayoutExecutionType());
+    accountPay.setAutomaticReceipt(paymentMethod.isAutomaticReceipt());
+    accountPay.setAutomaticDeposit(paymentMethod.isAutomaticDeposit());
+    accountPay.setUponReceiptUse(paymentMethod.getUponReceiptUse());
+    accountPay.setUponDepositUse(paymentMethod.getUponDepositUse());
+    accountPay.setOUTUponClearingUse(paymentMethod.getOUTUponClearingUse());
+
+    accountPay.setPayinAllow(paymentMethod.isPayinAllow());
+    accountPay.setPayinDeferred(paymentMethod.isPayinDeferred());
+    accountPay.setPayinExecutionProcess(paymentMethod.getPayinExecutionProcess());
+    accountPay.setPayinExecutionType(paymentMethod.getPayinExecutionType());
+    accountPay.setAutomaticPayment(paymentMethod.isAutomaticPayment());
+    accountPay.setAutomaticWithdrawn(paymentMethod.isAutomaticWithdrawn());
+    accountPay.setUponPaymentUse(paymentMethod.getUponPaymentUse());
+    accountPay.setUponWithdrawalUse(paymentMethod.getUponWithdrawalUse());
+    accountPay.setINUponClearingUse(paymentMethod.getINUponClearingUse());
+
+    boolean exception = false;
+    try {
+      // force dal commit to throw exception
+      OBDal.getInstance().save(accountPay);
+      OBDal.getInstance().flush();
+    } catch (org.hibernate.exception.GenericJDBCException e) {
+      log.error(e);
+      exception = true;
+      OBDal.getInstance().rollbackAndClose();
+    }
+
+    assertFalse("Not associated a valid payment method to the financial account", exception);
+
+    if (exception)
+      return null;
+    else
+      return accountPay;
+
+  }
+
+  public static Order createNewOrder(Client client, Organization org, Date orderDate,
+      Date accountingDate, Date taxDate, DocumentType documentType, BusinessPartner bp,
+      org.openbravo.model.common.businesspartner.Location loc, Warehouse warehouse,
+      String invoiceTerm, PriceList priceList, Currency currency, FIN_PaymentMethod paymentMethod,
+      PaymentTerm paymentTerm, Product product, UOM uom, BigDecimal orderedQuantity,
+      BigDecimal netUnitPrice, BigDecimal netListPrice, BigDecimal priceLimit, TaxRate taxRate,
+      BigDecimal lineNetAmount, boolean isReceipt) throws Exception {
+
+    // Create header
+    Order order = OBProvider.getInstance().get(Order.class);
+    order.setOrganization(org);
+    order.setClient(client);
+    order.setDocumentType(documentType);
+    order.setTransactionDocument(documentType);
+    order.setDocumentNo(FIN_Utility.getDocumentNo(org, "SOO", "C_Order"));
+    order.setAccountingDate(accountingDate);
+    order.setOrderDate(orderDate);
+    order.setWarehouse(warehouse);
+    if (!"".equals(invoiceTerm)) {
+      order.setInvoiceTerms(invoiceTerm);
+    }
+    // order.setTaxDate(taxDate);
+    order.setBusinessPartner(bp);
+    order.setPartnerAddress(loc);
+    order.setPriceList(priceList);
+    order.setCurrency(currency);
+    order.setSummedLineAmount(BigDecimal.ZERO);
+    order.setGrandTotalAmount(BigDecimal.ZERO);
+    // order.setWithholdingamount(BigDecimal.ZERO);
+    order.setSalesTransaction(isReceipt);
+    order.setPaymentMethod(paymentMethod);
+    order.setPaymentTerms(paymentTerm);
+
+    OBDal.getInstance().save(order);
+    OBDal.getInstance().flush();
+
+    // Create one line
+    OrderLine orderLine = OBProvider.getInstance().get(OrderLine.class);
+    orderLine.setOrganization(org);
+    orderLine.setClient(client);
+    orderLine.setSalesOrder(order);
+    orderLine.setOrderDate(orderDate);
+    orderLine.setWarehouse(warehouse);
+    orderLine.setCurrency(currency);
+    orderLine.setLineNo(new Long("10"));
+    orderLine.setProduct(product);
+    orderLine.setUOM(uom);
+    orderLine.setInvoicedQuantity(BigDecimal.ZERO);
+    orderLine.setOrderedQuantity(orderedQuantity);
+    orderLine.setUnitPrice(netUnitPrice);
+    orderLine.setListPrice(netListPrice);
+    orderLine.setPriceLimit(priceLimit);
+    orderLine.setTax(taxRate);
+    orderLine.setLineNetAmount(lineNetAmount);
+
+    OBDal.getInstance().save(orderLine);
+    OBDal.getInstance().flush();
+
+    return order;
+  }
+
+  public static boolean processOrder(Order order) throws Exception {
+    OBContext.setAdminMode();
+    Process process = null;
+    try {
+      process = OBDal.getInstance().get(Process.class, "104");
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    final ProcessInstance pinstance = CallProcess.getInstance().call(process, order.getId(), null);
+    OBDal.getInstance().save(order);
+    OBDal.getInstance().flush();
+    OBDal.getInstance().commitAndClose();
+    return (pinstance.getResult() == 0L);
+  }
+
+  public static Invoice createNewInvoice(Client client, Organization org, Date invoiceDate,
+      Date accountingDate, Date taxDate, DocumentType documentType, BusinessPartner bp,
+      org.openbravo.model.common.businesspartner.Location loc, PriceList priceList,
+      Currency currency, FIN_PaymentMethod paymentMethod, PaymentTerm paymentTerm, Product product,
+      UOM uom, BigDecimal invoicedQuantity, BigDecimal netUnitPrice, BigDecimal netListPrice,
+      BigDecimal priceLimit, TaxRate taxRate, BigDecimal lineNetAmount, boolean isReceipt)
+      throws Exception {
+
+    // Create header
+    Invoice invoice = OBProvider.getInstance().get(Invoice.class);
+    invoice.setOrganization(org);
+    invoice.setClient(client);
+    invoice.setDocumentType(documentType);
+    invoice.setTransactionDocument(documentType);
+    invoice.setDocumentNo(FIN_Utility.getDocumentNo(org, "ARI", "C_Invoice"));
+    invoice.setAccountingDate(accountingDate);
+    invoice.setInvoiceDate(invoiceDate);
+    invoice.setTaxDate(taxDate);
+    invoice.setBusinessPartner(bp);
+    invoice.setPartnerAddress(loc);
+    invoice.setPriceList(priceList);
+    invoice.setCurrency(currency);
+    invoice.setSummedLineAmount(BigDecimal.ZERO);
+    invoice.setGrandTotalAmount(BigDecimal.ZERO);
+    invoice.setWithholdingamount(BigDecimal.ZERO);
+    invoice.setSalesTransaction(isReceipt);
+    invoice.setPaymentMethod(paymentMethod);
+    invoice.setPaymentTerms(paymentTerm);
+
+    OBDal.getInstance().save(invoice);
+    OBDal.getInstance().flush();
+
+    // Create one line
+    InvoiceLine invoiceLine = OBProvider.getInstance().get(InvoiceLine.class);
+    invoiceLine.setOrganization(org);
+    invoiceLine.setClient(client);
+    invoiceLine.setInvoice(invoice);
+    invoiceLine.setLineNo(new Long("10"));
+    invoiceLine.setProduct(product);
+    invoiceLine.setUOM(uom);
+    invoiceLine.setInvoicedQuantity(invoicedQuantity);
+    invoiceLine.setUnitPrice(netUnitPrice);
+    invoiceLine.setListPrice(netListPrice);
+    invoiceLine.setPriceLimit(priceLimit);
+    invoiceLine.setTax(taxRate);
+    invoiceLine.setLineNetAmount(lineNetAmount);
+
+    OBDal.getInstance().save(invoiceLine);
+    OBDal.getInstance().flush();
+
+    return invoice;
+  }
+
+  public static boolean processInvoice(Invoice invoice) throws Exception {
+    OBContext.setAdminMode();
+    Process process = null;
+    try {
+      process = OBDal.getInstance().get(Process.class, "111");
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    final ProcessInstance pinstance = CallProcess.getInstance()
+        .call(process, invoice.getId(), null);
+    OBDal.getInstance().save(invoice);
+    OBDal.getInstance().flush();
+    OBDal.getInstance().commitAndClose();
+    return (pinstance.getResult() == 0L);
+  }
+
+  public static FIN_Payment addPaymentFromInvoice(Invoice invoice, FIN_FinancialAccount account,
+      BigDecimal amount, boolean isWriteOff) throws Exception {
+    AdvPaymentMngtDao dao = new AdvPaymentMngtDao();
+
+    OBDal.getInstance().getSession().refresh(invoice);
+    List<FIN_PaymentScheduleDetail> scheduleDetails = dao
+        .getInvoicePendingScheduledPaymentDetails(invoice);
+
+    HashMap<String, BigDecimal> paidAmount = new HashMap<String, BigDecimal>();
+    paidAmount.put(scheduleDetails.get(0).getId(), amount);
+
+    FIN_Payment payment = FIN_AddPayment
+        .savePayment(null, invoice.isSalesTransaction(),
+            FIN_Utility.getDocumentType(invoice.getOrganization(), "ARR"),
+            FIN_Utility.getDocumentNo(invoice.getOrganization(), "APP", "FIN_Payment"),
+            invoice.getBusinessPartner(), invoice.getPaymentMethod(), account, amount.toString(),
+            new Date(), invoice.getOrganization(), null, scheduleDetails, paidAmount, isWriteOff,
+            false);
+
+    return payment;
+  }
+
+  public static FIN_Payment addPaymentFromOrder(Order order, FIN_FinancialAccount account,
+      BigDecimal amount, boolean isWriteOff) throws Exception {
+    AdvPaymentMngtDao dao = new AdvPaymentMngtDao();
+
+    OBDal.getInstance().getSession().refresh(order);
+    List<FIN_PaymentScheduleDetail> scheduleDetails = dao
+        .getOrderPendingScheduledPaymentDetails(order);
+
+    HashMap<String, BigDecimal> paidAmount = new HashMap<String, BigDecimal>();
+    paidAmount.put(scheduleDetails.get(0).getId(), amount);
+
+    FIN_Payment payment = FIN_AddPayment.savePayment(null, order.isSalesTransaction(),
+        FIN_Utility.getDocumentType(order.getOrganization(), "ARR"),
+        FIN_Utility.getDocumentNo(order.getOrganization(), "APP", "FIN_Payment"),
+        order.getBusinessPartner(), order.getPaymentMethod(), account, amount.toString(),
+        new Date(), order.getOrganization(), null, scheduleDetails, paidAmount, isWriteOff, false);
+
+    return payment;
+  }
+
+  public static void processPayment(FIN_Payment payment, String strDocAction) throws Exception {
+    VariablesSecureApp vars = new VariablesSecureApp(OBContext.getOBContext().getUser().getId(),
+        OBContext.getOBContext().getCurrentClient().getId(), OBContext.getOBContext()
+            .getCurrentOrganization().getId(), OBContext.getOBContext().getRole().getId());
+
+    FIN_AddPayment.processPayment(vars, getConnectionProviderMy(), strDocAction, payment);
+  }
+
+  /**
+   * Method used to generating payment document with refund amount.
+   * 
+   * @param payment
+   *          Created Payment.
+   * @param refundAmount
+   *          Refund Amount need to transfer to the customer.
+   * @return Created FIN_Payment object.
+   * @throws Exception
+   *           In case of executing invalid data.
+   */
+  public static FIN_Payment createRefundPayment(FIN_Payment payment, BigDecimal refundAmount)
+      throws Exception {
+    OBContext.setAdminMode();
+    FIN_Payment refundPayment = null;
+    try {
+      VariablesSecureApp vars = new VariablesSecureApp(OBContext.getOBContext().getUser().getId(),
+          OBContext.getOBContext().getCurrentClient().getId(), OBContext.getOBContext()
+              .getCurrentOrganization().getId(), OBContext.getOBContext().getRole().getId());
+      refundPayment = FIN_AddPayment.createRefundPayment(getConnectionProviderMy(), vars, payment,
+          refundAmount.negate());
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return refundPayment;
+  }
+
+  public static void processPaymentProposal(FIN_PaymentProposal paymentProposal, String strDocAction)
+      throws Exception {
+    VariablesSecureApp vars = new VariablesSecureApp(OBContext.getOBContext().getUser().getId(),
+        OBContext.getOBContext().getCurrentClient().getId(), OBContext.getOBContext()
+            .getCurrentOrganization().getId(), OBContext.getOBContext().getRole().getId());
+
+    FIN_AddPayment.processPaymentProposal(vars, getConnectionProviderMy(), strDocAction,
+        paymentProposal.getId());
+  }
+
+  public static FIN_PaymentProposal createNewPaymentProposal(Client client, Organization org,
+      FIN_FinancialAccount account, Currency currency, FIN_PaymentMethod paymentMethod) {
+    FIN_PaymentProposal pp = OBProvider.getInstance().get(FIN_PaymentProposal.class);
+    pp.setOrganization(org);
+    pp.setClient(client);
+    pp.setAccount(account);
+    pp.setAmount(BigDecimal.ZERO);
+    pp.setBusinessPartner(null);
+    pp.setCurrency(currency);
+    pp.setDocumentNo(FIN_Utility.getDocumentNo(org, "APPP", "FIN_PaymentProposal"));
+    pp.setDocumentType(FIN_Utility.getDocumentType(org, "APPP"));
+    pp.setPaymentMethod(paymentMethod);
+    pp.setDuedate(null);
+    pp.setPaymentDate(new Date());
+    pp.setReceipt(false);
+    pp.setWriteoffAmount(BigDecimal.ZERO);
+    OBDal.getInstance().save(pp);
+    OBDal.getInstance().flush();
+
+    return pp;
+  }
+
+  public static <T extends BaseOBObject> T getOneInstance(Class<T> clazz, Value... values) {
+
+    // create an OBCriteria object and add a filter
+    final OBCriteria<T> obCriteria = OBDal.getInstance().createCriteria(clazz);
+
+    for (Value value : values) {
+      if (value.getValue() == null) {
+        obCriteria.add(Restrictions.isNull(value.getField()));
+      } else {
+        obCriteria.add(Restrictions.eq(value.getField(), value.getValue()));
+      }
+    }
+
+    final List<T> listt = obCriteria.list();
+    if (listt != null && listt.size() > 0) {
+      return listt.get(0);
+    } else {
+      return null;
+    }
+  }
+
+  public static void setTestContext() {
+    // User = Openbravo
+    // Role = F&B International Group Admin
+    // Client = F&B International Group
+    // Org = F&B US, Inc.
+    OBContext.setOBContext("100", "FF8080812AFBCB14012AFBD3E4340031",
+        "FF8080812AFBCB14012AFBD3E373001F", "B9C7088AB859483A9B1FB342AC2BE17A");
+  }
+
+  public static void setTestContextSpain() {
+    // User = Openbravo
+    // Role = F&B International Group Admin
+    // Client = F&B International Group
+    // Org = F&B US, Inc.
+    OBContext.setOBContext("100", "FF8080812AFBCB14012AFBD3E4340031",
+        "FF8080812AFBCB14012AFBD3E373001F", "4F68EB1C1B734E79B27DE9D2DF56089F");
+  }
+
+  private static ConnectionProvider getConnectionProviderMy() {
+    try {
+      final String propFile = OBConfigFileProvider.getInstance().getFileLocation();
+      final ConnectionProvider conn = new ConnectionProviderImpl(propFile + "/Openbravo.properties");
+      return conn;
+    } catch (PoolNotFoundException e) {
+      throw new IllegalStateException(e);
+    }
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/advpaymentmngt/test/Value.java	Tue Jul 26 13:54:18 2016 +0200
@@ -0,0 +1,38 @@
+/*
+ *************************************************************************
+ * 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 SLU
+ * All portions are Copyright (C) 2010 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.test;
+
+public class Value {
+  private String field;
+  private Object value;
+
+  public Value(String field, Object value) {
+    this.field = field;
+    this.value = value;
+  }
+
+  public String getField() {
+    return field;
+  }
+
+  public Object getValue() {
+    return value;
+  }
+}
\ No newline at end of file