diff --git a/migration/i5.1/oracle/201809081552_IDEMPIERE-2621.sql b/migration/i5.1/oracle/201809081552_IDEMPIERE-2621.sql new file mode 100644 index 0000000000..84e388b740 --- /dev/null +++ b/migration/i5.1/oracle/201809081552_IDEMPIERE-2621.sql @@ -0,0 +1,19 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-2621 Assign default warehouse from Org on inventory docs +-- Sep 8, 2018 3:47:28 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutOrder.organization',Updated=TO_DATE('2018-09-08 15:47:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3523 +; + +-- Sep 8, 2018 3:48:02 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutOrder.organization',Updated=TO_DATE('2018-09-08 15:48:02','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3544 +; + +-- Sep 8, 2018 3:48:30 PM CEST +UPDATE AD_Column SET AD_Val_Rule_ID=130, Callout='org.compiere.model.CalloutOrder.organization',Updated=TO_DATE('2018-09-08 15:48:30','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=11469 +; + +SELECT register_migration_script('201809081552_IDEMPIERE-2621.sql') FROM dual +; + diff --git a/migration/i5.1/oracle/201809081618_IDEMPIERE-2652.sql b/migration/i5.1/oracle/201809081618_IDEMPIERE-2652.sql new file mode 100644 index 0000000000..f8cfb694d0 --- /dev/null +++ b/migration/i5.1/oracle/201809081618_IDEMPIERE-2652.sql @@ -0,0 +1,15 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-2652 default value of ad_ctxhelpmsg_trl.create and ad_ctxhelpmsg_trl.update should now() +-- Sep 8, 2018 4:14:56 PM CEST +ALTER TABLE AD_CtxHelpMsg_Trl MODIFY Created DATE DEFAULT SYSDATE +; + +-- Sep 8, 2018 4:15:28 PM CEST +ALTER TABLE AD_CtxHelpMsg_Trl MODIFY Updated DATE DEFAULT SYSDATE +; + +SELECT register_migration_script('201809081618_IDEMPIERE-2652.sql') FROM dual +; + diff --git a/migration/i5.1/postgresql/201809081552_IDEMPIERE-2621.sql b/migration/i5.1/postgresql/201809081552_IDEMPIERE-2621.sql new file mode 100644 index 0000000000..3ac8826da0 --- /dev/null +++ b/migration/i5.1/postgresql/201809081552_IDEMPIERE-2621.sql @@ -0,0 +1,16 @@ +-- IDEMPIERE-2621 Assign default warehouse from Org on inventory docs +-- Sep 8, 2018 3:47:28 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutOrder.organization',Updated=TO_TIMESTAMP('2018-09-08 15:47:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3523 +; + +-- Sep 8, 2018 3:48:02 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutOrder.organization',Updated=TO_TIMESTAMP('2018-09-08 15:48:02','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3544 +; + +-- Sep 8, 2018 3:48:30 PM CEST +UPDATE AD_Column SET AD_Val_Rule_ID=130, Callout='org.compiere.model.CalloutOrder.organization',Updated=TO_TIMESTAMP('2018-09-08 15:48:30','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=11469 +; + +SELECT register_migration_script('201809081552_IDEMPIERE-2621.sql') FROM dual +; + diff --git a/migration/i5.1/postgresql/201809081618_IDEMPIERE-2652.sql b/migration/i5.1/postgresql/201809081618_IDEMPIERE-2652.sql new file mode 100644 index 0000000000..8d0a8cceea --- /dev/null +++ b/migration/i5.1/postgresql/201809081618_IDEMPIERE-2652.sql @@ -0,0 +1,12 @@ +-- IDEMPIERE-2652 default value of ad_ctxhelpmsg_trl.create and ad_ctxhelpmsg_trl.update should now() +-- Sep 8, 2018 4:14:56 PM CEST +INSERT INTO t_alter_column values('ad_ctxhelpmsg_trl','Created','TIMESTAMP',null,'statement_timestamp()') +; + +-- Sep 8, 2018 4:15:28 PM CEST +INSERT INTO t_alter_column values('ad_ctxhelpmsg_trl','Updated','TIMESTAMP',null,'statement_timestamp()') +; + +SELECT register_migration_script('201809081618_IDEMPIERE-2652.sql') FROM dual +; + diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java index 63a68e61fc..704a2eb6ab 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java @@ -1356,6 +1356,7 @@ public class CalloutOrder extends CalloutEngine return ""; } // SalesOrderTenderType + /* Called from AD_Org_ID in tables C_Order, M_InOut, M_Inventory, M_Requisition */ public String organization(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value){ //Return if Organization field is empty diff --git a/org.adempiere.base/src/org/compiere/model/MInOut.java b/org.adempiere.base/src/org/compiere/model/MInOut.java index d02e7ea254..3b6d4460f6 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOut.java +++ b/org.adempiere.base/src/org/compiere/model/MInOut.java @@ -18,7 +18,9 @@ package org.compiere.model; import java.io.File; import java.math.BigDecimal; +import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -26,6 +28,7 @@ import java.util.Properties; import java.util.logging.Level; import org.adempiere.exceptions.AdempiereException; +import org.adempiere.exceptions.DBException; import org.adempiere.exceptions.NegativeInventoryDisallowedException; import org.adempiere.exceptions.PeriodClosedException; import org.compiere.print.MPrintFormat; @@ -2240,6 +2243,34 @@ public class MInOut extends X_M_InOut implements DocAction asset.setDescription(asset.getDescription() + " (" + reversal.getDocumentNo() + " #" + rLine.getLine() + "<-)"); asset.saveEx(); } + // Un-Link inoutline to Invoiceline + String sql = "SELECT C_InvoiceLine_ID FROM C_InvoiceLine WHERE M_InOutLine_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement(sql, get_TrxName()); + pstmt.setInt(1, sLines[i].getM_InOutLine_ID()); + rs = pstmt.executeQuery(); + while (rs.next()) + { + int invoiceLineId = rs.getInt(1); + if (invoiceLineId > 0 ){ + MInvoiceLine iLine = new MInvoiceLine(getCtx(),invoiceLineId , get_TrxName()); + iLine.setM_InOutLine_ID(0); + iLine.saveEx(); + } + } + } + catch (SQLException e) + { + throw new DBException(e, sql); + } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } } reversal.setC_Order_ID(getC_Order_ID()); // Set M_RMA_ID diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index aa53bdc5a5..65aab2a5cb 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -2420,12 +2420,19 @@ public class MInvoice extends X_C_Invoice implements DocAction if (mPO[i].getM_InOutLine_ID() == 0) { - if (!mPO[i].reverse(reversalDate)) + if(mPO[i].isPosted()) { - m_processMsg = "Could not Reverse MatchPO"; - return null; + if (!mPO[i].reverse(reversalDate)) + { + m_processMsg = "Could not Reverse MatchPO"; + return null; + } + addDocsPostProcess(new MMatchPO(Env.getCtx(), mPO[i].getReversal_ID(), get_TrxName())); + } + else + { + mPO[i].deleteEx(true); } - addDocsPostProcess(new MMatchPO(Env.getCtx(), mPO[i].getReversal_ID(), get_TrxName())); } else { diff --git a/org.adempiere.base/src/org/compiere/model/MMatchPO.java b/org.adempiere.base/src/org/compiere/model/MMatchPO.java index 167c843f76..44308e982d 100644 --- a/org.adempiere.base/src/org/compiere/model/MMatchPO.java +++ b/org.adempiere.base/src/org/compiere/model/MMatchPO.java @@ -531,10 +531,7 @@ public class MMatchPO extends X_M_MatchPO otherMatchPO = matchPO; iLine = new MInvoiceLine(retValue.getCtx(), matchPO.getC_InvoiceLine_ID(), retValue.get_TrxName()); matchPO.setQty(matchPO.getQty().subtract(retValue.getQty())); - if (matchPO.getQty().signum() == 0 ) - matchPO.deleteEx(true); - else - matchPO.saveEx(); + matchPO.saveEx(); break; } @@ -594,6 +591,8 @@ public class MMatchPO extends X_M_MatchPO } catch (Exception e) {} } } + if (otherMatchPO.getQty().signum() == 0 ) + otherMatchPO.deleteEx(true); } } if (!retValue.save()) @@ -865,7 +864,7 @@ public class MMatchPO extends X_M_MatchPO // Bayu, Sistematika // BF [ 2240484 ] Re MatchingPO, MMatchPO doesn't contains Invoice info // If newRecord, set c_invoiceline_id while null - if (newRecord && getC_InvoiceLine_ID() == 0) + if (newRecord && getC_InvoiceLine_ID() == 0 && getReversal_ID()==0) { MMatchInv[] mpi = MMatchInv.getInOutLine(getCtx(), getM_InOutLine_ID(), get_TrxName()); for (int i = 0; i < mpi.length; i++) @@ -873,6 +872,12 @@ public class MMatchPO extends X_M_MatchPO if (mpi[i].getC_InvoiceLine_ID() != 0 && mpi[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID()) { + //verify m_matchpo not created yet + int cnt = DB.getSQLValue(get_TrxName(), "SELECT Count(*) FROM M_MatchPO WHERE M_InOutLine_ID="+getM_InOutLine_ID() + +" AND C_InvoiceLine_ID="+mpi[i].getC_InvoiceLine_ID()); + if (cnt > 0) + continue; + if (mpi[i].getQty().compareTo(getQty()) == 0) // same quantity { setC_InvoiceLine_ID(mpi[i].getC_InvoiceLine_ID()); @@ -992,7 +997,7 @@ public class MMatchPO extends X_M_MatchPO { MInOutLine line = new MInOutLine(getCtx(), getM_InOutLine_ID(), get_TrxName()); BigDecimal matchedQty = DB.getSQLValueBD(get_TrxName(), "SELECT Coalesce(SUM(Qty),0) FROM M_MatchPO WHERE M_InOutLine_ID=?" , getM_InOutLine_ID()); - if (matchedQty != null && matchedQty.compareTo(line.getMovementQty()) > 0) + if (line.getMovementQty().signum() > 0 && matchedQty != null && matchedQty.compareTo(line.getMovementQty()) > 0) { throw new IllegalStateException("Total matched qty > movement qty. MatchedQty="+matchedQty+", MovementQty="+line.getMovementQty()+", Line="+line); } @@ -1000,8 +1005,8 @@ public class MMatchPO extends X_M_MatchPO if (getC_InvoiceLine_ID() > 0) { - MInvoiceLine line = new MInvoiceLine(getCtx(), getC_InvoiceLine_ID(), get_TrxName()); - BigDecimal matchedQty = DB.getSQLValueBD(get_TrxName(), "SELECT Coalesce(SUM(Qty),0) FROM M_MatchPO WHERE C_InvoiceLine_ID=?" , getC_InvoiceLine_ID()); + MInvoiceLine line = new MInvoiceLine(getCtx(), getC_InvoiceLine_ID(), get_TrxName()); + BigDecimal matchedQty = DB.getSQLValueBD(get_TrxName(), "SELECT Coalesce(SUM(Qty),0) FROM M_MatchPO WHERE C_InvoiceLine_ID=? AND Reversal_ID IS NULL " , getC_InvoiceLine_ID() ); if (matchedQty != null && matchedQty.compareTo(line.getQtyInvoiced()) > 0) { throw new IllegalStateException("Total matched qty > invoiced qty. MatchedQty="+matchedQty+", InvoicedQty="+line.getQtyInvoiced()+", Line="+line); @@ -1039,15 +1044,21 @@ public class MMatchPO extends X_M_MatchPO { if (getM_InOutLine_ID() != 0) // new delivery orderLine.setQtyDelivered(orderLine.getQtyDelivered().add(getQty())); - else // if (getM_InOutLine_ID() == 0) // reset to 0 + else if (!newRecord) // if (getM_InOutLine_ID() == 0) // reset to 0 orderLine.setQtyDelivered(orderLine.getQtyDelivered().subtract(getQty())); orderLine.setDateDelivered(getDateTrx()); // overwrite=last } + else if (!newRecord && getM_InOutLine_ID() > 0 && is_ValueChanged(COLUMNNAME_Qty)) + { + BigDecimal oldQty = (BigDecimal)(get_ValueOld(COLUMNNAME_Qty)); + orderLine.setQtyDelivered(orderLine.getQtyDelivered().subtract(oldQty.subtract(getQty()))); + } + if (m_isInvoiceLineChange && (newRecord || getC_InvoiceLine_ID() != get_ValueOldAsInt("C_InvoiceLine_ID"))) { if (getC_InvoiceLine_ID() != 0) // first time orderLine.setQtyInvoiced(orderLine.getQtyInvoiced().add(getQty())); - else // if (getC_InvoiceLine_ID() == 0) // set to 0 + else if (!newRecord) // if (getC_InvoiceLine_ID() == 0) // set to 0 orderLine.setQtyInvoiced(orderLine.getQtyInvoiced().subtract(getQty())); orderLine.setDateInvoiced(getDateTrx()); // overwrite=last } @@ -1253,8 +1264,14 @@ public class MMatchPO extends X_M_MatchPO { MMatchPO reversal = new MMatchPO (getCtx(), 0, get_TrxName()); reversal.setC_InvoiceLine_ID(getC_InvoiceLine_ID()); - reversal.setM_InOutLine_ID(getM_InOutLine_ID()); - PO.copyValues(this, reversal); + reversal.setM_InOutLine_ID(getM_InOutLine_ID()); + if (getC_OrderLine_ID() != 0) + reversal.setC_OrderLine_ID(getC_OrderLine_ID()); + else{ + reversal.setC_OrderLine_ID(getM_InOutLine().getC_OrderLine_ID()); + } + reversal.setM_Product_ID(getM_Product_ID()); + reversal.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID()); reversal.setAD_Org_ID(this.getAD_Org_ID()); reversal.setDescription("(->" + this.getDocumentNo() + ")"); reversal.setQty(this.getQty().negate()); @@ -1262,14 +1279,16 @@ public class MMatchPO extends X_M_MatchPO reversal.setDateTrx(reversalDate); reversal.set_ValueNoCheck ("DocumentNo", null); reversal.setPosted (false); - reversal.setReversal_ID(getM_MatchPO_ID()); + reversal.setProcessed(true); + reversal.setReversal_ID(getM_MatchPO_ID()); reversal.saveEx(); + this.setDescription("(" + reversal.getDocumentNo() + "<-)"); this.setReversal_ID(reversal.getM_MatchPO_ID()); this.saveEx(); - - // reversal of mr if have both shipment and invoice line - if ( reversal.getM_InOutLine_ID() > 0 && reversal.getC_InvoiceLine_ID() > 0) + + // auto create new matchpo if have invoice line + if ( reversal.getC_InvoiceLine_ID() > 0) { MMatchPO[] matchPOs = MMatchPO.getOrderLine(reversal.getCtx(), reversal.getC_OrderLine_ID(), reversal.get_TrxName()); BigDecimal matchQty = getQty(); @@ -1288,12 +1307,19 @@ public class MMatchPO extends X_M_MatchPO if (matchQty.signum() != 0) { - MMatchPO matchPO = new MMatchPO (getCtx(), 0, get_TrxName()); - PO.copyValues(this, matchPO); + MMatchPO matchPO = new MMatchPO (getCtx(), 0, get_TrxName()); + matchPO.setC_OrderLine_ID(getC_OrderLine_ID()); matchPO.setC_InvoiceLine_ID(getC_InvoiceLine_ID()); - matchPO.setM_InOutLine_ID(0); + matchPO.setM_InOutLine_ID(0); + matchPO.setAD_Org_ID(getAD_Org_ID()); + matchPO.setQty(getQty()); + matchPO.setDateAcct(getDateAcct()); + matchPO.setDateTrx(getDateTrx()); + matchPO.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID()); + matchPO.setM_Product_ID(getM_Product_ID()); matchPO.setDescription(null); - matchPO.setPosted (false); + matchPO.setProcessed(true); + matchPO.setPosted (false); matchPO.saveEx(); } } diff --git a/org.adempiere.base/src/org/compiere/model/MPeriod.java b/org.adempiere.base/src/org/compiere/model/MPeriod.java index b518226da9..943ed0135c 100644 --- a/org.adempiere.base/src/org/compiere/model/MPeriod.java +++ b/org.adempiere.base/src/org/compiere/model/MPeriod.java @@ -88,7 +88,7 @@ public class MPeriod extends X_C_Period */ public static MPeriod get (Properties ctx, Timestamp DateAcct) { - return get(ctx, DateAcct, 0); + return get(ctx, DateAcct, 0, null); } // get /** @@ -200,7 +200,7 @@ public class MPeriod extends X_C_Period */ public static int getC_Period_ID (Properties ctx, Timestamp DateAcct) { - MPeriod period = get (ctx, DateAcct); + MPeriod period = get (ctx, DateAcct, 0, null); if (period == null) return 0; return period.getC_Period_ID(); @@ -215,7 +215,7 @@ public class MPeriod extends X_C_Period */ public static int getC_Period_ID (Properties ctx, Timestamp DateAcct, int AD_Org_ID) { - MPeriod period = get (ctx, DateAcct, AD_Org_ID); + MPeriod period = get (ctx, DateAcct, AD_Org_ID, null); if (period == null) return 0; return period.getC_Period_ID(); @@ -254,7 +254,7 @@ public class MPeriod extends X_C_Period s_log.warning("No DocBaseType"); return false; } - MPeriod period = MPeriod.get (ctx, DateAcct, AD_Org_ID); + MPeriod period = MPeriod.get (ctx, DateAcct, AD_Org_ID, null); if (period == null) { s_log.warning("No Period for " + DateAcct + " (" + DocBaseType + ")"); @@ -398,7 +398,7 @@ public class MPeriod extends X_C_Period public static MPeriod getFirstInYear (Properties ctx, Timestamp DateAcct, int AD_Org_ID) { MPeriod retValue = null; - int C_Calendar_ID = MPeriod.get(ctx, DateAcct, AD_Org_ID).getC_Calendar_ID(); + int C_Calendar_ID = MPeriod.get(ctx, DateAcct, AD_Org_ID, null).getC_Calendar_ID(); String sql = "SELECT * " + "FROM C_Period " @@ -780,7 +780,7 @@ public class MPeriod extends X_C_Period public static void testPeriodOpen(Properties ctx, Timestamp dateAcct, String docBaseType) throws PeriodClosedException { - if (!MPeriod.isOpen(ctx, dateAcct, docBaseType)) { + if (!MPeriod.isOpen(ctx, dateAcct, docBaseType, 0)) { throw new PeriodClosedException(dateAcct, docBaseType); } } @@ -815,7 +815,7 @@ public class MPeriod extends X_C_Period throws PeriodClosedException { MDocType dt = MDocType.get(ctx, C_DocType_ID); - testPeriodOpen(ctx, dateAcct, dt.getDocBaseType()); + testPeriodOpen(ctx, dateAcct, dt.getDocBaseType(), 0); } /** @@ -842,9 +842,9 @@ public class MPeriod extends X_C_Period { if (m_C_Calendar_ID == 0) { - MYear year = (MYear) getC_Year(); - if (year != null) - m_C_Calendar_ID = year.getC_Calendar_ID(); + int calId = DB.getSQLValueEx(null, "SELECT C_Calendar_ID FROM C_Year WHERE C_Year_ID=?", getC_Year_ID()); + if (calId >= 0) + m_C_Calendar_ID = calId; else log.severe("@NotFound@ C_Year_ID=" + getC_Year_ID()); } diff --git a/org.adempiere.base/src/org/compiere/util/Trx.java b/org.adempiere.base/src/org/compiere/util/Trx.java index 22c74b982d..9dbfd1cf5c 100644 --- a/org.adempiere.base/src/org/compiere/util/Trx.java +++ b/org.adempiere.base/src/org/compiere/util/Trx.java @@ -624,7 +624,6 @@ public class Trx } catch (SQLException e2) {;} } - trx = null; // Throw exception if (e instanceof RuntimeException) { diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLMandatoryElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLMandatoryElementHandler.java index 8de3d8e3f5..02cde5be95 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLMandatoryElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLMandatoryElementHandler.java @@ -56,16 +56,17 @@ public class SQLMandatoryElementHandler extends AbstractElementHandler { if (sql.endsWith(";") && !(sql.toLowerCase().endsWith("end;"))) sql = sql.substring(0, sql.length() - 1); sql = Env.parseContext(Env.getCtx(), 0, sql, false); + int count = 0; PreparedStatement pstmt = null; X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, "", 0); try { pstmt = DB.prepareStatement(sql, getTrxName(ctx)); if (DBType.equals("ALL")) { - int n = pstmt.executeUpdate(); - if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory: "+ getStringValue(element, "statement") + " ReturnValue="+n); + count = pstmt.executeUpdate(); + if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory: "+ getStringValue(element, "statement") + " ReturnValue="+count); } else if (DB.isOracle() && DBType.equals("Oracle")) { - int n = pstmt.executeUpdate(); - if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+n); + count = pstmt.executeUpdate(); + if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+count); } else if (DB.isPostgreSQL() && ( DBType.equals("Postgres") || DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand @@ -79,18 +80,18 @@ public class SQLMandatoryElementHandler extends AbstractElementHandler { Statement stmt = null; try { stmt = pstmt.getConnection().createStatement(); - int n = stmt.executeUpdate (sql); - if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n); + count = stmt.executeUpdate (sql); + if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+count); } finally { DB.close(stmt); stmt = null; } } - logImportDetail (ctx, impDetail, 1, "SQLMandatory",1,"Execute"); + logImportDetail (ctx, impDetail, 1, "SQLMandatory",count,"Execute"); ctx.packIn.getNotifier().addSuccessLine("-> " + sql); } catch (Exception e) { ctx.packIn.getNotifier().addFailureLine("SQL Mandatory failed, error (" + e.getLocalizedMessage() + "):"); - logImportDetail (ctx, impDetail, 0, "SQLMandatory",1,"Execute"); + logImportDetail (ctx, impDetail, 0, "SQLMandatory",-1,"Execute"); ctx.packIn.getNotifier().addFailureLine("-> " + sql); log.log(Level.SEVERE,"SQLMandatory", e); throw new AdempiereException(e); diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java index fab99602f2..89372ff93a 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java @@ -49,6 +49,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler { sql = sql.substring(0, sql.length() - 1); sql=Env.parseContext(Env.getCtx(), 0, sql, false); // tbayen IDEMPIERE-2140 Savepoint savepoint = null; + int count = 0; PreparedStatement pstmt = null; X_AD_Package_Imp_Detail impDetail = null; impDetail = createImportDetail(ctx, element.qName, "", 0); @@ -61,11 +62,11 @@ public class SQLStatementElementHandler extends AbstractElementHandler { pstmt = DB.prepareStatement(sql, getTrxName(ctx)); if (DBType.equals("ALL")) { - int n = pstmt.executeUpdate(); - if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+n); + count = pstmt.executeUpdate(); + if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+count); } else if (DB.isOracle() == true && DBType.equals("Oracle")) { - int n = pstmt.executeUpdate(); - if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+n); + count = pstmt.executeUpdate(); + if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+count); } else if (DB.isPostgreSQL() && ( DBType.equals("Postgres") || DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand @@ -80,14 +81,14 @@ public class SQLStatementElementHandler extends AbstractElementHandler { Statement stmt = null; try { stmt = pstmt.getConnection().createStatement(); - int n = stmt.executeUpdate (sql); - if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n); + count = stmt.executeUpdate (sql); + if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+count); } finally { DB.close(stmt); stmt = null; } } - logImportDetail (ctx, impDetail, 1, "SQLStatement",1,"Execute"); + logImportDetail (ctx, impDetail, 1, "SQLStatement",count,"Execute"); ctx.packIn.getNotifier().addSuccessLine("-> " + sql); } catch (Exception e) { // rollback immediately on exception to avoid a wrong SQL stop the whole process @@ -105,7 +106,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler { savepoint = null; } ctx.packIn.getNotifier().addFailureLine("SQL statement failed but ignored, error (" + e.getLocalizedMessage() + "): "); - logImportDetail (ctx, impDetail, 0, "SQLStatement",1,"Execute"); + logImportDetail (ctx, impDetail, 0, "SQLStatement",-1,"Execute"); ctx.packIn.getNotifier().addFailureLine("-> " + sql); log.log(Level.SEVERE,"SQLStatement", e); } finally {