From edcd061da7909adcfb803855966f073c857d1569 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 26 Mar 2010 14:44:24 +0000 Subject: [PATCH] Fix [2962244] - Future dated price list version used in order Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2962244 --- base/src/org/compiere/model/CalloutInvoice.java | 17 +++++++++++++++++ base/src/org/compiere/model/CalloutOrder.java | 10 ++++++---- migration/354a-trunk/oracle/697_BF2962244.sql | 16 ++++++++++++++++ .../354a-trunk/postgresql/697_BF2962244.sql | 17 +++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 migration/354a-trunk/oracle/697_BF2962244.sql create mode 100644 migration/354a-trunk/postgresql/697_BF2962244.sql diff --git a/base/src/org/compiere/model/CalloutInvoice.java b/base/src/org/compiere/model/CalloutInvoice.java index 5fe0dddce4..7abda9e8cf 100644 --- a/base/src/org/compiere/model/CalloutInvoice.java +++ b/base/src/org/compiere/model/CalloutInvoice.java @@ -321,7 +321,24 @@ public class CalloutInvoice extends CalloutEngine // int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"); pp.setM_PriceList_ID(M_PriceList_ID); + + Timestamp invoiceDate = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced"); + /** PLV is only accurate if PL selected in header */ int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID"); + if ( M_PriceList_Version_ID == 0 && M_PriceList_ID > 0) + { + String sql = "SELECT plv.M_PriceList_Version_ID " + + "FROM M_PriceList_Version plv " + + "WHERE plv.M_PriceList_ID=? " // 1 + + " AND plv.ValidFrom <= ? " + + "ORDER BY plv.ValidFrom DESC"; + // Use newest price list - may not be future + + M_PriceList_Version_ID = DB.getSQLValueEx(null, sql, M_PriceList_ID, invoiceDate); + if ( M_PriceList_Version_ID > 0 ) + Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", M_PriceList_Version_ID ); + } + pp.setM_PriceList_Version_ID(M_PriceList_Version_ID); Timestamp date = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced"); pp.setPriceDate(date); diff --git a/base/src/org/compiere/model/CalloutOrder.java b/base/src/org/compiere/model/CalloutOrder.java index 65316d7ef0..a43c75e12e 100644 --- a/base/src/org/compiere/model/CalloutOrder.java +++ b/base/src/org/compiere/model/CalloutOrder.java @@ -621,7 +621,7 @@ public class CalloutOrder extends CalloutEngine */ public String priceList (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) { - Integer M_PriceList_ID = (Integer)value; + 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"); @@ -640,7 +640,11 @@ public class CalloutOrder extends CalloutEngine { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, M_PriceList_ID.intValue()); - Timestamp date = Env.getContextAsDate(ctx, WindowNo, "DateOrdered"); + Timestamp date = new Timestamp(System.currentTimeMillis()); + 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(); @@ -715,8 +719,6 @@ public class CalloutOrder extends CalloutEngine int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID"); if ( M_PriceList_Version_ID == 0 && M_PriceList_ID > 0) { - PreparedStatement pstmt = null; - ResultSet rs = null; String sql = "SELECT plv.M_PriceList_Version_ID " + "FROM M_PriceList_Version plv " + "WHERE plv.M_PriceList_ID=? " // 1 diff --git a/migration/354a-trunk/oracle/697_BF2962244.sql b/migration/354a-trunk/oracle/697_BF2962244.sql new file mode 100644 index 0000000000..cdc965f302 --- /dev/null +++ b/migration/354a-trunk/oracle/697_BF2962244.sql @@ -0,0 +1,16 @@ +-- Mar 16, 2010 10:59:51 PM COT +-- BF 2962244 Future dated price list version used in order +UPDATE AD_Column SET Callout=NULL,Updated=TO_DATE('2010-03-16 22:59:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56376 +; + +-- Mar 16, 2010 11:00:48 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.dateAcct; org.compiere.model.CalloutOrder.priceList',Updated=TO_DATE('2010-03-16 23:00:48','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2181 +; + +-- Mar 16, 2010 11:00:51 PM COT +UPDATE AD_Column SET Callout=NULL,Updated=TO_DATE('2010-03-16 23:00:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2166 +; + +-- Mar 16, 2010 11:01:11 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.dateAcct; org.compiere.model.CalloutOrder.priceList',Updated=TO_DATE('2010-03-16 23:01:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3783 +; diff --git a/migration/354a-trunk/postgresql/697_BF2962244.sql b/migration/354a-trunk/postgresql/697_BF2962244.sql new file mode 100644 index 0000000000..2799f5dc69 --- /dev/null +++ b/migration/354a-trunk/postgresql/697_BF2962244.sql @@ -0,0 +1,17 @@ +-- Mar 16, 2010 10:59:51 PM COT +-- BF 2962244 Future dated price list version used in order +UPDATE AD_Column SET Callout=NULL,Updated=TO_TIMESTAMP('2010-03-16 22:59:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=56376 +; + +-- Mar 16, 2010 11:00:48 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.dateAcct; org.compiere.model.CalloutOrder.priceList',Updated=TO_TIMESTAMP('2010-03-16 23:00:48','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2181 +; + +-- Mar 16, 2010 11:00:51 PM COT +UPDATE AD_Column SET Callout=NULL,Updated=TO_TIMESTAMP('2010-03-16 23:00:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2166 +; + +-- Mar 16, 2010 11:01:11 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.dateAcct; org.compiere.model.CalloutOrder.priceList',Updated=TO_TIMESTAMP('2010-03-16 23:01:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3783 +; +