From 8538db5ec8c821b4fa0a28d4a98348df7378de96 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Thu, 12 Feb 2009 07:42:09 +0000 Subject: [PATCH] [ 1761918 ] Error creating periods for a year with per. created partial - refactoring - NPE [ https://sourceforge.net/forum/message.php?msg_id=6404099 ] --- base/src/org/compiere/model/MPeriod.java | 18 ++++++++++++++++-- base/src/org/compiere/model/MYear.java | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/base/src/org/compiere/model/MPeriod.java b/base/src/org/compiere/model/MPeriod.java index 029b8a60b9..532f18e962 100644 --- a/base/src/org/compiere/model/MPeriod.java +++ b/base/src/org/compiere/model/MPeriod.java @@ -95,12 +95,26 @@ public class MPeriod extends X_C_Period */ public static MPeriod get (Properties ctx, Timestamp DateAcct, int AD_Org_ID) { - int AD_Client_ID = Env.getAD_Client_ID(ctx); + if (DateAcct == null) return null; int C_Calendar_ID = getC_Calendar_ID(ctx,AD_Org_ID); + return findByCalendar(ctx, DateAcct, C_Calendar_ID); + } // get + + /** + * + * @param ctx + * @param DateAcct + * @param C_Calendar_ID + * @return MPeriod + */ + public static MPeriod findByCalendar(Properties ctx, Timestamp DateAcct, + int C_Calendar_ID) { + + int AD_Client_ID = Env.getAD_Client_ID(ctx); // Search in Cache first Iterator it = s_cache.values().iterator(); while (it.hasNext()) @@ -152,7 +166,7 @@ public class MPeriod extends X_C_Period s_log.warning("No Standard Period for " + DateAcct + " (AD_Client_ID=" + AD_Client_ID + ")"); return retValue; - } // get + } /** * Find valid standard Period of DateAcct based on Client Calendar diff --git a/base/src/org/compiere/model/MYear.java b/base/src/org/compiere/model/MYear.java index 3e52319947..533ea93ffa 100644 --- a/base/src/org/compiere/model/MYear.java +++ b/base/src/org/compiere/model/MYear.java @@ -224,7 +224,7 @@ public class MYear extends X_C_Year cal.add(Calendar.DAY_OF_YEAR, -1); Timestamp end = new Timestamp(cal.getTimeInMillis()); // - MPeriod period = MPeriod.get(getCtx(), start, getAD_Org_ID()); + MPeriod period = MPeriod.findByCalendar(getCtx(), start, getC_Calendar_ID()); if (period == null) { period = new MPeriod (this, month+1, name, start, end);