From 7c48dd78af8c47da391c9f7e5050342be08f5b04 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 1 May 2018 13:31:50 +0200 Subject: [PATCH] IDEMPIERE-2825 - Pluggable product pricing / partial backout of 7338b68 - to avoid NPE when importing invoices, on import time the pricing is called at a time where the line still doesn't have a header in database --- .../org/compiere/model/CalloutInvoice.java | 24 ++++++++++++------- .../src/org/compiere/model/CalloutOrder.java | 23 +++++++++++------- 2 files changed, 31 insertions(+), 16 deletions(-) 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 a78788b2bd..e09670033d 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java @@ -26,7 +26,6 @@ import java.util.logging.Level; import org.adempiere.base.Core; import org.adempiere.base.IProductPricing; -import org.adempiere.model.GridTabWrapper; import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.DisplayType; @@ -322,9 +321,11 @@ public class CalloutInvoice extends CalloutEngine mTab.setValue("M_AttributeSetInstance_ID", null); /***** Price Calculation see also qty ****/ - I_C_InvoiceLine invoiceLine = GridTabWrapper.create(mTab, I_C_InvoiceLine.class); + boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y"); + int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, "C_BPartner_ID"); + BigDecimal Qty = (BigDecimal)mTab.getValue("QtyInvoiced"); IProductPricing pp = Core.getProductPricing(); - pp.setInvoiceLine(invoiceLine, null); + pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null); // int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"); pp.setM_PriceList_ID(M_PriceList_ID); @@ -347,6 +348,8 @@ public class CalloutInvoice extends CalloutEngine } pp.setM_PriceList_Version_ID(M_PriceList_Version_ID); + Timestamp date = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced"); + pp.setPriceDate(date); // mTab.setValue("PriceList", pp.getPriceList()); mTab.setValue("PriceLimit", pp.getPriceLimit()); @@ -552,18 +555,20 @@ public class CalloutInvoice extends CalloutEngine || mField.getColumnName().equals("M_Product_ID")) && !"N".equals(Env.getContext(ctx, WindowNo, "DiscountSchema"))) { + int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, "C_BPartner_ID"); if (mField.getColumnName().equals("QtyEntered")) QtyInvoiced = MUOMConversion.convertProductFrom (ctx, M_Product_ID, C_UOM_To_ID, QtyEntered); if (QtyInvoiced == null) QtyInvoiced = QtyEntered; - I_C_InvoiceLine invoiceLine = GridTabWrapper.create(mTab, I_C_InvoiceLine.class); + boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y"); IProductPricing pp = Core.getProductPricing(); - pp.setInvoiceLine(invoiceLine, null); + pp.setInitialValues(M_Product_ID, C_BPartner_ID, QtyInvoiced, IsSOTrx, null); pp.setM_PriceList_ID(M_PriceList_ID); - pp.setQty(QtyInvoiced); int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID"); pp.setM_PriceList_Version_ID(M_PriceList_Version_ID); + Timestamp date = (Timestamp)mTab.getValue("DateInvoiced"); + pp.setPriceDate(date); // PriceEntered = MUOMConversion.convertProductFrom (ctx, M_Product_ID, C_UOM_To_ID, pp.getPriceStd()); @@ -836,9 +841,11 @@ public class CalloutInvoice extends CalloutEngine } /***** Price Calculation see also qty ****/ - I_C_InvoiceLine invoiceLine = GridTabWrapper.create(mTab, I_C_InvoiceLine.class); + 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"); IProductPricing pp = Core.getProductPricing(); - pp.setInvoiceLine(invoiceLine, null); + pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null); // int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"); pp.setM_PriceList_ID(M_PriceList_ID); @@ -859,6 +866,7 @@ public class CalloutInvoice extends CalloutEngine 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"); 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 4f300b068c..9b33fa87be 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java @@ -26,7 +26,6 @@ import java.util.logging.Level; import org.adempiere.base.Core; import org.adempiere.base.IProductPricing; -import org.adempiere.model.GridTabWrapper; import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.DisplayType; @@ -779,9 +778,11 @@ public class CalloutOrder extends CalloutEngine mTab.setValue("M_AttributeSetInstance_ID", null); /***** Price Calculation see also qty ****/ - I_C_OrderLine orderLine = GridTabWrapper.create(mTab, I_C_OrderLine.class); + 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"); IProductPricing pp = Core.getProductPricing(); - pp.setOrderLine(orderLine, null); + pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null); // int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"); pp.setM_PriceList_ID(M_PriceList_ID); @@ -802,6 +803,7 @@ public class CalloutOrder extends CalloutEngine Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", M_PriceList_Version_ID ); } pp.setM_PriceList_Version_ID(M_PriceList_Version_ID); + pp.setPriceDate(orderDate); // mTab.setValue("PriceList", pp.getPriceList()); mTab.setValue("PriceLimit", pp.getPriceLimit()); @@ -1075,18 +1077,20 @@ public class CalloutOrder extends CalloutEngine || mField.getColumnName().equals("M_Product_ID")) && !"N".equals(Env.getContext(ctx, WindowNo, "DiscountSchema"))) { + int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, "C_BPartner_ID"); if (mField.getColumnName().equals("QtyEntered")) QtyOrdered = MUOMConversion.convertProductFrom (ctx, M_Product_ID, C_UOM_To_ID, QtyEntered); if (QtyOrdered == null) QtyOrdered = QtyEntered; - I_C_OrderLine orderLine = GridTabWrapper.create(mTab, I_C_OrderLine.class); + boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y"); IProductPricing pp = Core.getProductPricing(); - pp.setOrderLine(orderLine, null); - pp.setQty(QtyOrdered); + pp.setInitialValues(M_Product_ID, C_BPartner_ID, QtyOrdered, IsSOTrx, null); pp.setM_PriceList_ID(M_PriceList_ID); int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID"); pp.setM_PriceList_Version_ID(M_PriceList_Version_ID); + Timestamp date = (Timestamp)mTab.getValue("DateOrdered"); + pp.setPriceDate(date); // PriceEntered = MUOMConversion.convertProductFrom (ctx, M_Product_ID, C_UOM_To_ID, pp.getPriceStd()); @@ -1407,9 +1411,11 @@ public class CalloutOrder extends CalloutEngine } /***** Price Calculation see also qty ****/ - I_C_OrderLine orderLine = GridTabWrapper.create(mTab, I_C_OrderLine.class); + 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"); IProductPricing pp = Core.getProductPricing(); - pp.setOrderLine(orderLine, null); + pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null); // int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"); pp.setM_PriceList_ID(M_PriceList_ID); @@ -1430,6 +1436,7 @@ public class CalloutOrder extends CalloutEngine 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");