IDEMPIERE-2825 - Pluggable product pricing - solve the NPE while still allowing new columns in line to be used by the plugin

This commit is contained in:
Carlos Ruiz 2018-05-01 13:54:41 +02:00
parent 7c48dd78af
commit 3f0872261b
3 changed files with 50 additions and 20 deletions

View File

@ -26,6 +26,7 @@ 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;
@ -326,11 +327,15 @@ public class CalloutInvoice extends CalloutEngine
BigDecimal Qty = (BigDecimal)mTab.getValue("QtyInvoiced");
IProductPricing pp = Core.getProductPricing();
pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null);
Timestamp invoiceDate = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
pp.setPriceDate(invoiceDate);
I_C_InvoiceLine invoiceLine = GridTabWrapper.create(mTab, I_C_InvoiceLine.class);
pp.setInvoiceLine(invoiceLine, null);
//
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)
@ -348,8 +353,6 @@ 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());
@ -564,11 +567,13 @@ public class CalloutInvoice extends CalloutEngine
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
IProductPricing pp = Core.getProductPricing();
pp.setInitialValues(M_Product_ID, C_BPartner_ID, QtyInvoiced, IsSOTrx, null);
Timestamp date = (Timestamp)mTab.getValue("DateInvoiced");
pp.setPriceDate(date);
I_C_InvoiceLine invoiceLine = GridTabWrapper.create(mTab, I_C_InvoiceLine.class);
pp.setInvoiceLine(invoiceLine, 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("DateInvoiced");
pp.setPriceDate(date);
//
PriceEntered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
C_UOM_To_ID, pp.getPriceStd());
@ -846,10 +851,13 @@ public class CalloutInvoice extends CalloutEngine
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
IProductPricing pp = Core.getProductPricing();
pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null);
Timestamp orderDate = (Timestamp)mTab.getValue("DateOrdered");
pp.setPriceDate(orderDate);
I_C_InvoiceLine invoiceLine = GridTabWrapper.create(mTab, I_C_InvoiceLine.class);
pp.setInvoiceLine(invoiceLine, null);
//
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)
@ -866,7 +874,6 @@ 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");

View File

@ -26,6 +26,7 @@ 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;
@ -783,10 +784,13 @@ public class CalloutOrder extends CalloutEngine
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
IProductPricing pp = Core.getProductPricing();
pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null);
Timestamp orderDate = (Timestamp)mTab.getValue("DateOrdered");
pp.setPriceDate(orderDate);
I_C_OrderLine orderLine = GridTabWrapper.create(mTab, I_C_OrderLine.class);
pp.setOrderLine(orderLine, null);
//
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)
@ -803,7 +807,6 @@ 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());
@ -1086,11 +1089,13 @@ public class CalloutOrder extends CalloutEngine
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
IProductPricing pp = Core.getProductPricing();
pp.setInitialValues(M_Product_ID, C_BPartner_ID, QtyOrdered, IsSOTrx, null);
Timestamp date = (Timestamp)mTab.getValue("DateOrdered");
pp.setPriceDate(date);
I_C_OrderLine orderLine = GridTabWrapper.create(mTab, I_C_OrderLine.class);
pp.setOrderLine(orderLine, 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());
@ -1416,10 +1421,13 @@ public class CalloutOrder extends CalloutEngine
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
IProductPricing pp = Core.getProductPricing();
pp.setInitialValues(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null);
Timestamp orderDate = (Timestamp)mTab.getValue("DateOrdered");
pp.setPriceDate(orderDate);
I_C_OrderLine orderLine = GridTabWrapper.create(mTab, I_C_OrderLine.class);
pp.setOrderLine(orderLine, null);
//
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)
@ -1436,7 +1444,6 @@ 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");

View File

@ -16,9 +16,13 @@ package org.adempiere.base;
import java.math.BigDecimal;
import java.sql.Timestamp;
import org.compiere.model.I_C_Invoice;
import org.compiere.model.I_C_InvoiceLine;
import org.compiere.model.I_C_Order;
import org.compiere.model.I_C_OrderLine;
import org.compiere.model.I_C_Project;
import org.compiere.model.I_C_ProjectLine;
import org.compiere.model.I_M_RMA;
import org.compiere.model.I_M_RMALine;
import org.compiere.model.I_M_RequisitionLine;
import org.compiere.util.Env;
@ -86,11 +90,14 @@ public abstract class AbstractProductPricing implements IProductPricing {
@Override
public void setOrderLine(I_C_OrderLine orderLine, String trxName) {
m_M_Product_ID = orderLine.getM_Product_ID();
if (orderLine.getC_Order_ID() > 0) {
I_C_Order order = orderLine.getC_Order();
m_isSOTrx = order.isSOTrx();
}
m_C_BPartner_ID = orderLine.getC_BPartner_ID();
BigDecimal qty = orderLine.getQtyOrdered();
if (qty != null && Env.ZERO.compareTo(qty) != 0)
m_Qty = qty;
m_isSOTrx = orderLine.getC_Order().isSOTrx();
m_PriceDate = orderLine.getDateOrdered();
this.trxName = trxName;
}
@ -98,20 +105,26 @@ public abstract class AbstractProductPricing implements IProductPricing {
@Override
public void setInvoiceLine(I_C_InvoiceLine invoiceLine, String trxName) {
m_M_Product_ID = invoiceLine.getM_Product_ID();
m_C_BPartner_ID = invoiceLine.getC_Invoice().getC_BPartner_ID();
if (invoiceLine.getC_Invoice_ID() > 0) {
I_C_Invoice invoice = invoiceLine.getC_Invoice();
m_C_BPartner_ID = invoice.getC_BPartner_ID();
m_isSOTrx = invoice.isSOTrx();
m_PriceDate = invoice.getDateInvoiced();
}
BigDecimal qty = invoiceLine.getQtyInvoiced() != null ?
invoiceLine.getQtyInvoiced() : invoiceLine.getQtyEntered();
if (qty != null && Env.ZERO.compareTo(qty) != 0)
m_Qty = qty;
m_isSOTrx = invoiceLine.getC_Invoice().isSOTrx();
m_PriceDate = invoiceLine.getC_Invoice().getDateInvoiced();
this.trxName = trxName;
}
@Override
public void setProjectLine(I_C_ProjectLine projectLine, String trxName) {
m_M_Product_ID = projectLine.getM_Product_ID();
m_C_BPartner_ID = projectLine.getC_Project().getC_BPartner_ID();
if (projectLine.getC_Project_ID() > 0) {
I_C_Project project = projectLine.getC_Project();
m_C_BPartner_ID = project.getC_BPartner_ID();
}
BigDecimal qty = projectLine.getPlannedQty();
if (qty != null && Env.ZERO.compareTo(qty) != 0)
m_Qty = qty;
@ -133,9 +146,12 @@ public abstract class AbstractProductPricing implements IProductPricing {
@Override
public void setRMALine(I_M_RMALine rmaLine, String trxName) {
m_M_Product_ID = rmaLine.getM_Product_ID();
m_C_BPartner_ID = rmaLine.getM_RMA().getC_BPartner_ID();
if (rmaLine.getM_RMA_ID() > 0) {
I_M_RMA rma = rmaLine.getM_RMA();
m_C_BPartner_ID = rma.getC_BPartner_ID();
m_isSOTrx = rma.isSOTrx();
}
m_Qty = Env.ONE;
m_isSOTrx = rmaLine.getM_RMA().isSOTrx();
this.trxName = trxName;
}
}