From f010b104461c47fbeadd6a31b92908a92097f248 Mon Sep 17 00:00:00 2001 From: hengsin Date: Mon, 3 Aug 2020 18:04:53 +0800 Subject: [PATCH] IDEMPIERE-4393 Replace Oracle outer join synax (+) with SQL standard outer join (#199) add native postgresql unit test for GenericPaymentExport remove unnecessary static and fix sql exception doesn't stop the export replace Oracle (+) with standard sql outer joint --- .../compiere/util/GenericPaymentExport.java | 17 +-- .../test/base/GenericPaymentExportTest.java | 124 ++++++++++++++++++ 2 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 org.idempiere.test/src/org/idempiere/test/base/GenericPaymentExportTest.java diff --git a/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java b/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java index 5750ab605c..3f7a43ee9c 100644 --- a/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java +++ b/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.logging.Level; +import org.adempiere.exceptions.DBException; import org.compiere.model.MCurrency; import org.compiere.model.MPaySelectionCheck; import org.compiere.model.MPaySelectionLine; @@ -184,20 +185,20 @@ public class GenericPaymentExport implements PaymentExport * @param C_BPartner_ID BPartner * @return info array */ - private static String[] getBPartnerInfo (int C_BPartner_ID) + private String[] getBPartnerInfo (int C_BPartner_ID) { String[] bp = new String[10]; String sql = "SELECT bp.Value, bp.Name, c.Name AS Contact, " + "a.Address1, a.Address2, a.City, r.Name AS Region, a.Postal, " + "cc.Name AS Country, bp.ReferenceNo " - + "FROM C_BPartner bp, AD_User c, C_BPartner_Location l, C_Location a, C_Region r, C_Country cc " + + "FROM C_BPartner bp " + + "LEFT OUTER JOIN AD_User c ON (bp.C_BPartner_ID=c.C_BPartner_ID) " + + "INNER JOIN C_BPartner_Location l ON (bp.C_BPartner_ID=l.C_BPartner_ID) " + + "INNER JOIN C_Location a ON (l.C_Location_ID=a.C_Location_ID) " + + "LEFT OUTER JOIN C_Region r ON (a.C_Region_ID=r.C_Region_ID) " + + "INNER JOIN C_Country cc ON (a.C_Country_ID=cc.C_Country_ID) " + "WHERE bp.C_BPartner_ID=?" // #1 - + " AND bp.C_BPartner_ID=c.C_BPartner_ID(+)" - + " AND bp.C_BPartner_ID=l.C_BPartner_ID" - + " AND l.C_Location_ID=a.C_Location_ID" - + " AND a.C_Region_ID=r.C_Region_ID(+)" - + " AND a.C_Country_ID=cc.C_Country_ID " + "ORDER BY l.IsBillTo DESC"; PreparedStatement pstmt = null; ResultSet rs = null; @@ -243,7 +244,7 @@ public class GenericPaymentExport implements PaymentExport } catch (SQLException e) { - s_log.log(Level.SEVERE, sql, e); + throw new DBException(e); } finally { diff --git a/org.idempiere.test/src/org/idempiere/test/base/GenericPaymentExportTest.java b/org.idempiere.test/src/org/idempiere/test/base/GenericPaymentExportTest.java new file mode 100644 index 0000000000..1d335d51fb --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/base/GenericPaymentExportTest.java @@ -0,0 +1,124 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.base; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; + +import org.compiere.model.MBPartner; +import org.compiere.model.MInvoice; +import org.compiere.model.MInvoiceLine; +import org.compiere.model.MPaySelection; +import org.compiere.model.MPaySelectionCheck; +import org.compiere.model.MPaySelectionLine; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfo; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.GenericPaymentExport; +import org.compiere.util.Ini; +import org.compiere.util.TimeUtil; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.junit.jupiter.api.Test; + +/** + * + * @author hengsin + * + */ +public class GenericPaymentExportTest extends AbstractTestCase { + + public GenericPaymentExportTest() { + } + + @Test + public void testGenericPaymentExport() { + if (DB.isPostgreSQL()) + Ini.setProperty("PostgreSQLNative", "Y"); + + int seedFarm=120; + int moneyBankCheckAccount=100; + int commissionCharge=101; + + MInvoice invoice = new MInvoice(Env.getCtx(), 0, getTrxName()); + invoice.setIsSOTrx(false); + invoice.setC_DocTypeTarget_ID(); + invoice.setC_DocType_ID(invoice.getC_DocTypeTarget_ID()); + invoice.setBPartner(new MBPartner(Env.getCtx(), seedFarm, getTrxName())); + invoice.setDateInvoiced(TimeUtil.getDay(System.currentTimeMillis())); + invoice.setGrandTotal(new BigDecimal("10.00")); + invoice.setDocStatus(DocAction.STATUS_Drafted); + invoice.setDocAction(DocAction.ACTION_Complete); + invoice.saveEx(); + MInvoiceLine il = new MInvoiceLine(invoice); + il.setLine(10); + il.setC_Charge_ID(commissionCharge); + il.setPrice(new BigDecimal("10.00")); + il.saveEx(); + + ProcessInfo pi = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete); + assertFalse(pi.isError()); + + String paymentRule = MPaySelectionLine.PAYMENTRULE_Check; + MPaySelection ps = new MPaySelection(Env.getCtx(), 0, getTrxName()); + ps.setAD_Org_ID(getAD_Org_ID()); + ps.setC_BankAccount_ID(moneyBankCheckAccount); + ps.setPayDate(TimeUtil.getDay(System.currentTimeMillis())); + ps.setName("Test@" + System.currentTimeMillis()); + ps.setTotalAmt(new BigDecimal("10.00")); + ps.saveEx(); + + MPaySelectionLine psl = new MPaySelectionLine(ps, 10, paymentRule); + psl.setIsSOTrx(false); + psl.setPayAmt(ps.getTotalAmt()); + psl.setDifferenceAmt(BigDecimal.ZERO); + psl.setDiscountAmt(BigDecimal.ZERO); + psl.setOpenAmt(ps.getTotalAmt()); + psl.setWriteOffAmt(BigDecimal.ZERO); + psl.setC_Invoice_ID(invoice.getC_Invoice_ID()); + psl.saveEx(); + + MPaySelectionCheck psc = new MPaySelectionCheck(psl, paymentRule); + psc.saveEx(); + + GenericPaymentExport export = new GenericPaymentExport(); + StringBuffer err = new StringBuffer(); + File file = null; + try { + file = File.createTempFile("GenericPaymentExportTest", "csv"); + } catch (IOException e) { + fail(e); + return; + } + int noOfLines = export.exportToFile(new MPaySelectionCheck[] {psc}, false, MPaySelectionCheck.PAYMENTRULE_Check, file, err); + assertEquals(2, noOfLines); + } +}