From ab5c5817fa63dd2c48982f5b638a49dccb0f48bc Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 11 Jul 2018 13:34:43 +0200 Subject: [PATCH] IDEMPIERE-3743 Changing price list does not change currency when entering an invoice/order (AP2-383) --- .../src/org/compiere/model/CalloutOrder.java | 65 ++++++------------- .../src/org/compiere/model/MPriceList.java | 2 +- 2 files changed, 20 insertions(+), 47 deletions(-) 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 617ac5698f..9776dff0ef 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java @@ -651,58 +651,31 @@ public class CalloutOrder extends CalloutEngine Integer M_PriceList_ID = (Integer) mTab.getValue("M_PriceList_ID"); if (M_PriceList_ID == null || M_PriceList_ID.intValue()== 0) return ""; - if (steps) log.warning("init"); - PreparedStatement pstmt = null; - ResultSet rs = null; - String sql = "SELECT pl.IsTaxIncluded,pl.EnforcePriceLimit,pl.C_Currency_ID,c.StdPrecision," - + "plv.M_PriceList_Version_ID,plv.ValidFrom " - + "FROM M_PriceList pl,C_Currency c,M_PriceList_Version plv " - + "WHERE pl.C_Currency_ID=c.C_Currency_ID" - + " AND pl.M_PriceList_ID=plv.M_PriceList_ID" - + " AND pl.M_PriceList_ID=? " // 1 - + " AND plv.ValidFrom <= ? " - + "ORDER BY plv.ValidFrom DESC"; - // Use newest price list - may not be future - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, M_PriceList_ID.intValue()); - Timestamp date = new Timestamp(System.currentTimeMillis()); + + MPriceList pl = MPriceList.get(ctx, M_PriceList_ID, null); + if (pl != null && pl.getM_PriceList_ID() == M_PriceList_ID) { + if (!readonly) { + // Tax Included + mTab.setValue("IsTaxIncluded", pl.isTaxIncluded()); + // Currency + mTab.setValue("C_Currency_ID", pl.getC_Currency_ID()); + } + // Price Limit Enforce + Env.setContext(ctx, WindowNo, "EnforcePriceLimit", pl.isEnforcePriceLimit()); + + // PriceList Version + Timestamp date = null; if (mTab.getAD_Table_ID() == I_C_Order.Table_ID) date = Env.getContextAsDate(ctx, WindowNo, "DateOrdered"); else if (mTab.getAD_Table_ID() == I_C_Invoice.Table_ID) date = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced"); - pstmt.setTimestamp(2, date); - - rs = pstmt.executeQuery(); - if (rs.next()) - { - // Tax Included - if (!readonly) { - mTab.setValue("IsTaxIncluded", new Boolean("Y".equals(rs.getString(1)))); - } - // Price Limit Enforce - Env.setContext(ctx, WindowNo, "EnforcePriceLimit", rs.getString(2)); - // Currency - if (!readonly) { - Integer ii = new Integer(rs.getInt(3)); - mTab.setValue("C_Currency_ID", ii); - } - // PriceList Version - Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", rs.getInt(5)); + MPriceListVersion plv = pl.getPriceListVersion(date); + if (plv != null && plv.getM_PriceList_Version_ID() > 0) { + Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", plv.getM_PriceList_Version_ID()); + } else { + Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", (String) null); } } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - return e.getLocalizedMessage(); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - if (steps) log.warning("fini"); return ""; } // priceListFill diff --git a/org.adempiere.base/src/org/compiere/model/MPriceList.java b/org.adempiere.base/src/org/compiere/model/MPriceList.java index f569d2b6f9..b06188c463 100644 --- a/org.adempiere.base/src/org/compiere/model/MPriceList.java +++ b/org.adempiere.base/src/org/compiere/model/MPriceList.java @@ -248,7 +248,7 @@ public class MPriceList extends X_M_PriceList .setOrderBy("ValidFrom DESC") .first(); if (m_plv == null) - log.warning("None found M_PriceList_ID=" + getM_PriceList_ID() + " - " + valid); + if (log.isLoggable(Level.INFO)) log.info("None found M_PriceList_ID=" + getM_PriceList_ID() + " - " + valid); else if (log.isLoggable(Level.FINE)) log.fine(m_plv.toString()); return m_plv;