Related to issue 33531: Code review improvements
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Mon, 01 Aug 2016 13:21:44 +0200
changeset 30093 3928a857fcb8
parent 30092 5489c10e9115
child 30094 156bc152049d
Related to issue 33531: 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.
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	Tue Jul 26 14:43:28 2016 -0400
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java	Mon Aug 01 13:21:44 2016 +0200
@@ -37,7 +37,7 @@
  */
 public class DocLineCashVATReady_PaymentTransactionReconciliation extends DocLine {
 
-  List<String> invoiceTaxCashVAT_V = new ArrayList<String>();
+  private List<String> invoiceTaxCashVAT_V = new ArrayList<String>();
 
   public DocLineCashVATReady_PaymentTransactionReconciliation(String DocumentType,
       String TrxHeader_ID, String TrxLine_ID) {
@@ -49,16 +49,43 @@
    * 
    * It internally creates a Set from the invoiceTaxCashVAT_V attribute and returns a List
    */
-  public List<String> getInvoiceTaxCashVAT_V() {
+  public List<String> getInvoiceTaxCashVAT_V_IDs() {
     final Set<String> invoiceTaxCashVAT_V_Set = new HashSet<String>(invoiceTaxCashVAT_V);
     return new ArrayList<String>(invoiceTaxCashVAT_V_Set);
   }
 
-  public void setInvoiceTaxCashVAT_V(List<String> invoiceTaxCashVAT_V) {
+  /**
+   * 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>(
+        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) {
+    for (InvoiceTaxCashVAT_V itcv : invoiceTaxCashVAT_V) {
+      this.invoiceTaxCashVAT_V.add(itcv.getId());
+    }
+  }
+
+  /**
    * Given the payment detail id (finPaymentDetailID), the method calculates the linked
    * InvoiceTaxCashVAT_V records and adds them to the invoiceTaxCashVAT_V list associated to the
    * object. If this method is called several times for different finPaymentDetailID, the system
@@ -71,7 +98,7 @@
       try {
         OBContext.setAdminMode(true);
         final StringBuffer hql = new StringBuffer();
-        hql.append(" select " + InvoiceTaxCashVAT_V.PROPERTY_ID);
+        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 ");
--- a/src/org/openbravo/erpCommon/utility/CashVATUtil.java	Tue Jul 26 14:43:28 2016 -0400
+++ b/src/org/openbravo/erpCommon/utility/CashVATUtil.java	Mon Aug 01 13:21:44 2016 +0200
@@ -490,9 +490,9 @@
       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 String itcvId : 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();