diff --git a/base/src/org/compiere/model/MPriceList.java b/base/src/org/compiere/model/MPriceList.java index e7cc2bfa59..fea455e744 100644 --- a/base/src/org/compiere/model/MPriceList.java +++ b/base/src/org/compiere/model/MPriceList.java @@ -99,6 +99,53 @@ public class MPriceList extends X_M_PriceList return retValue; } // getDefault + /** + * Get Default Price List for Client (cached) with given currency + * @param ctx context + * @param IsSOPriceList SO or PO + * @param ISOCurrency + * @return PriceList or null + */ + public static MPriceList getDefault(Properties ctx, boolean IsSOPriceList, String ISOCurrency) + { + int AD_Client_ID = Env.getAD_Client_ID(ctx); + MCurrency currency = MCurrency.get(ctx, ISOCurrency); + // If currency is null, return the default without looking at currency + if (currency==null) return(getDefault(ctx, IsSOPriceList)); + + int M_Currency_ID = currency.get_ID(); + + MPriceList retValue = null; + // Search for it in cache + Iterator it = s_cache.values().iterator(); + while (it.hasNext()) + { + retValue = it.next(); + if (retValue.isDefault() + && retValue.getAD_Client_ID() == AD_Client_ID + && retValue.isSOPriceList() == IsSOPriceList + && retValue.getC_Currency_ID()==M_Currency_ID + ) + { + return retValue; + } + } + + // Get from DB + final String whereClause = "AD_Client_ID=? AND IsDefault=? AND IsSOPriceList=? AND C_Currency_ID=?"; + retValue = new Query(ctx, Table_Name, whereClause, null) + .setParameters(new Object[]{AD_Client_ID, "Y", IsSOPriceList ? "Y" : "N", Integer.valueOf(M_Currency_ID)}) + .setOrderBy("M_PriceList_ID") + .first(); + + // Return value + if (retValue != null) + { + s_cache.put(retValue.get_ID(), retValue); + } + return retValue; + } + /** * Get Standard Currency Precision * @param ctx context