IDEMPIERE-5936 Slow performance creating MR/Invoice Lines using CREATE LINES FROM.. in process M_InOut/C_Invoice_CreateFromProcess (#2123)

* IDEMPIERE-5936 Slow performance creating MR/Invoice Lines using CREATE LINES FROM.. in process M_InOut/C_Invoice_CreateFromProcess

* IDEMPIERE-5936 Slow performance creating MR/Invoice Lines using CREATE LINES FROM.. in process M_InOut/C_Invoice_CreateFromProcess
This commit is contained in:
Elaine Tan 2023-11-30 11:22:35 +08:00 committed by GitHub
parent b8f1d6d2fb
commit cacb456c2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 128 deletions

View File

@ -41,6 +41,7 @@ import org.compiere.model.MOrder;
import org.compiere.model.MProcessPara; import org.compiere.model.MProcessPara;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
import org.compiere.model.MRMA; import org.compiere.model.MRMA;
import org.compiere.model.MTable;
import org.compiere.util.AdempiereUserError; import org.compiere.util.AdempiereUserError;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -92,12 +93,9 @@ public class CreateFromInOut extends SvrProcess
// Lines // Lines
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append("SELECT t.T_Selection_ID, t.ViewID, v.AD_Table_ID, v.Line, v.C_Order_ID, v.C_Invoice_ID, v.M_RMA_ID, "); sql.append("SELECT t.T_Selection_ID, CAST(t.ViewID AS Integer) AS AD_Table_ID ");
sql.append("v.Qty, v.C_UOM_ID, v.M_Locator_ID, v.M_Product_ID, v.C_OrderLine_ID, v.C_InvoiceLine_ID, v.M_RMALine_ID "); sql.append("FROM T_Selection t ");
sql.append("FROM T_Selection t, M_InOut_CreateFrom_v v "); sql.append("WHERE t.AD_PInstance_ID=? ");
sql.append("WHERE (t.ViewID || '_' || t.T_Selection_ID)=(v.AD_Table_ID || '_' || v.M_InOut_CreateFrom_v_ID) ");
sql.append("AND t.AD_PInstance_ID=? ");
sql.append("ORDER BY v.Line, v.AD_Table_ID, t.T_Selection_ID ");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -113,52 +111,9 @@ public class CreateFromInOut extends SvrProcess
selectionIDList.add(T_Selection_ID); selectionIDList.add(T_Selection_ID);
String ColumnName = "AD_Table_ID"; String ColumnName = "AD_Table_ID";
String key = ColumnName + "_" + T_Selection_ID; MTable table = MTable.get(rs.getInt(ColumnName));
selectionValueMap.put(key, rs.getInt(ColumnName)); String key = table.getKeyColumns()[0] + "_" + T_Selection_ID;
selectionValueMap.put(key, T_Selection_ID);
ColumnName = "Line";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "C_Order_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "C_Invoice_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_RMA_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "Qty";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getBigDecimal(ColumnName));
ColumnName = "C_UOM_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_Locator_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_Product_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "C_OrderLine_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "C_InvoiceLine_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_RMALine_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
} }
} }
catch (Exception e) catch (Exception e)

View File

