diff --git a/base/src/org/compiere/acct/Doc_InOut.java b/base/src/org/compiere/acct/Doc_InOut.java
index 6b292582a0..b6dd054009 100644
--- a/base/src/org/compiere/acct/Doc_InOut.java
+++ b/base/src/org/compiere/acct/Doc_InOut.java
@@ -21,6 +21,8 @@ import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.logging.Level;
+import org.compiere.model.MTax;
+import org.compiere.model.MCurrency;
import org.compiere.model.MAccount;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MCostDetail;
@@ -41,6 +43,7 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @author Armen Rizal, Goodwill Consulting
*
BF [ 1745154 ] Cost in Reversing Material Related Docs
+ * BF [ 2858043 ] Correct Included Tax in Average Costing
* @version $Id: Doc_InOut.java,v 1.3 2006/07/30 00:53:33 jjanke Exp $
*/
public class Doc_InOut extends Doc
@@ -364,13 +367,28 @@ public class Doc_InOut extends Doc
if (C_OrderLine_ID > 0)
{
MOrderLine orderLine = new MOrderLine (getCtx(), C_OrderLine_ID, getTrxName());
- costs = orderLine.getPriceCost();
- if (costs == null || costs.signum() == 0)
- costs = orderLine.getPriceActual();
- costs = costs.multiply(line.getQty());
// Elaine 2008/06/26
C_Currency_ID = orderLine.getC_Currency_ID();
//
+ costs = orderLine.getPriceCost();
+ if (costs == null || costs.signum() == 0)
+ {
+ costs = orderLine.getPriceActual();
+ // Goodwill: Correct included Tax
+ int C_Tax_ID = orderLine.getC_Tax_ID();
+ if (orderLine.isTaxIncluded() && C_Tax_ID != 0)
+ {
+ MTax tax = MTax.get(getCtx(), C_Tax_ID);
+ if (!tax.isZeroTax())
+ {
+ int stdPrecision = MCurrency.getStdPrecision(getCtx(), C_Currency_ID);
+ BigDecimal costTax = tax.calculateTax(costs, true, stdPrecision);
+ log.fine("Costs=" + costs + " - Tax=" + costTax);
+ costs = costs.subtract(costTax);
+ }
+ } // correct included Tax
+ }
+ costs = costs.multiply(line.getQty());
}
else
{
diff --git a/base/src/org/compiere/model/MMatchPO.java b/base/src/org/compiere/model/MMatchPO.java
index 76b4edb764..b3ea1c4257 100644
--- a/base/src/org/compiere/model/MMatchPO.java
+++ b/base/src/org/compiere/model/MMatchPO.java
@@ -46,6 +46,7 @@ import org.compiere.util.Env;
*
* @author Armen Rizal, Goodwill Consulting
* BF [ 2215840 ] MatchPO Bug Collection
+ * BF [ 2858043 ] Correct Included Tax in Average Costing
*
* @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com
* FR [ 2520591 ] Support multiples calendar for Org
@@ -874,7 +875,22 @@ public class MMatchPO extends X_M_MatchPO
// Purchase Order Line
BigDecimal poCost = oLine.getPriceCost();
if (poCost == null || poCost.signum() == 0)
+ {
poCost = oLine.getPriceActual();
+ // Goodwill: Correct included Tax
+ int C_Tax_ID = oLine.getC_Tax_ID();
+ if (oLine.isTaxIncluded() && C_Tax_ID != 0)
+ {
+ MTax tax = MTax.get(getCtx(), C_Tax_ID);
+ if (!tax.isZeroTax())
+ {
+ int stdPrecision = MCurrency.getStdPrecision(getCtx(), oLine.getC_Currency_ID());
+ BigDecimal costTax = tax.calculateTax(poCost, true, stdPrecision);
+ log.fine("Costs=" + poCost + " - Tax=" + costTax);
+ poCost = poCost.subtract(costTax);
+ }
+ } // correct included Tax
+ }
// Source from Doc_MatchPO.createFacts(MAcctSchema)
MInOutLine receiptLine = new MInOutLine (getCtx(), getM_InOutLine_ID(), get_TrxName());