Fixes issue 33531: Error posting Cash VAT payment if pays more than one invoice
authorMark <markmm82@gmail.com>
Tue, 26 Jul 2016 14:43:28 -0400
changeset 30092 5489c10e9115
parent 30091 a9de7947f68d
child 30093 3928a857fcb8
Fixes issue 33531: Error posting Cash VAT payment if pays more than one invoice

When trying to post a Cash VAT payment that pays more than one invoice, process was failing and an error was shown. It was caused by a clearing of the session when iterating on the cash vat invoices list. To avoid it, list of cash vat ids are retrieved instead a list of InvoiceTaxCashVAT_V.
src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java
src/org/openbravo/erpCommon/utility/CashVATUtil.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java	Fri Jul 15 23:25:35 2016 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java	Tue Jul 26 14:43:28 2016 -0400
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2013-2015 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -25,9 +25,9 @@
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.hibernate.Query;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
-import org.openbravo.dal.service.OBQuery;
 import org.openbravo.model.common.invoice.InvoiceTaxCashVAT_V;
 
 /**
@@ -37,7 +37,7 @@
  */
 public class DocLineCashVATReady_PaymentTransactionReconciliation extends DocLine {
 
-  List<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V = new ArrayList<InvoiceTaxCashVAT_V>();
+  List<String> invoiceTaxCashVAT_V = new ArrayList<String>();
 
   public DocLineCashVATReady_PaymentTransactionReconciliation(String DocumentType,
       String TrxHeader_ID, String TrxLine_ID) {
@@ -49,13 +49,12 @@
    * 
    * It internally creates a Set from the invoiceTaxCashVAT_V attribute and returns a List
    */
-  public List<InvoiceTaxCashVAT_V> getInvoiceTaxCashVAT_V() {
-    final Set<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V_Set = new HashSet<InvoiceTaxCashVAT_V>(
-        invoiceTaxCashVAT_V);
-    return new ArrayList<InvoiceTaxCashVAT_V>(invoiceTaxCashVAT_V_Set);
+  public List<String> getInvoiceTaxCashVAT_V() {
+    final Set<String> invoiceTaxCashVAT_V_Set = new HashSet<String>(invoiceTaxCashVAT_V);
+    return new ArrayList<String>(invoiceTaxCashVAT_V_Set);
   }
 
-  public void setInvoiceTaxCashVAT_V(List<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V) {
+  public void setInvoiceTaxCashVAT_V(List<String> invoiceTaxCashVAT_V) {
     this.invoiceTaxCashVAT_V = invoiceTaxCashVAT_V;
   }
 
@@ -66,21 +65,20 @@
    * will add (not override) the associated invoiceTaxCashVAT_V records to the object
    * 
    */
+  @SuppressWarnings("unchecked")
   public void setInvoiceTaxCashVAT_V(String finPaymentDetailID) {
     if (StringUtils.isNotBlank(finPaymentDetailID)) {
       try {
         OBContext.setAdminMode(true);
         final StringBuffer hql = new StringBuffer();
-        hql.append(" as itcv ");
+        hql.append(" select " + InvoiceTaxCashVAT_V.PROPERTY_ID);
+        hql.append(" from " + InvoiceTaxCashVAT_V.ENTITY_NAME + " as itcv ");
         hql.append(" where itcv." + InvoiceTaxCashVAT_V.PROPERTY_PAYMENTDETAILS
             + ".id = :finPaymentDetailID ");
         hql.append(" and itcv." + InvoiceTaxCashVAT_V.PROPERTY_CANCELED + " = false");
-        OBQuery<InvoiceTaxCashVAT_V> obq = OBDal.getInstance().createQuery(
-            InvoiceTaxCashVAT_V.class, hql.toString());
-        obq.setNamedParameter("finPaymentDetailID", finPaymentDetailID);
-        obq.setFilterOnReadableClients(false);
-        obq.setFilterOnReadableOrganization(false);
-
+        hql.append(" and itcv." + InvoiceTaxCashVAT_V.PROPERTY_ACTIVE + " = true");
+        Query obq = OBDal.getInstance().getSession().createQuery(hql.toString());
+        obq.setParameter("finPaymentDetailID", finPaymentDetailID);
         this.invoiceTaxCashVAT_V.addAll(obq.list());
       } finally {
         OBContext.restorePreviousMode();
--- a/src/org/openbravo/erpCommon/utility/CashVATUtil.java	Fri Jul 15 23:25:35 2016 +0200
+++ b/src/org/openbravo/erpCommon/utility/CashVATUtil.java	Tue Jul 26 14:43:28 2016 -0400
@@ -492,7 +492,8 @@
     try {
       if (invoice.isCashVAT() && !line.getInvoiceTaxCashVAT_V().isEmpty()) {
         FactLine factLine2 = null;
-        for (final InvoiceTaxCashVAT_V itcv : line.getInvoiceTaxCashVAT_V()) {
+        for (final String itcvId : line.getInvoiceTaxCashVAT_V()) {
+          InvoiceTaxCashVAT_V itcv = OBDal.getInstance().get(InvoiceTaxCashVAT_V.class, itcvId);
           final TaxRate tax = itcv.getInvoiceTax().getTax();
           Invoice inv = itcv.getInvoiceTax().getInvoice();
           if (tax.isCashVAT() && StringUtils.equals(inv.getId(), invoice.getId())) {