details:   https://code.openbravo.com/erp/devel/pi/rev/429081c6bccb
changeset: 29812:429081c6bccb
user:      Mark <markmm82 <at> gmail.com>
date:      Tue Jul 26 14:43:28 2016 -0400
summary:   Fixes issue 33508: 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.

details:   https://code.openbravo.com/erp/devel/pi/rev/7ebe0a53a425
changeset: 29813:7ebe0a53a425
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Mon Aug 01 13:21:44 2016 +0200
summary:   Related to issue 33508: Code review improvements

Set invoiceTaxCashVAT_V variable as private.
Keep getInvoiceTaxCashVAT_V and setInvoiceTaxCashVAT_V methods as deprecated to 
avoid API change.
Add distinct to setInvoiceTaxCashVAT_V query to avoid retrieve duplicated ids.

diffstat:

 
src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java
 |  49 +++++++--
 src/org/openbravo/erpCommon/utility/CashVATUtil.java                           
                |   5 +-
 2 files changed, 40 insertions(+), 14 deletions(-)

diffs (119 lines):

diff -r 6bef7cf32538 -r 7ebe0a53a425 
src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java
--- 
a/src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java
    Fri Jul 29 11:18:31 2016 +0200
+++ 
b/src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java
    Mon Aug 01 13:21:44 2016 +0200
@@ -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>();
+  private List<String> invoiceTaxCashVAT_V = new ArrayList<String>();
 
   public DocLineCashVATReady_PaymentTransactionReconciliation(String 
DocumentType,
       String TrxHeader_ID, String TrxLine_ID) {
@@ -49,14 +49,40 @@
    * 
    * It internally creates a Set from the invoiceTaxCashVAT_V attribute and 
returns a List
    */
+  public List<String> getInvoiceTaxCashVAT_V_IDs() {
+    final Set<String> invoiceTaxCashVAT_V_Set = new 
HashSet<String>(invoiceTaxCashVAT_V);
+    return new ArrayList<String>(invoiceTaxCashVAT_V_Set);
+  }
+
+  /**
+   * Returns a list of different InvoiceTaxCashVAT_V records.
+   * 
+   * It internally creates a Set from the invoiceTaxCashVAT_V attribute and 
returns a List
+   * 
+   * @deprecated Use {@link #getInvoiceTaxCashVAT_V_IDs()}
+   */
   public List<InvoiceTaxCashVAT_V> getInvoiceTaxCashVAT_V() {
+    List<InvoiceTaxCashVAT_V> itcvList = new ArrayList<InvoiceTaxCashVAT_V>();
+    for (String itcv : invoiceTaxCashVAT_V) {
+      itcvList.add(OBDal.getInstance().get(InvoiceTaxCashVAT_V.class, itcv));
+    }
     final Set<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V_Set = new 
HashSet<InvoiceTaxCashVAT_V>(
-        invoiceTaxCashVAT_V);
+        itcvList);
     return new ArrayList<InvoiceTaxCashVAT_V>(invoiceTaxCashVAT_V_Set);
   }
 
+  public void setInvoiceTaxCashVAT_V_IDs(List<String> invoiceTaxCashVAT_V) {
+    this.invoiceTaxCashVAT_V = invoiceTaxCashVAT_V;
+  }
+
+  /**
+   * 
+   * @deprecated Use {@link #setInvoiceTaxCashVAT_V_IDs()}
+   */
   public void setInvoiceTaxCashVAT_V(List<InvoiceTaxCashVAT_V> 
invoiceTaxCashVAT_V) {
-    this.invoiceTaxCashVAT_V = invoiceTaxCashVAT_V;
+    for (InvoiceTaxCashVAT_V itcv : invoiceTaxCashVAT_V) {
+      this.invoiceTaxCashVAT_V.add(itcv.getId());
+    }
   }
 
   /**
@@ -66,21 +92,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 distinct " + 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();
diff -r 6bef7cf32538 -r 7ebe0a53a425 
src/org/openbravo/erpCommon/utility/CashVATUtil.java
--- a/src/org/openbravo/erpCommon/utility/CashVATUtil.java      Fri Jul 29 
11:18:31 2016 +0200
+++ b/src/org/openbravo/erpCommon/utility/CashVATUtil.java      Mon Aug 01 
13:21:44 2016 +0200
@@ -490,9 +490,10 @@
       String Fact_Acct_Group_ID, 
DocLineCashVATReady_PaymentTransactionReconciliation line,
       Invoice invoice, final String documentType, final String SeqNo) {
     try {
-      if (invoice.isCashVAT() && !line.getInvoiceTaxCashVAT_V().isEmpty()) {
+      if (invoice.isCashVAT() && !line.getInvoiceTaxCashVAT_V_IDs().isEmpty()) 
{
         FactLine factLine2 = null;
-        for (final InvoiceTaxCashVAT_V itcv : line.getInvoiceTaxCashVAT_V()) {
+        for (final String itcvId : line.getInvoiceTaxCashVAT_V_IDs()) {
+          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())) {

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to