IDEMPIERE-3743 Changing price list does not change currency when entering an invoice/order (AP2-383)

This commit is contained in:
Carlos Ruiz 2018-07-11 13:34:43 +02:00
parent 975e7d7c87
commit ab5c5817fa
2 changed files with 20 additions and 47 deletions

View File

@ -651,58 +651,31 @@ public class CalloutOrder extends CalloutEngine
Integer M_PriceList_ID = (Integer) mTab.getValue("M_PriceList_ID"); Integer M_PriceList_ID = (Integer) mTab.getValue("M_PriceList_ID");
if (M_PriceList_ID == null || M_PriceList_ID.intValue()== 0) if (M_PriceList_ID == null || M_PriceList_ID.intValue()== 0)
return ""; return "";
if (steps) log.warning("init");
PreparedStatement pstmt = null; MPriceList pl = MPriceList.get(ctx, M_PriceList_ID, null);
ResultSet rs = null; if (pl != null && pl.getM_PriceList_ID() == M_PriceList_ID) {
String sql = "SELECT pl.IsTaxIncluded,pl.EnforcePriceLimit,pl.C_Currency_ID,c.StdPrecision," if (!readonly) {
+ "plv.M_PriceList_Version_ID,plv.ValidFrom " // Tax Included
+ "FROM M_PriceList pl,C_Currency c,M_PriceList_Version plv " mTab.setValue("IsTaxIncluded", pl.isTaxIncluded());
+ "WHERE pl.C_Currency_ID=c.C_Currency_ID" // Currency
+ " AND pl.M_PriceList_ID=plv.M_PriceList_ID" mTab.setValue("C_Currency_ID", pl.getC_Currency_ID());
+ " AND pl.M_PriceList_ID=? " // 1 }
+ " AND plv.ValidFrom <= ? " // Price Limit Enforce
+ "ORDER BY plv.ValidFrom DESC"; Env.setContext(ctx, WindowNo, "EnforcePriceLimit", pl.isEnforcePriceLimit());
// Use newest price list - may not be future
try // PriceList Version
{ Timestamp date = null;
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_PriceList_ID.intValue());
Timestamp date = new Timestamp(System.currentTimeMillis());
if (mTab.getAD_Table_ID() == I_C_Order.Table_ID) if (mTab.getAD_Table_ID() == I_C_Order.Table_ID)
date = Env.getContextAsDate(ctx, WindowNo, "DateOrdered"); date = Env.getContextAsDate(ctx, WindowNo, "DateOrdered");
else if (mTab.getAD_Table_ID() == I_C_Invoice.Table_ID) else if (mTab.getAD_Table_ID() == I_C_Invoice.Table_ID)
date = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced"); date = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
pstmt.setTimestamp(2, date); MPriceListVersion plv = pl.getPriceListVersion(date);
if (plv != null && plv.getM_PriceList_Version_ID() > 0) {
rs = pstmt.executeQuery(); Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", plv.getM_PriceList_Version_ID());
if (rs.next()) } else {
{ Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", (String) null);
// 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));
} }
} }
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 ""; return "";
} // priceListFill } // priceListFill

View File

@ -248,7 +248,7 @@ public class MPriceList extends X_M_PriceList
.setOrderBy("ValidFrom DESC") .setOrderBy("ValidFrom DESC")
.first(); .first();
if (m_plv == null) 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 else
if (log.isLoggable(Level.FINE)) log.fine(m_plv.toString()); if (log.isLoggable(Level.FINE)) log.fine(m_plv.toString());
return m_plv; return m_plv;