From d69c6ebded8315ec45aaf0fe9ffeaabdfb076ee3 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 25 Mar 2011 22:56:11 -0500 Subject: [PATCH] Fix bug reported on [1913092] - Add the Payment Rule to Commissioning https://sourceforge.net/tracker/index.php?func=detail&aid=1913092&group_id=176962&atid=879335 Bug reported here: https://sourceforge.net/projects/adempiere/forums/forum/610547/topic/3966649 --- .../360lts-release/oracle/762_Fix1913092.sql | 5 ++++ .../postgresql/762_Fix1913092.sql | 5 ++++ .../org/compiere/process/CommissionCalc.java | 28 ++++++++----------- 3 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 migration/360lts-release/oracle/762_Fix1913092.sql create mode 100644 migration/360lts-release/postgresql/762_Fix1913092.sql diff --git a/migration/360lts-release/oracle/762_Fix1913092.sql b/migration/360lts-release/oracle/762_Fix1913092.sql new file mode 100644 index 0000000000..2be3e51643 --- /dev/null +++ b/migration/360lts-release/oracle/762_Fix1913092.sql @@ -0,0 +1,5 @@ +-- Dec 11, 2010 10:19:59 AM COT +-- Fix bug on [1913092] - Add the Payment Rule to Commissioning +UPDATE AD_Column SET AD_Reference_ID=17,Updated=TO_DATE('2010-12-11 10:19:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=54679 +; + diff --git a/migration/360lts-release/postgresql/762_Fix1913092.sql b/migration/360lts-release/postgresql/762_Fix1913092.sql new file mode 100644 index 0000000000..717e95783b --- /dev/null +++ b/migration/360lts-release/postgresql/762_Fix1913092.sql @@ -0,0 +1,5 @@ +-- Dec 11, 2010 10:19:59 AM COT +-- Fix bug on [1913092] - Add the Payment Rule to Commissioning +UPDATE AD_Column SET AD_Reference_ID=17,Updated=TO_TIMESTAMP('2010-12-11 10:19:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=54679 +; + diff --git a/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java b/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java index 2c05ef1d10..d879e8eef4 100644 --- a/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java +++ b/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java @@ -197,7 +197,7 @@ public class CommissionCalc extends SvrProcess // CommissionOrders/Invoices if (lines[i].isCommissionOrders()) { - MUser[] users = MUser.getOfBPartner(getCtx(), m_com.getC_BPartner_ID()); + MUser[] users = MUser.getOfBPartner(getCtx(), m_com.getC_BPartner_ID(), get_TrxName()); if (users == null || users.length == 0) throw new AdempiereUserError ("Commission Business Partner has no Users/Contact"); if (users.length == 1) @@ -236,8 +236,7 @@ public class CommissionCalc extends SvrProcess + "(SELECT M_Product_ID FROM M_Product WHERE M_Product_Category_ID=").append(lines[i].getM_Product_Category_ID()).append(")"); // Payment Rule if (lines[i].getPaymentRule() != null) - sql.append(" AND h.PaymentRule IN " - + "(SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=195 and value = '").append(lines[i].getPaymentRule()).append("')"); + sql.append(" AND h.PaymentRule='").append(lines[i].getPaymentRule()).append("'"); // Grouping if (!m_com.isListDetails()) sql.append(" GROUP BY h.C_Currency_ID"); @@ -339,17 +338,19 @@ public class CommissionCalc extends SvrProcess * Create Commission Detail * @param sql sql statement * @param comAmt parent + * @throws Exception */ - private void createDetail (String sql, MCommissionAmt comAmt) + private void createDetail (String sql, MCommissionAmt comAmt) throws Exception { PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, m_com.getAD_Client_ID()); pstmt.setTimestamp(2, p_StartDate); pstmt.setTimestamp(3, m_EndDate); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { // CommissionAmount, C_Currency_ID, Amt, Qty, @@ -372,26 +373,19 @@ public class CommissionCalc extends SvrProcess cd.setConvertedAmt(date); // - if (!cd.save()) // creates memory leak + if (!cd.save()) throw new IllegalArgumentException ("CommissionCalc - Detail Not saved"); } - rs.close(); - pstmt.close(); pstmt = null; } catch (Exception e) { - log.log(Level.SEVERE, "createDetail", e); + throw new AdempiereSystemError("System Error: " + e.getLocalizedMessage(), e); } - try + finally { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } } // createDetail