@ -35,11 +35,13 @@ import java.util.HashMap;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MInOut;
import org.compiere.model.MInvoice; import org.compiere.model.MInvoice;
import org.compiere.model.MOrder; import org.compiere.model.MOrder;
import org.compiere.model.MProcessPara; import org.compiere.model.MProcessPara;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
import org.compiere.model.MRMA; import org.compiere.model.MRMA;
import org.compiere.model.MTable;
import org.compiere.util.AdempiereUserError; import org.compiere.util.AdempiereUserError;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -89,12 +91,9 @@ public class CreateFromInvoice extends SvrProcess
if (log.isLoggable(Level.CONFIG)) log.config(invoice.toString()); if (log.isLoggable(Level.CONFIG)) log.config(invoice.toString());
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append("SELECT t.T_Selection_ID, t.ViewID, v.AD_Table_ID, v.Line, v.C_Order_ID, v.M_InOut_ID, v.M_RMA_ID, "); sql.append("SELECT t.T_Selection_ID, CAST(t.ViewID AS Integer) AS AD_Table_ID ");
sql.append("v.Qty, v.C_UOM_ID, v.M_Product_ID, v.C_OrderLine_ID, v.M_InOutLine_ID, v.M_RMALine_ID "); sql.append("FROM T_Selection t ");
sql.append("FROM T_Selection t, C_Invoice_CreateFrom_v v "); sql.append("WHERE t.AD_PInstance_ID=? ");
sql.append("WHERE (t.ViewID || '_' || t.T_Selection_ID)=(v.AD_Table_ID || '_' || v.C_Invoice_CreateFrom_v_ID) ");
sql.append("AND t.AD_PInstance_ID=? ");
sql.append("ORDER BY v.Line, v.AD_Table_ID, t.T_Selection_ID ");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -110,48 +109,9 @@ public class CreateFromInvoice extends SvrProcess
selectionIDList.add(T_Selection_ID); selectionIDList.add(T_Selection_ID);
String ColumnName = "AD_Table_ID"; String ColumnName = "AD_Table_ID";
String key = ColumnName + "_" + T_Selection_ID; MTable table = MTable.get(rs.getInt(ColumnName));
selectionValueMap.put(key, rs.getInt(ColumnName)); String key = table.getKeyColumns()[0] + "_" + T_Selection_ID;
selectionValueMap.put(key, T_Selection_ID);
ColumnName = "Line";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "C_Order_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_InOut_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_RMA_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "Qty";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getBigDecimal(ColumnName));
ColumnName = "C_UOM_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_Product_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "C_OrderLine_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_InOutLine_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
ColumnName = "M_RMALine_ID";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName));
} }
} }
catch (Exception e) catch (Exception e)
@ -215,6 +175,7 @@ public class CreateFromInvoice extends SvrProcess
} }
MOrder m_order = null; MOrder m_order = null;
MInOut m_inout = null;
MRMA m_rma = null; MRMA m_rma = null;
for (int i = 0; i < selectionIDList.size(); i++) for (int i = 0; i < selectionIDList.size(); i++)
@ -225,29 +186,34 @@ public class CreateFromInvoice extends SvrProcess
String key = ColumnName + "_" + T_Selection_ID; String key = ColumnName + "_" + T_Selection_ID;
Object value = selectionValueMap.get(key); Object value = selectionValueMap.get(key);
int C_Order_ID = value != null ? ((Number) value).intValue() : 0; int C_Order_ID = value != null ? ((Number) value).intValue() : 0;
if (C_Order_ID != 0 && (m_order == null || m_order.getC_Order_ID() != C_Order_ID)) if (C_Order_ID > 0 && (m_order == null || m_order.getC_Order_ID() != C_Order_ID))
{ {
m_order = new MOrder(getCtx(), C_Order_ID, get_TrxName()); m_order = new MOrder(getCtx(), C_Order_ID, get_TrxName());
if (m_order != null)
{
invoice.setOrder(m_order); // overwrite header values invoice.setOrder(m_order); // overwrite header values
invoice.saveEx(); invoice.saveEx();
} }
ColumnName = "M_InOut_ID";
key = ColumnName + "_" + T_Selection_ID;
value = selectionValueMap.get(key);
int M_InOut_ID = value != null ? ((Number) value).intValue() : 0;
if (M_InOut_ID > 0 && (m_inout == null || m_inout.getM_InOut_ID() != M_InOut_ID))
{
m_inout = new MInOut(getCtx(), M_InOut_ID, get_TrxName());
invoice.setShipment(m_inout);
invoice.saveEx();
} }
ColumnName = "M_RMA_ID"; ColumnName = "M_RMA_ID";
key = ColumnName + "_" + T_Selection_ID; key = ColumnName + "_" + T_Selection_ID;
value = selectionValueMap.get(key); value = selectionValueMap.get(key);
int M_RMA_ID = value != null ? ((Number) value).intValue() : 0; int M_RMA_ID = value != null ? ((Number) value).intValue() : 0;
if (M_RMA_ID != 0 && (m_rma == null || m_rma.getM_RMA_ID() != M_RMA_ID)) if (M_RMA_ID > 0 && (m_rma == null || m_rma.getM_RMA_ID() != M_RMA_ID))
{ {
m_rma = new MRMA(getCtx(), M_RMA_ID, get_TrxName()); m_rma = new MRMA(getCtx(), M_RMA_ID, get_TrxName());
if (m_rma != null)
{
invoice.setM_RMA_ID(m_rma.getM_RMA_ID()); invoice.setM_RMA_ID(m_rma.getM_RMA_ID());
invoice.saveEx(); invoice.saveEx();
} }
}
ColumnName = "Qty"; ColumnName = "Qty";
key = ColumnName + "_" + T_Selection_ID; key = ColumnName + "_" + T_Selection_ID;

View File

@ -84,12 +84,9 @@ public class CreateFromRMA extends SvrProcess
if (log.isLoggable(Level.CONFIG)) log.config(rma.toString()); if (log.isLoggable(Level.CONFIG)) log.config(rma.toString());
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append("SELECT t.T_Selection_ID, v.Line, v.M_InOut_ID, v.M_InOutLine_ID, "); sql.append("SELECT t.T_Selection_ID ");
sql.append("v.MovementQty, v.Description "); sql.append("FROM T_Selection t ");
sql.append("FROM T_Selection t, M_RMA_CreateFrom_v v "); sql.append("WHERE t.AD_PInstance_ID=? ");
sql.append("WHERE t.T_Selection_ID=v.M_RMA_CreateFrom_v_ID ");
sql.append("AND t.AD_PInstance_ID=? ");
sql.append("ORDER BY v.Line, v.M_InOut_ID, t.T_Selection_ID ");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -106,15 +103,7 @@ public class CreateFromRMA extends SvrProcess
String ColumnName = "M_InOutLine_ID"; String ColumnName = "M_InOutLine_ID";
String key = ColumnName + "_" + T_Selection_ID; String key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getInt(ColumnName)); selectionValueMap.put(key, T_Selection_ID);
ColumnName = "MovementQty";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getBigDecimal(ColumnName));
ColumnName = "Description";
key = ColumnName + "_" + T_Selection_ID;
selectionValueMap.put(key, rs.getString(ColumnName));
} }
} }
catch (Exception e) catch (Exception e)

View File

@ -3098,6 +3098,8 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess
} }
else if (il != null) else if (il != null)
{ {
if (il.getC_OrderLine_ID() > 0)
iol.setC_OrderLine_ID(il.getC_OrderLine_ID());
if (il.getQtyEntered().compareTo(il.getQtyInvoiced()) != 0) if (il.getQtyEntered().compareTo(il.getQtyInvoiced()) != 0)
{ {
iol.setMovementQty(Qty iol.setMovementQty(Qty

View File

@ -2727,7 +2727,6 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
for(int col = 0 ; col < p_layout.length; col ++) for(int col = 0 ; col < p_layout.length; col ++)
{ {
// layout has same columns as selectedInfo // layout has same columns as selectedInfo
if (!p_layout[col].isReadOnly())
values.put(p_layout[col].getColumnName(), selectedInfo.getValue().get(col)); values.put(p_layout[col].getColumnName(), selectedInfo.getValue().get(col));
} }
if(values.size() > 0) if(values.size() > 0)