hg merge release-5.1 (merge release5.1 into default)

This commit is contained in:
Carlos Ruiz 2018-09-27 20:48:58 +02:00
commit 53583c1a1d
12 changed files with 179 additions and 51 deletions

View File

@ -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
;

View File

@ -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
;

View File

@ -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
;

View File

@ -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
;

View File

@ -1356,6 +1356,7 @@ public class CalloutOrder extends CalloutEngine
return ""; return "";
} // SalesOrderTenderType } // 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){ public String organization(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value){
//Return if Organization field is empty //Return if Organization field is empty

View File

@ -18,7 +18,9 @@ package org.compiere.model;
import java.io.File; import java.io.File;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -26,6 +28,7 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DBException;
import org.adempiere.exceptions.NegativeInventoryDisallowedException; import org.adempiere.exceptions.NegativeInventoryDisallowedException;
import org.adempiere.exceptions.PeriodClosedException; import org.adempiere.exceptions.PeriodClosedException;
import org.compiere.print.MPrintFormat; 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.setDescription(asset.getDescription() + " (" + reversal.getDocumentNo() + " #" + rLine.getLine() + "<-)");
asset.saveEx(); 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()); reversal.setC_Order_ID(getC_Order_ID());
// Set M_RMA_ID // Set M_RMA_ID

View File

