diff --git a/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java b/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java
index bdadacea6a..c14c3bb203 100644
--- a/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java
+++ b/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java
@@ -20,6 +20,8 @@ package org.adempiere.model;
import java.math.BigDecimal;
import java.util.Properties;
+import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.compiere.model.CalloutEngine;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
@@ -30,7 +32,6 @@ import org.compiere.model.MInvoice;
import org.compiere.model.MInvoiceLine;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
-import org.compiere.model.MProductPricing;
import org.compiere.model.MRMA;
import org.compiere.model.MRMALine;
import org.compiere.model.Query;
@@ -146,7 +147,8 @@ public class CalloutRMA extends CalloutEngine {
return "";
MRMA rma = new MRMA(ctx, M_RMA_ID, null);
- MProductPricing pp = new MProductPricing(M_Product_ID, rma.getC_BPartner_ID(), Env.ONE, rma.isSOTrx(), null);
+ IProductPricing pp = Core.getProductPricing();
+ pp.setInitialValues(M_Product_ID, rma.getC_BPartner_ID(), Env.ONE, rma.isSOTrx(), null);
int taxId = 0;
int precision = 0;
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 e8b3f4f666..a0d7beafc3 100644
--- a/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java
+++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutInvoice.java
@@ -24,6 +24,8 @@ import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;
+import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
@@ -327,7 +329,8 @@ public class CalloutInvoice extends CalloutEngine
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");
- MProductPricing pp = new MProductPricing (M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx, null);
+ IProductPricing pp = Core.getProductPricing();
+ 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);
@@ -564,7 +567,8 @@ public class CalloutInvoice extends CalloutEngine
if (QtyInvoiced == null)
QtyInvoiced = QtyEntered;
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
- MProductPricing pp = new MProductPricing (M_Product_ID, C_BPartner_ID, QtyInvoiced, IsSOTrx, null);
+ IProductPricing pp = Core.getProductPricing();
+ pp.setInitialValues(M_Product_ID, C_BPartner_ID, QtyInvoiced, 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);
@@ -845,7 +849,8 @@ public class CalloutInvoice extends CalloutEngine
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, null);
+ IProductPricing pp = Core.getProductPricing();
+ 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);
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 7cc24c63aa..59cf24c2fc 100644
--- a/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java
+++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutOrder.java
@@ -24,6 +24,8 @@ import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;
+import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
@@ -800,7 +802,8 @@ public class CalloutOrder extends CalloutEngine
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, null);
+ IProductPricing pp = Core.getProductPricing();
+ 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);
@@ -1096,7 +1099,8 @@ public class CalloutOrder extends CalloutEngine
if (QtyOrdered == null)
QtyOrdered = QtyEntered;
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
- MProductPricing pp = new MProductPricing (M_Product_ID, C_BPartner_ID, QtyOrdered, IsSOTrx, null);
+ IProductPricing pp = Core.getProductPricing();
+ 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);
@@ -1425,7 +1429,8 @@ public class CalloutOrder extends CalloutEngine
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, null);
+ IProductPricing pp = Core.getProductPricing();
+ 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);
diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutRequisition.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutRequisition.java
index 5391757bda..45eb0157fc 100644
--- a/org.adempiere.base.callout/src/org/compiere/model/CalloutRequisition.java
+++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutRequisition.java
@@ -21,6 +21,8 @@ import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;
+import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.adempiere.model.GridTabWrapper;
import org.compiere.util.Env;
@@ -100,7 +102,8 @@ public class CalloutRequisition extends CalloutEngine
int C_BPartner_ID = line.getC_BPartner_ID();
BigDecimal Qty = line.getQty();
boolean isSOTrx = false;
- MProductPricing pp = new MProductPricing (line.getM_Product_ID(), C_BPartner_ID, Qty, isSOTrx, null);
+ IProductPricing pp = Core.getProductPricing();
+ pp.setInitialValues(line.getM_Product_ID(), C_BPartner_ID, Qty, isSOTrx, null);
//
int M_PriceList_ID = req.getM_PriceList_ID();
pp.setM_PriceList_ID(M_PriceList_ID);
diff --git a/org.adempiere.base.process/src/org/compiere/process/ProjectLinePricing.java b/org.adempiere.base.process/src/org/compiere/process/ProjectLinePricing.java
index 695c6201cd..3c2a3e117b 100644
--- a/org.adempiere.base.process/src/org/compiere/process/ProjectLinePricing.java
+++ b/org.adempiere.base.process/src/org/compiere/process/ProjectLinePricing.java
@@ -19,7 +19,8 @@ package org.compiere.process;
import java.util.logging.Level;
-import org.compiere.model.MProductPricing;
+import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.compiere.model.MProject;
import org.compiere.model.MProjectLine;
import org.compiere.util.Msg;
@@ -71,8 +72,9 @@ public class ProjectLinePricing extends SvrProcess
throw new IllegalArgumentException("No PriceList");
//
boolean isSOTrx = true;
- MProductPricing pp = new MProductPricing (projectLine.getM_Product_ID(),
- project.getC_BPartner_ID(), projectLine.getPlannedQty(), isSOTrx, get_TrxName());
+ IProductPricing pp = Core.getProductPricing();
+ pp.setInitialValues(projectLine.getM_Product_ID(), project.getC_BPartner_ID(),
+ projectLine.getPlannedQty(), isSOTrx, get_TrxName());
pp.setM_PriceList_ID(project.getM_PriceList_ID());
pp.setPriceDate(project.getDateContract());
//
diff --git a/org.adempiere.base/OSGI-INF/defaultproductpricingfactory.xml b/org.adempiere.base/OSGI-INF/defaultproductpricingfactory.xml
new file mode 100644
index 0000000000..27ed659f8a
--- /dev/null
+++ b/org.adempiere.base/OSGI-INF/defaultproductpricingfactory.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/org.adempiere.base/build.properties b/org.adempiere.base/build.properties
index 47da21473d..1c58047ed2 100644
--- a/org.adempiere.base/build.properties
+++ b/org.adempiere.base/build.properties
@@ -22,6 +22,7 @@ bin.includes = META-INF/,\
OSGI-INF/defaultaddressvalidationfactory.xml,\
OSGI-INF/defaulttaxproviderfactory.xml,\
OSGI-INF/addressvalidationeventhandler.xml,\
+ OSGI-INF/defaultproductpricingfactory.xml\
schema/,\
bsh-2.0b6.jar,\
commons-validator-1.6.jar
diff --git a/org.adempiere.base/src/org/adempiere/base/AbstractProductPricing.java b/org.adempiere.base/src/org/adempiere/base/AbstractProductPricing.java
new file mode 100644
index 0000000000..10704ccd5e
--- /dev/null
+++ b/org.adempiere.base/src/org/adempiere/base/AbstractProductPricing.java
@@ -0,0 +1,135 @@
+/******************************************************************************
+ * Copyright (C) 2017 Diego Ruiz *
+ * Copyright (C) 2017 Bx Service GmbH *
+ * This program is free software; you can redistribute it and/or modify it *
+ * under the terms version 2 of the GNU General Public License as published *
+ * by the Free Software Foundation. This program is distributed in the hope *
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU General Public License for more details. *
+ * You should have received a copy of the GNU General Public License along *
+ * with this program; if not, write to the Free Software Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
+ *****************************************************************************/
+package org.adempiere.base;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+
+import org.compiere.model.I_C_InvoiceLine;
+import org.compiere.model.I_C_OrderLine;
+import org.compiere.model.I_C_ProjectLine;
+import org.compiere.model.I_M_RMALine;
+import org.compiere.model.I_M_RequisitionLine;
+import org.compiere.util.Env;
+
+public abstract class AbstractProductPricing implements IProductPricing {
+
+ protected int m_M_Product_ID;
+ protected int m_C_BPartner_ID;
+ protected BigDecimal m_Qty = Env.ONE;
+ protected boolean m_isSOTrx = true;
+ protected String trxName = null;
+
+ protected int m_M_PriceList_Version_ID = 0;
+ protected int m_M_PriceList_ID = 0;
+ protected Timestamp m_PriceDate;
+
+ public AbstractProductPricing() {}
+
+ @Override
+ public void setInitialValues(int M_Product_ID, int C_BPartner_ID, BigDecimal qty, boolean isSOTrx, String trxName) {
+ this.trxName=trxName;
+ m_M_Product_ID = M_Product_ID;
+ m_C_BPartner_ID = C_BPartner_ID;
+
+ if (qty != null && Env.ZERO.compareTo(qty) != 0)
+ m_Qty = qty;
+ m_isSOTrx = isSOTrx;
+ }
+
+ @Override
+ public int getM_Product_ID() {
+ return m_M_Product_ID;
+ }
+
+ @Override
+ public int getM_PriceList_ID() {
+ return m_M_PriceList_ID;
+ }
+
+ @Override
+ public void setM_PriceList_ID(int M_PriceList_ID) {
+ m_M_PriceList_ID = M_PriceList_ID;
+ }
+
+ @Override
+ public void setM_PriceList_Version_ID(int M_PriceList_Version_ID) {
+ m_M_PriceList_Version_ID = M_PriceList_Version_ID;
+ }
+
+ @Override
+ public Timestamp getPriceDate() {
+ return m_PriceDate;
+ }
+
+ @Override
+ public void setPriceDate(Timestamp priceDate) {
+ m_PriceDate = priceDate;
+ }
+
+ @Override
+ public void setOrderLine(I_C_OrderLine orderLine, String trxName) {
+ m_M_Product_ID = orderLine.getM_Product_ID();
+ 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;
+ }
+
+ @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();
+ BigDecimal qty = invoiceLine.getQtyInvoiced();
+ 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();
+ BigDecimal qty = projectLine.getPlannedQty();
+ if (qty != null && Env.ZERO.compareTo(qty) != 0)
+ m_Qty = qty;
+ m_isSOTrx = true;
+ this.trxName = trxName;
+ }
+
+ @Override
+ public void setRequisitionLine(I_M_RequisitionLine reqLine, String trxName) {
+ m_M_Product_ID = reqLine.getM_Product_ID();
+ m_C_BPartner_ID = reqLine.getC_BPartner_ID();
+ BigDecimal qty = reqLine.getQty();
+ if (qty != null && Env.ZERO.compareTo(qty) != 0)
+ m_Qty = qty;
+ m_isSOTrx = false;
+ this.trxName = trxName;
+ }
+
+ @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();
+ m_Qty = Env.ONE;
+ m_isSOTrx = rmaLine.getM_RMA().isSOTrx();
+ this.trxName = trxName;
+ }
+}
diff --git a/org.adempiere.base/src/org/adempiere/base/Core.java b/org.adempiere.base/src/org/adempiere/base/Core.java
index 59c5a90c8e..a562fe6a28 100644
--- a/org.adempiere.base/src/org/adempiere/base/Core.java
+++ b/org.adempiere.base/src/org/adempiere/base/Core.java
@@ -450,4 +450,26 @@ public class Core {
return myPaymentExporter;
}
+
+ /**
+ * get ProductPricing instance
+ *
+ * @return instance of the IProductPricing or null
+ */
+ public static IProductPricing getProductPricing() {
+
+ List factoryList =
+ Service.locator().list(IProductPricingFactory.class).getServices();
+ if (factoryList != null) {
+ for(IProductPricingFactory factory : factoryList) {
+ IProductPricing myProductPricing = factory.newProductPricingInstance();
+ if (myProductPricing != null) {
+ return myProductPricing;
+ }
+ }
+ }
+
+ return null;
+ }
+
}
diff --git a/org.adempiere.base/src/org/adempiere/base/DefaultProductPricingFactory.java b/org.adempiere.base/src/org/adempiere/base/DefaultProductPricingFactory.java
new file mode 100644
index 0000000000..e8f87f618d
--- /dev/null
+++ b/org.adempiere.base/src/org/adempiere/base/DefaultProductPricingFactory.java
@@ -0,0 +1,18 @@
+package org.adempiere.base;
+
+import org.compiere.model.MProductPricing;
+
+public class DefaultProductPricingFactory implements IProductPricingFactory {
+
+ /**
+ * default constructor
+ */
+ public DefaultProductPricingFactory() {
+ }
+
+ @Override
+ public AbstractProductPricing newProductPricingInstance() {
+ return new MProductPricing();
+ }
+
+}
diff --git a/org.adempiere.base/src/org/adempiere/base/IProductPricing.java b/org.adempiere.base/src/org/adempiere/base/IProductPricing.java
new file mode 100644
index 0000000000..4487deabf2
--- /dev/null
+++ b/org.adempiere.base/src/org/adempiere/base/IProductPricing.java
@@ -0,0 +1,157 @@
+/******************************************************************************
+ * Copyright (C) 2017 Diego Ruiz *
+ * Copyright (C) 2017 Bx Service GmbH *
+ * This program is free software; you can redistribute it and/or modify it *
+ * under the terms version 2 of the GNU General Public License as published *
+ * by the Free Software Foundation. This program is distributed in the hope *
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU General Public License for more details. *
+ * You should have received a copy of the GNU General Public License along *
+ * with this program; if not, write to the Free Software Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
+ *****************************************************************************/
+package org.adempiere.base;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+
+import org.compiere.model.I_C_InvoiceLine;
+import org.compiere.model.I_C_OrderLine;
+import org.compiere.model.I_C_ProjectLine;
+import org.compiere.model.I_M_RMALine;
+import org.compiere.model.I_M_RequisitionLine;
+
+/**
+ * Product Price Calculations
+ */
+public interface IProductPricing {
+
+ /**
+ * Set the initial values that the old MProductPricing uses
+ * for backward compatibility
+ * @param M_Product_ID
+ * @param C_BPartner_ID
+ * @param qty
+ * @param isSOTrx
+ * @param trxName
+ */
+ void setInitialValues(int M_Product_ID, int C_BPartner_ID,
+ BigDecimal qty, boolean isSOTrx, String trxName);
+
+ /**
+ * Calculate Price
+ * @return true if calculated
+ */
+ boolean calculatePrice();
+
+ /**
+ * Calculate Discount Percentage
+ * @return Discount
+ */
+ BigDecimal getDiscount();
+
+ int getM_Product_ID();
+
+ int getM_PriceList_ID();
+
+ void setM_PriceList_ID(int M_PriceList_ID);
+
+ void setM_PriceList_Version_ID(int M_PriceList_Version_ID);
+
+ /**
+ * Get Price Date
+ * @return date
+ */
+ Timestamp getPriceDate();
+
+ /**
+ * Set Price Date
+ * @param priceDate date
+ */
+ void setPriceDate(Timestamp priceDate);
+
+ /**
+ * Get C_UOM_ID
+ * @return uom
+ */
+ int getC_UOM_ID();
+
+ /**
+ * Get Price List
+ * @return list
+ */
+ BigDecimal getPriceList();
+
+ /**
+ * Get Price Std
+ * @return std
+ */
+ BigDecimal getPriceStd();
+
+ /**
+ * Get Price Limit
+ * @return limit
+ */
+ BigDecimal getPriceLimit();
+
+ /**
+ * Get Price List Currency
+ * @return currency
+ */
+ int getC_Currency_ID();
+
+ /**
+ * Is Price List enforced?
+ * @return enforce limit
+ */
+ boolean isEnforcePriceLimit();
+
+ /**
+ * Is a DiscountSchema active?
+ * @return active Discount Schema
+ */
+ boolean isDiscountSchema();
+
+ /**
+ * Is the Price Calculated (i.e. found)?
+ * @return calculated
+ */
+ boolean isCalculated();
+
+ /**
+ * Set order line and calculate the parameters from it
+ * @param orderLine
+ * @param trxName
+ */
+ void setOrderLine(I_C_OrderLine orderLine, String trxName);
+
+ /**
+ * Set invoice line and calculate the parameters from it
+ * @param invoiceLine
+ * @param trxName
+ */
+ void setInvoiceLine(I_C_InvoiceLine invoiceLine, String trxName);
+
+ /**
+ * Set project line and calculate the parameters from it
+ * @param projectLine
+ * @param trxName
+ */
+ void setProjectLine(I_C_ProjectLine projectLine, String trxName);
+
+ /**
+ * Set requisition line and calculate the parameters from it
+ * @param reqLine
+ * @param trxName
+ */
+ void setRequisitionLine(I_M_RequisitionLine reqLine, String trxName);
+
+ /**
+ * Set rma line and calculate the parameters from it
+ * @param rmaLine
+ * @param trxName
+ */
+ void setRMALine(I_M_RMALine rmaLine, String trxName);
+
+}
diff --git a/org.adempiere.base/src/org/adempiere/base/IProductPricingFactory.java b/org.adempiere.base/src/org/adempiere/base/IProductPricingFactory.java
new file mode 100644
index 0000000000..846929a6c2
--- /dev/null
+++ b/org.adempiere.base/src/org/adempiere/base/IProductPricingFactory.java
@@ -0,0 +1,20 @@
+/******************************************************************************
+ * Copyright (C) 2017 Diego Ruiz *
+ * Copyright (C) 2017 Bx Service GmbH *
+ * This program is free software; you can redistribute it and/or modify it *
+ * under the terms version 2 of the GNU General Public License as published *
+ * by the Free Software Foundation. This program is distributed in the hope *
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU General Public License for more details. *
+ * You should have received a copy of the GNU General Public License along *
+ * with this program; if not, write to the Free Software Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
+ *****************************************************************************/
+package org.adempiere.base;
+
+public interface IProductPricingFactory {
+
+ public AbstractProductPricing newProductPricingInstance();
+
+}
diff --git a/org.adempiere.base/src/org/adempiere/exceptions/ProductNotOnPriceListException.java b/org.adempiere.base/src/org/adempiere/exceptions/ProductNotOnPriceListException.java
index c654354149..33fca3567b 100644
--- a/org.adempiere.base/src/org/adempiere/exceptions/ProductNotOnPriceListException.java
+++ b/org.adempiere.base/src/org/adempiere/exceptions/ProductNotOnPriceListException.java
@@ -15,9 +15,9 @@ package org.adempiere.exceptions;
import java.text.DateFormat;
+import org.adempiere.base.IProductPricing;
import org.compiere.model.MPriceList;
import org.compiere.model.MProduct;
-import org.compiere.model.MProductPricing;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@@ -36,12 +36,12 @@ public class ProductNotOnPriceListException extends AdempiereException
public static final String AD_Message = "ProductNotOnPriceList";
- public ProductNotOnPriceListException(MProductPricing productPricing, int documentLineNo)
+ public ProductNotOnPriceListException(IProductPricing productPricing, int documentLineNo)
{
super(buildMessage(productPricing, documentLineNo));
}
- private static final String buildMessage (MProductPricing pp, int documentLineNo)
+ private static final String buildMessage (IProductPricing pp, int documentLineNo)
{
StringBuilder sb = new StringBuilder();
if (documentLineNo > 0)
diff --git a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java
index e0a80eafb4..272995eb03 100644
--- a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java
+++ b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java
@@ -26,6 +26,7 @@ import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.model.ITaxProvider;
import org.compiere.util.CLogger;
@@ -177,7 +178,7 @@ public class MInvoiceLine extends X_C_InvoiceLine
/** Cached Precision */
private Integer m_precision = null;
/** Product Pricing */
- private MProductPricing m_productPricing = null;
+ private IProductPricing m_productPricing = null;
/** Parent */
private MInvoice m_parent = null;
@@ -378,10 +379,9 @@ public class MInvoiceLine extends X_C_InvoiceLine
return;
//
if (log.isLoggable(Level.FINE)) log.fine("M_PriceList_ID=" + M_PriceList_ID);
- m_productPricing = new MProductPricing (getM_Product_ID(),
- C_BPartner_ID, getQtyInvoiced(), m_IsSOTrx, get_TrxName());
+ m_productPricing = Core.getProductPricing();
+ m_productPricing.setInvoiceLine(this, get_TrxName());
m_productPricing.setM_PriceList_ID(M_PriceList_ID);
- m_productPricing.setPriceDate(m_DateInvoiced);
//
setPriceActual (m_productPricing.getPriceStd());
setPriceList (m_productPricing.getPriceList());
diff --git a/org.adempiere.base/src/org/compiere/model/MOrderLine.java b/org.adempiere.base/src/org/compiere/model/MOrderLine.java
index ffa04d4299..c4858e018a 100644
--- a/org.adempiere.base/src/org/compiere/model/MOrderLine.java
+++ b/org.adempiere.base/src/org/compiere/model/MOrderLine.java
@@ -23,6 +23,7 @@ import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.ProductNotOnPriceListException;
import org.adempiere.model.ITaxProvider;
@@ -196,7 +197,7 @@ public class MOrderLine extends X_C_OrderLine
//
protected boolean m_IsSOTrx = true;
// Product Pricing
- protected MProductPricing m_productPrice = null;
+ protected IProductPricing m_productPrice = null;
/** Tax */
protected MTax m_tax = null;
@@ -321,12 +322,11 @@ public class MOrderLine extends X_C_OrderLine
* @param M_PriceList_ID id
* @return product pricing
*/
- protected MProductPricing getProductPricing (int M_PriceList_ID)
+ protected IProductPricing getProductPricing (int M_PriceList_ID)
{
- m_productPrice = new MProductPricing (getM_Product_ID(),
- getC_BPartner_ID(), getQtyOrdered(), m_IsSOTrx, get_TrxName());
+ m_productPrice = Core.getProductPricing();
+ m_productPrice.setOrderLine(this, get_TrxName());
m_productPrice.setM_PriceList_ID(M_PriceList_ID);
- m_productPrice.setPriceDate(getDateOrdered());
//
m_productPrice.calculatePrice();
return m_productPrice;
diff --git a/org.adempiere.base/src/org/compiere/model/MProductPricing.java b/org.adempiere.base/src/org/compiere/model/MProductPricing.java
index b49cd5357e..c2a06912fa 100644
--- a/org.adempiere.base/src/org/compiere/model/MProductPricing.java
+++ b/org.adempiere.base/src/org/compiere/model/MProductPricing.java
@@ -22,6 +22,7 @@ import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.logging.Level;
+import org.adempiere.base.AbstractProductPricing;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
@@ -33,13 +34,19 @@ import org.compiere.util.Trace;
* @author Jorg Janke
* @version $Id: MProductPricing.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
*/
-public class MProductPricing
+public class MProductPricing extends AbstractProductPricing
{
private String trxName=null;
+
+ /**
+ * New constructor to be used with the ProductPriceFactories
+ */
+ public MProductPricing() {}
/**
- * Constructor
+ * Old Constructor to keep backward
+ * compatibility
* @param M_Product_ID product
* @param C_BPartner_ID partner
* @param Qty quantity
@@ -49,17 +56,7 @@ public class MProductPricing
public MProductPricing (int M_Product_ID, int C_BPartner_ID,
BigDecimal Qty, boolean isSOTrx, String trxName)
{
- this.trxName=trxName;
-
- m_M_Product_ID = M_Product_ID;
- m_C_BPartner_ID = C_BPartner_ID;
- if (Qty != null && Env.ZERO.compareTo(Qty) != 0)
- m_Qty = Qty;
- m_isSOTrx = isSOTrx;
- int thereAreVendorBreakRecords = DB.getSQLValue(trxName,
- "SELECT count(M_Product_ID) FROM M_ProductPriceVendorBreak WHERE M_Product_ID=? AND (C_BPartner_ID=? OR C_BPartner_ID is NULL)",
- m_M_Product_ID, m_C_BPartner_ID);
- m_useVendorBreak = thereAreVendorBreakRecords > 0;
+ setInitialValues(M_Product_ID, C_BPartner_ID, Qty, isSOTrx, trxName);
}
@@ -76,13 +73,20 @@ public class MProductPricing
{
this(M_Product_ID,C_BPartner_ID,Qty,isSOTrx,null);
} // MProductPricing
+
+ @Override
+ public void setInitialValues(int M_Product_ID, int C_BPartner_ID, BigDecimal qty, boolean isSOTrx, String trxName) {
+ super.setInitialValues(M_Product_ID, C_BPartner_ID, qty, isSOTrx, trxName);
+ checkVendorBreak();
+ }
+
+ private void checkVendorBreak() {
+ int thereAreVendorBreakRecords = DB.getSQLValue(trxName,
+ "SELECT count(M_Product_ID) FROM M_ProductPriceVendorBreak WHERE M_Product_ID=? AND (C_BPartner_ID=? OR C_BPartner_ID is NULL)",
+ m_M_Product_ID, m_C_BPartner_ID);
+ m_useVendorBreak = thereAreVendorBreakRecords > 0;
+ }
- private int m_M_Product_ID;
- private int m_C_BPartner_ID;
- private BigDecimal m_Qty = Env.ONE;
- private boolean m_isSOTrx = true;
- //
- private int m_M_PriceList_ID = 0;
private int m_M_PriceList_Version_ID = 0;
private Timestamp m_PriceDate;
/** Precision -1 = no rounding */
@@ -828,32 +832,13 @@ public class MProductPricing
-
- /**************************************************************************
- * Get Product ID
- * @return id
- */
- public int getM_Product_ID()
- {
- return m_M_Product_ID;
- }
-
- /**
- * Get PriceList ID
- * @return pl
- */
- public int getM_PriceList_ID()
- {
- return m_M_PriceList_ID;
- } // getM_PriceList_ID
-
/**
* Set PriceList
* @param M_PriceList_ID pl
*/
public void setM_PriceList_ID( int M_PriceList_ID)
{
- m_M_PriceList_ID = M_PriceList_ID;
+ super.setM_PriceList_ID(M_PriceList_ID);
m_calculated = false;
} // setM_PriceList_ID
@@ -872,26 +857,17 @@ public class MProductPricing
*/
public void setM_PriceList_Version_ID (int M_PriceList_Version_ID)
{
- m_M_PriceList_Version_ID = M_PriceList_Version_ID;
+ super.setM_PriceList_Version_ID(M_PriceList_Version_ID);
m_calculated = false;
} // setM_PriceList_Version_ID
- /**
- * Get Price Date
- * @return date
- */
- public Timestamp getPriceDate()
- {
- return m_PriceDate;
- } // getPriceDate
-
/**
* Set Price Date
* @param priceDate date
*/
public void setPriceDate(Timestamp priceDate)
{
- m_PriceDate = priceDate;
+ super.setPriceDate(priceDate);
m_calculated = false;
} // setPriceDate
@@ -1006,4 +982,34 @@ public class MProductPricing
return m_calculated;
} // isCalculated
+ @Override
+ public void setOrderLine(I_C_OrderLine orderLine, String trxName) {
+ super.setOrderLine(orderLine, trxName);
+ checkVendorBreak();
+ }
+
+ @Override
+ public void setInvoiceLine(I_C_InvoiceLine invoiceLine, String trxName) {
+ super.setInvoiceLine(invoiceLine, trxName);
+ checkVendorBreak();
+ }
+
+ @Override
+ public void setProjectLine(I_C_ProjectLine projectLine, String trxName) {
+ super.setProjectLine(projectLine, trxName);
+ checkVendorBreak();
+ }
+
+ @Override
+ public void setRequisitionLine(I_M_RequisitionLine reqLine, String trxName) {
+ super.setRequisitionLine(reqLine, trxName);
+ checkVendorBreak();
+ }
+
+ @Override
+ public void setRMALine(I_M_RMALine rmaLine, String trxName) {
+ super.setRMALine(rmaLine, trxName);
+ checkVendorBreak();
+ }
+
} // MProductPrice
diff --git a/org.adempiere.base/src/org/compiere/model/MProjectLine.java b/org.adempiere.base/src/org/compiere/model/MProjectLine.java
index 22f92c20fe..eb5cc11d91 100644
--- a/org.adempiere.base/src/org/compiere/model/MProjectLine.java
+++ b/org.adempiere.base/src/org/compiere/model/MProjectLine.java
@@ -21,6 +21,8 @@ import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
+import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.compiere.util.DB;
import org.compiere.util.Env;
@@ -146,9 +148,8 @@ public class MProjectLine extends X_C_ProjectLine
return limitPrice;
if (getProject() == null)
return limitPrice;
- boolean isSOTrx = true;
- MProductPricing pp = new MProductPricing (getM_Product_ID(),
- m_parent.getC_BPartner_ID(), getPlannedQty(), isSOTrx, get_TrxName());
+ IProductPricing pp = Core.getProductPricing();
+ pp.setProjectLine(this, get_TrxName());
pp.setM_PriceList_ID(m_parent.getM_PriceList_ID());
if (pp.calculatePrice())
limitPrice = pp.getPriceLimit();
diff --git a/org.adempiere.base/src/org/compiere/model/MRMALine.java b/org.adempiere.base/src/org/compiere/model/MRMALine.java
index 6e12609e16..4150085e01 100644
--- a/org.adempiere.base/src/org/compiere/model/MRMALine.java
+++ b/org.adempiere.base/src/org/compiere/model/MRMALine.java
@@ -22,6 +22,7 @@ import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.model.ITaxProvider;
import org.compiere.util.DB;
@@ -147,7 +148,8 @@ public class MRMALine extends X_M_RMALine
}
else if (getM_Product_ID() != 0)
{
- MProductPricing pp = new MProductPricing (getM_Product_ID(), getParent().getC_BPartner_ID(), Env.ONE, getParent().isSOTrx(), get_TrxName());
+ IProductPricing pp = Core.getProductPricing();
+ pp.setRMALine(this, get_TrxName());
MInvoice invoice = getParent().getOriginalInvoice();
if (invoice != null)
diff --git a/org.adempiere.base/src/org/compiere/model/MRequisitionLine.java b/org.adempiere.base/src/org/compiere/model/MRequisitionLine.java
index 322c82de36..b6449be440 100644
--- a/org.adempiere.base/src/org/compiere/model/MRequisitionLine.java
+++ b/org.adempiere.base/src/org/compiere/model/MRequisitionLine.java
@@ -23,6 +23,8 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
+import org.adempiere.base.Core;
+import org.adempiere.base.IProductPricing;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.util.DB;
import org.compiere.util.Env;
@@ -232,9 +234,8 @@ public class MRequisitionLine extends X_M_RequisitionLine
return;
//
if (log.isLoggable(Level.FINE)) log.fine("M_PriceList_ID=" + M_PriceList_ID);
- boolean isSOTrx = false;
- MProductPricing pp = new MProductPricing (getM_Product_ID(),
- getC_BPartner_ID(), getQty(), isSOTrx, get_TrxName());
+ IProductPricing pp = Core.getProductPricing();
+ pp.setRequisitionLine(this, get_TrxName());
pp.setM_PriceList_ID(M_PriceList_ID);
// pp.setPriceDate(getDateOrdered());
//