diff --git a/migration/i4.1/oracle/201706241900_IDEMPIERE-3401.sql b/migration/i4.1/oracle/201706241900_IDEMPIERE-3401.sql new file mode 100644 index 0000000000..50a21b0432 --- /dev/null +++ b/migration/i4.1/oracle/201706241900_IDEMPIERE-3401.sql @@ -0,0 +1,15 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-3401 Orderline Discount Context issue +-- Jun 24, 2017 6:44:50 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutOrder.navigateOrderLine', IsUpdateable='N',Updated=TO_DATE('2017-06-24 18:44:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2205 +; + +-- Jun 24, 2017 6:45:45 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutInvoice.navigateInvoiceLine', IsUpdateable='N',Updated=TO_DATE('2017-06-24 18:45:45','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3828 +; + +SELECT register_migration_script('201706241900_IDEMPIERE-3401.sql') FROM dual +; + diff --git a/migration/i4.1/postgresql/201706241900_IDEMPIERE-3401.sql b/migration/i4.1/postgresql/201706241900_IDEMPIERE-3401.sql new file mode 100644 index 0000000000..cf898c6e8e --- /dev/null +++ b/migration/i4.1/postgresql/201706241900_IDEMPIERE-3401.sql @@ -0,0 +1,12 @@ +-- IDEMPIERE-3401 Orderline Discount Context issue +-- Jun 24, 2017 6:44:50 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutOrder.navigateOrderLine', IsUpdateable='N',Updated=TO_TIMESTAMP('2017-06-24 18:44:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2205 +; + +-- Jun 24, 2017 6:45:45 PM CEST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutInvoice.navigateInvoiceLine', IsUpdateable='N',Updated=TO_TIMESTAMP('2017-06-24 18:45:45','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3828 +; + +SELECT register_migration_script('201706241900_IDEMPIERE-3401.sql') FROM dual +; + diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java index 35abd3717e..d937cafebc 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java @@ -832,6 +832,45 @@ public class CalloutInvoice extends CalloutEngine // return ""; } // qty - - + + public String navigateInvoiceLine(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) { + Integer M_Product_ID = Env.getContextAsInt(ctx, WindowNo, mTab.getTabNo(), "M_Product_ID"); + if (M_Product_ID == null || M_Product_ID.intValue() == 0) { + Env.setContext(ctx, WindowNo, "DiscountSchema", "N"); + return ""; + } + + /***** Price Calculation see also qty ****/ + int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, "C_BPartner_ID"); + BigDecimal Qty = (BigDecimal)mTab.getValue("QtyOrdered"); + boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y"); + MProductPricing pp = new MProductPricing (M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx); + // + int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"); + pp.setM_PriceList_ID(M_PriceList_ID); + Timestamp orderDate = (Timestamp)mTab.getValue("DateOrdered"); + /** 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, orderDate); + 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); + pp.setPriceDate(orderDate); + // + Env.setContext(ctx, WindowNo, "EnforcePriceLimit", pp.isEnforcePriceLimit() ? "Y" : "N"); + Env.setContext(ctx, WindowNo, "DiscountSchema", pp.isDiscountSchema() ? "Y" : "N"); + + return ""; + } + } // CalloutInvoice 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 e7af41069b..8600179ba8 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java @@ -1411,5 +1411,46 @@ public class CalloutOrder extends CalloutEngine } return ""; } + + public String navigateOrderLine(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) { + Integer M_Product_ID = Env.getContextAsInt(ctx, WindowNo, mTab.getTabNo(), "M_Product_ID"); + if (M_Product_ID == null || M_Product_ID.intValue() == 0) { + Env.setContext(ctx, WindowNo, "DiscountSchema", "N"); + return ""; + } + + /***** Price Calculation see also qty ****/ + int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, "C_BPartner_ID"); + BigDecimal Qty = (BigDecimal)mTab.getValue("QtyOrdered"); + boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y"); + MProductPricing pp = new MProductPricing (M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx); + // + int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"); + pp.setM_PriceList_ID(M_PriceList_ID); + Timestamp orderDate = (Timestamp)mTab.getValue("DateOrdered"); + /** 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, orderDate); + 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); + pp.setPriceDate(orderDate); + // + Env.setContext(ctx, WindowNo, "EnforcePriceLimit", pp.isEnforcePriceLimit() ? "Y" : "N"); + Env.setContext(ctx, WindowNo, "DiscountSchema", pp.isDiscountSchema() ? "Y" : "N"); + + return ""; + } + } // CalloutOrder