@ -2420,12 +2420,19 @@ public class MInvoice extends X_C_Invoice implements DocAction
if (mPO[i].getM_InOutLine_ID() == 0) if (mPO[i].getM_InOutLine_ID() == 0)
{ {
if (!mPO[i].reverse(reversalDate)) if(mPO[i].isPosted())
{ {
m_processMsg = "Could not Reverse MatchPO"; if (!mPO[i].reverse(reversalDate))
return null; {
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 else
{ {

View File

@ -531,10 +531,7 @@ public class MMatchPO extends X_M_MatchPO
otherMatchPO = matchPO; otherMatchPO = matchPO;
iLine = new MInvoiceLine(retValue.getCtx(), matchPO.getC_InvoiceLine_ID(), retValue.get_TrxName()); iLine = new MInvoiceLine(retValue.getCtx(), matchPO.getC_InvoiceLine_ID(), retValue.get_TrxName());
matchPO.setQty(matchPO.getQty().subtract(retValue.getQty())); matchPO.setQty(matchPO.getQty().subtract(retValue.getQty()));
if (matchPO.getQty().signum() == 0 ) matchPO.saveEx();
matchPO.deleteEx(true);
else
matchPO.saveEx();
break; break;
} }
@ -594,6 +591,8 @@ public class MMatchPO extends X_M_MatchPO
} catch (Exception e) {} } catch (Exception e) {}
} }
} }
if (otherMatchPO.getQty().signum() == 0 )
otherMatchPO.deleteEx(true);
} }
} }
if (!retValue.save()) if (!retValue.save())
@ -865,7 +864,7 @@ public class MMatchPO extends X_M_MatchPO
// Bayu, Sistematika // Bayu, Sistematika
// BF [ 2240484 ] Re MatchingPO, MMatchPO doesn't contains Invoice info // BF [ 2240484 ] Re MatchingPO, MMatchPO doesn't contains Invoice info
// If newRecord, set c_invoiceline_id while null // 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()); MMatchInv[] mpi = MMatchInv.getInOutLine(getCtx(), getM_InOutLine_ID(), get_TrxName());
for (int i = 0; i < mpi.length; i++) 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 && if (mpi[i].getC_InvoiceLine_ID() != 0 &&
mpi[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID()) 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 if (mpi[i].getQty().compareTo(getQty()) == 0) // same quantity
{ {
setC_InvoiceLine_ID(mpi[i].getC_InvoiceLine_ID()); 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()); 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()); 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); 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) if (getC_InvoiceLine_ID() > 0)
{ {
MInvoiceLine line = new MInvoiceLine(getCtx(), getC_InvoiceLine_ID(), get_TrxName()); 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()); 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) if (matchedQty != null && matchedQty.compareTo(line.getQtyInvoiced()) > 0)
{ {
throw new IllegalStateException("Total matched qty > invoiced qty. MatchedQty="+matchedQty+", InvoicedQty="+line.getQtyInvoiced()+", Line="+line); 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 if (getM_InOutLine_ID() != 0) // new delivery
orderLine.setQtyDelivered(orderLine.getQtyDelivered().add(getQty())); 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.setQtyDelivered(orderLine.getQtyDelivered().subtract(getQty()));
orderLine.setDateDelivered(getDateTrx()); // overwrite=last 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 (m_isInvoiceLineChange && (newRecord || getC_InvoiceLine_ID() != get_ValueOldAsInt("C_InvoiceLine_ID")))
{ {
if (getC_InvoiceLine_ID() != 0) // first time if (getC_InvoiceLine_ID() != 0) // first time
orderLine.setQtyInvoiced(orderLine.getQtyInvoiced().add(getQty())); 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.setQtyInvoiced(orderLine.getQtyInvoiced().subtract(getQty()));
orderLine.setDateInvoiced(getDateTrx()); // overwrite=last orderLine.setDateInvoiced(getDateTrx()); // overwrite=last
} }
@ -1253,8 +1264,14 @@ public class MMatchPO extends X_M_MatchPO
{ {
MMatchPO reversal = new MMatchPO (getCtx(), 0, get_TrxName()); MMatchPO reversal = new MMatchPO (getCtx(), 0, get_TrxName());
reversal.setC_InvoiceLine_ID(getC_InvoiceLine_ID()); reversal.setC_InvoiceLine_ID(getC_InvoiceLine_ID());
reversal.setM_InOutLine_ID(getM_InOutLine_ID()); reversal.setM_InOutLine_ID(getM_InOutLine_ID());
PO.copyValues(this, reversal); 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.setAD_Org_ID(this.getAD_Org_ID());
reversal.setDescription("(->" + this.getDocumentNo() + ")"); reversal.setDescription("(->" + this.getDocumentNo() + ")");
reversal.setQty(this.getQty().negate()); reversal.setQty(this.getQty().negate());
@ -1262,14 +1279,16 @@ public class MMatchPO extends X_M_MatchPO
reversal.setDateTrx(reversalDate); reversal.setDateTrx(reversalDate);
reversal.set_ValueNoCheck ("DocumentNo", null); reversal.set_ValueNoCheck ("DocumentNo", null);
reversal.setPosted (false); reversal.setPosted (false);
reversal.setReversal_ID(getM_MatchPO_ID()); reversal.setProcessed(true);
reversal.setReversal_ID(getM_MatchPO_ID());
reversal.saveEx(); reversal.saveEx();
this.setDescription("(" + reversal.getDocumentNo() + "<-)"); this.setDescription("(" + reversal.getDocumentNo() + "<-)");
this.setReversal_ID(reversal.getM_MatchPO_ID()); this.setReversal_ID(reversal.getM_MatchPO_ID());
this.saveEx(); this.saveEx();
// reversal of mr if have both shipment and invoice line // auto create new matchpo if have invoice line
if ( reversal.getM_InOutLine_ID() > 0 && reversal.getC_InvoiceLine_ID() > 0) if ( reversal.getC_InvoiceLine_ID() > 0)
{ {
MMatchPO[] matchPOs = MMatchPO.getOrderLine(reversal.getCtx(), reversal.getC_OrderLine_ID(), reversal.get_TrxName()); MMatchPO[] matchPOs = MMatchPO.getOrderLine(reversal.getCtx(), reversal.getC_OrderLine_ID(), reversal.get_TrxName());
BigDecimal matchQty = getQty(); BigDecimal matchQty = getQty();
@ -1288,12 +1307,19 @@ public class MMatchPO extends X_M_MatchPO
if (matchQty.signum() != 0) if (matchQty.signum() != 0)
{ {
MMatchPO matchPO = new MMatchPO (getCtx(), 0, get_TrxName()); MMatchPO matchPO = new MMatchPO (getCtx(), 0, get_TrxName());
PO.copyValues(this, matchPO); matchPO.setC_OrderLine_ID(getC_OrderLine_ID());
matchPO.setC_InvoiceLine_ID(getC_InvoiceLine_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.setDescription(null);
matchPO.setPosted (false); matchPO.setProcessed(true);
matchPO.setPosted (false);
matchPO.saveEx(); matchPO.saveEx();
} }
} }

View File

@ -88,7 +88,7 @@ public class MPeriod extends X_C_Period
*/ */
public static MPeriod get (Properties ctx, Timestamp DateAcct) public static MPeriod get (Properties ctx, Timestamp DateAcct)
{ {
return get(ctx, DateAcct, 0); return get(ctx, DateAcct, 0, null);
} // get } // get
/** /**
@ -200,7 +200,7 @@ public class MPeriod extends X_C_Period
*/ */
public static int getC_Period_ID (Properties ctx, Timestamp DateAcct) 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) if (period == null)
return 0; return 0;
return period.getC_Period_ID(); 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) 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) if (period == null)
return 0; return 0;
return period.getC_Period_ID(); return period.getC_Period_ID();
@ -254,7 +254,7 @@ public class MPeriod extends X_C_Period
s_log.warning("No DocBaseType"); s_log.warning("No DocBaseType");
return false; return false;
} }
MPeriod period = MPeriod.get (ctx, DateAcct, AD_Org_ID); MPeriod period = MPeriod.get (ctx, DateAcct, AD_Org_ID, null);
if (period == null) if (period == null)
{ {
s_log.warning("No Period for " + DateAcct + " (" + DocBaseType + ")"); 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) public static MPeriod getFirstInYear (Properties ctx, Timestamp DateAcct, int AD_Org_ID)
{ {
MPeriod retValue = null; 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 * " String sql = "SELECT * "
+ "FROM C_Period " + "FROM C_Period "
@ -780,7 +780,7 @@ public class MPeriod extends X_C_Period
public static void testPeriodOpen(Properties ctx, Timestamp dateAcct, String docBaseType) public static void testPeriodOpen(Properties ctx, Timestamp dateAcct, String docBaseType)
throws PeriodClosedException throws PeriodClosedException
{ {
if (!MPeriod.isOpen(ctx, dateAcct, docBaseType)) { if (!MPeriod.isOpen(ctx, dateAcct, docBaseType, 0)) {
throw new PeriodClosedException(dateAcct, docBaseType); throw new PeriodClosedException(dateAcct, docBaseType);
} }
} }
@ -815,7 +815,7 @@ public class MPeriod extends X_C_Period
throws PeriodClosedException throws PeriodClosedException
{ {
MDocType dt = MDocType.get(ctx, C_DocType_ID); 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) if (m_C_Calendar_ID == 0)
{ {
MYear year = (MYear) getC_Year(); int calId = DB.getSQLValueEx(null, "SELECT C_Calendar_ID FROM C_Year WHERE C_Year_ID=?", getC_Year_ID());
if (year != null) if (calId >= 0)
m_C_Calendar_ID = year.getC_Calendar_ID(); m_C_Calendar_ID = calId;
else else
log.severe("@NotFound@ C_Year_ID=" + getC_Year_ID()); log.severe("@NotFound@ C_Year_ID=" + getC_Year_ID());
} }

View File

@ -624,7 +624,6 @@ public class Trx
} }
catch (SQLException e2) {;} catch (SQLException e2) {;}
} }
trx = null;
// Throw exception // Throw exception
if (e instanceof RuntimeException) if (e instanceof RuntimeException)
{ {

View File

@ -56,16 +56,17 @@ public class SQLMandatoryElementHandler extends AbstractElementHandler {
if (sql.endsWith(";") && !(sql.toLowerCase().endsWith("end;"))) if (sql.endsWith(";") && !(sql.toLowerCase().endsWith("end;")))
sql = sql.substring(0, sql.length() - 1); sql = sql.substring(0, sql.length() - 1);
sql = Env.parseContext(Env.getCtx(), 0, sql, false); sql = Env.parseContext(Env.getCtx(), 0, sql, false);
int count = 0;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, "", 0); X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, "", 0);
try { try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx)); pstmt = DB.prepareStatement(sql, getTrxName(ctx));
if (DBType.equals("ALL")) { if (DBType.equals("ALL")) {
int n = pstmt.executeUpdate(); count = pstmt.executeUpdate();
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory: "+ getStringValue(element, "statement") + " ReturnValue="+n); if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory: "+ getStringValue(element, "statement") + " ReturnValue="+count);
} else if (DB.isOracle() && DBType.equals("Oracle")) { } else if (DB.isOracle() && DBType.equals("Oracle")) {
int n = pstmt.executeUpdate(); count = pstmt.executeUpdate();
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+n); if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+count);
} else if (DB.isPostgreSQL() } else if (DB.isPostgreSQL()
&& ( DBType.equals("Postgres") && ( DBType.equals("Postgres")
|| DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand || DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand
@ -79,18 +80,18 @@ public class SQLMandatoryElementHandler extends AbstractElementHandler {
Statement stmt = null; Statement stmt = null;
try { try {
stmt = pstmt.getConnection().createStatement(); stmt = pstmt.getConnection().createStatement();
int n = stmt.executeUpdate (sql); count = stmt.executeUpdate (sql);
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n); if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+count);
} finally { } finally {
DB.close(stmt); DB.close(stmt);
stmt = null; stmt = null;
} }
} }
logImportDetail (ctx, impDetail, 1, "SQLMandatory",1,"Execute"); logImportDetail (ctx, impDetail, 1, "SQLMandatory",count,"Execute");
ctx.packIn.getNotifier().addSuccessLine("-> " + sql); ctx.packIn.getNotifier().addSuccessLine("-> " + sql);
} catch (Exception e) { } catch (Exception e) {
ctx.packIn.getNotifier().addFailureLine("SQL Mandatory failed, error (" + e.getLocalizedMessage() + "):"); 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); ctx.packIn.getNotifier().addFailureLine("-> " + sql);
log.log(Level.SEVERE,"SQLMandatory", e); log.log(Level.SEVERE,"SQLMandatory", e);
throw new AdempiereException(e); throw new AdempiereException(e);

View File

@ -49,6 +49,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
sql = sql.substring(0, sql.length() - 1); sql = sql.substring(0, sql.length() - 1);
sql=Env.parseContext(Env.getCtx(), 0, sql, false); // tbayen IDEMPIERE-2140 sql=Env.parseContext(Env.getCtx(), 0, sql, false); // tbayen IDEMPIERE-2140
Savepoint savepoint = null; Savepoint savepoint = null;
int count = 0;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
X_AD_Package_Imp_Detail impDetail = null; X_AD_Package_Imp_Detail impDetail = null;
impDetail = createImportDetail(ctx, element.qName, "", 0); impDetail = createImportDetail(ctx, element.qName, "", 0);
@ -61,11 +62,11 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
pstmt = DB.prepareStatement(sql, getTrxName(ctx)); pstmt = DB.prepareStatement(sql, getTrxName(ctx));
if (DBType.equals("ALL")) { if (DBType.equals("ALL")) {
int n = pstmt.executeUpdate(); count = pstmt.executeUpdate();
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+n); if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+count);
} else if (DB.isOracle() == true && DBType.equals("Oracle")) { } else if (DB.isOracle() == true && DBType.equals("Oracle")) {
int n = pstmt.executeUpdate(); count = pstmt.executeUpdate();
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+n); if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+count);
} else if (DB.isPostgreSQL() } else if (DB.isPostgreSQL()
&& ( DBType.equals("Postgres") && ( DBType.equals("Postgres")
|| DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand || DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand
@ -80,14 +81,14 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
Statement stmt = null; Statement stmt = null;
try { try {
stmt = pstmt.getConnection().createStatement(); stmt = pstmt.getConnection().createStatement();
int n = stmt.executeUpdate (sql); count = stmt.executeUpdate (sql);
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n); if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+count);
} finally { } finally {
DB.close(stmt); DB.close(stmt);
stmt = null; stmt = null;
} }
} }
logImportDetail (ctx, impDetail, 1, "SQLStatement",1,"Execute"); logImportDetail (ctx, impDetail, 1, "SQLStatement",count,"Execute");
ctx.packIn.getNotifier().addSuccessLine("-> " + sql); ctx.packIn.getNotifier().addSuccessLine("-> " + sql);
} catch (Exception e) { } catch (Exception e) {
// rollback immediately on exception to avoid a wrong SQL stop the whole process // rollback immediately on exception to avoid a wrong SQL stop the whole process
@ -105,7 +106,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
savepoint = null; savepoint = null;
} }
ctx.packIn.getNotifier().addFailureLine("SQL statement failed but ignored, error (" + e.getLocalizedMessage() + "): "); 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); ctx.packIn.getNotifier().addFailureLine("-> " + sql);
log.log(Level.SEVERE,"SQLStatement", e); log.log(Level.SEVERE,"SQLStatement", e);
} finally { } finally {