# HG changeset patch
# User Alvaro Ferraz <alvaro.ferraz@openbravo.com>
# Date 1470661005 -7200
#      Mon Aug 08 14:56:45 2016 +0200
# Node ID 08b363ab9b8c2d0ed0bbde5919b440099d8e8fc6
# Parent  3f38dea1af12c2d4368bae83de5cc67552422d13
Fixes issue 32265

diff --git a/src-db/database/model/functions/C_GET_NET_AMOUNT_FROM_GROSS.xml b/src-db/database/model/functions/C_GET_NET_AMOUNT_FROM_GROSS.xml
new file mode 100644
--- /dev/null
+++ b/src-db/database/model/functions/C_GET_NET_AMOUNT_FROM_GROSS.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0"?>
+  <database name="FUNCTION C_GET_NET_AMOUNT_FROM_GROSS">
+    <function name="C_GET_NET_AMOUNT_FROM_GROSS" type="NUMERIC">
+      <parameter name="p_tax_id" type="VARCHAR" mode="in">
+        <default/>
+      </parameter>
+      <parameter name="p_grossamt" type="NUMERIC" mode="in">
+        <default/>
+      </parameter>
+      <parameter name="p_alternatetaxbaseamt" type="NUMERIC" mode="in">
+        <default/>
+      </parameter>
+      <parameter name="p_stdprecision" type="NUMERIC" mode="in">
+        <default/>
+      </parameter>
+      <body><![CDATA[/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SLU
+* All portions are Copyright (C) 2015 Openbravo SLU
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+-- Logistice
+  v_ResultStr VARCHAR(2000):='';
+  v_message VARCHAR2(2000):='';
+  v_NetAmount NUMBER;
+  v_TaxAmount NUMBER;
+  v_calcPrecision NUMBER:=50;
+BEGIN --BODY
+  IF (p_grossamt = 0) THEN
+    RETURN 0;
+  END IF;
+  IF (p_stdprecision > 50) THEN
+    v_calcPrecision := p_stdprecision;
+  END IF;
+  v_TaxAmount := C_GET_TAX_AMT_FROM_NET(p_tax_id, p_grossamt, p_alternatetaxbaseamt, v_calcPrecision, 0);
+  DBMS_OUTPUT.PUT_LINE('Unit tax ' || v_TaxAmount);
+  v_NetAmount:= ROUND(p_grossamt * (p_grossamt  / (p_grossamt + v_TaxAmount)), p_stdprecision);
+
+  --TODO:Call function to recalculate alternate taxbase amount.
+
+  --TODO:If alternate taxbase amount is different recalculate line net amount c_tax_from_net_amt function.
+
+  RETURN v_NetAmount;
+
+EXCEPTION
+WHEN OTHERS THEN
+  v_ResultStr:= '@ERROR=' || SQLERRM;
+  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
+  RAISE;
+END C_GET_NET_AMOUNT_FROM_GROSS
+]]></body>
+    </function>
+  </database>
diff --git a/src-db/database/model/functions/C_INVOICE_POST.xml b/src-db/database/model/functions/C_INVOICE_POST.xml
--- a/src-db/database/model/functions/C_INVOICE_POST.xml
+++ b/src-db/database/model/functions/C_INVOICE_POST.xml
@@ -1236,7 +1236,7 @@
           ELSE
             v_line_gross_amount:=(-1) * Cur_TaxDiscount.LINEGROSSAMT * Cur_CInvoiceDiscount.Discount/100;
           END IF;
-          v_Discount:= C_GET_NET_PRICE_FROM_GROSS(Cur_TaxDiscount.C_TAX_ID, v_line_gross_amount, 0, v_precision, 1);
+          v_Discount:= 0;
           v_gross_unit_price:= v_line_gross_amount;
         ELSE
           IF (Cur_CInvoiceDiscount.CASCADE='Y') THEN
diff --git a/src-db/database/model/functions/C_ORDER_POST1.xml b/src-db/database/model/functions/C_ORDER_POST1.xml
--- a/src-db/database/model/functions/C_ORDER_POST1.xml
+++ b/src-db/database/model/functions/C_ORDER_POST1.xml
@@ -971,7 +971,8 @@
               ELSE
                 v_line_gross_amount:=(-1) * Cur_TaxDiscount.LINEGROSSAMT * Cur_COrderDiscount.Discount/100;
               END IF;
-              v_Discount:= C_GET_NET_PRICE_FROM_GROSS(Cur_TaxDiscount.C_TAX_ID, v_line_gross_amount, 0, v_precision, 1);
+              --TODO: ENSURE THIS PRECISION IS PRICE PRECISION. i WAS EXPECTING STD PRECISION
+              v_Discount:= C_GET_NET_AMOUNT_FROM_GROSS(Cur_TaxDiscount.C_TAX_ID, v_line_gross_amount, 0, v_precision);
               v_gross_unit_price:= v_line_gross_amount;
             ELSE
               IF (Cur_COrderDiscount.CASCADE='Y') THEN
diff --git a/src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml b/src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml
--- a/src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml
+++ b/src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml
@@ -143,9 +143,10 @@
         IF(v_IsTaxIncluded='Y') THEN
 					v_gross_unit_price:=M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID);
 					v_gross_price_list:=M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceList(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID);
+					--TODO: REVIEW PRECISION FOR GROSS AMOUNT
 					v_line_gross_amount:=ROUND(CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty*v_gross_unit_price, v_Precision);
-					v_price_actual:=ROUND(C_GET_NET_PRICE_FROM_GROSS(V_C_Tax_Id,  M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID), 0, v_Precision, 1),v_Precision);
-					v_line_net_amt:=ROUND(CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty*v_price_actual, v_Precision);
+					v_price_actual:=0;
+					v_line_net_amt:=0;
 				ELSE
 					v_gross_unit_price:=0;
 					v_line_gross_amount:=0;
diff --git a/src-db/database/model/functions/M_INOUT_CREATEINVOICE.xml b/src-db/database/model/functions/M_INOUT_CREATEINVOICE.xml
--- a/src-db/database/model/functions/M_INOUT_CREATEINVOICE.xml
+++ b/src-db/database/model/functions/M_INOUT_CREATEINVOICE.xml
@@ -318,7 +318,7 @@
                 v_grosspricestd:= v_PriceActual;
                 v_grosspricelist:= v_PriceList;
                 v_line_gross_amount:= ROUND(v_gross_unit_price * CUR_ShipmentLines.MovementQty, v_stdprecision);
-                v_PriceActual:= C_GET_NET_PRICE_FROM_GROSS(v_C_Tax_ID, v_PriceActual, 0, v_priceprecision, 1);
+                v_PriceActual:= 0;
                 v_PriceList:= C_GET_NET_PRICE_FROM_GROSS(v_C_Tax_ID, v_PriceList, 0, v_priceprecision, 1);
                 v_PriceLimit:= C_GET_NET_PRICE_FROM_GROSS(v_C_Tax_ID, v_PriceLimit, 0, v_priceprecision, 1);
                 v_LineNetAmt:= ROUND(v_PriceActual * CUR_ShipmentLines.MovementQty, v_stdprecision);
diff --git a/src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml b/src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml
--- a/src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml
+++ b/src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml
@@ -108,8 +108,8 @@
     v_newGrossAmt := round(v_newUnitPrice * v_qty, p_stdprecision);
     v_totalPromotion := v_origGrossAmt - v_newGrossAmt;
 
-    v_newNetPrice := c_get_net_price_from_gross(v_tax, v_newGrossAmt, v_newGrossAmt, p_priceprecision, v_qty);
-    v_newNetAmt := round(v_newNetPrice * v_qty, p_stdprecision);
+    v_newNetAmt := c_get_net_amount_from_gross(v_tax, v_newGrossAmt, v_newGrossAmt, p_stdprecision);
+    v_newNetPrice := round(v_newNetAmt / v_qty, p_priceprecision);
     v_basePrice := v_unitprice;
   else
     if (v_fixed is not null) then
diff --git a/src-db/database/model/functions/M_REQUISITION_CREATEPO.xml b/src-db/database/model/functions/M_REQUISITION_CREATEPO.xml
--- a/src-db/database/model/functions/M_REQUISITION_CREATEPO.xml
+++ b/src-db/database/model/functions/M_REQUISITION_CREATEPO.xml
@@ -256,8 +256,8 @@
       IF (Cur_Lines.istaxincluded = 'Y') THEN
         v_gross_unit_price:= v_Gross;
         v_line_gross_amount:= ROUND(v_gross_unit_price * (Cur_Lines.QTY - Cur_Lines.ORDEREDQTY), v_stdPre);
-        v_PriceActual:= C_GET_NET_PRICE_FROM_GROSS(v_Tax_ID, v_line_gross_amount, v_line_gross_amount, v_priPre, (Cur_Lines.QTY - Cur_Lines.ORDEREDQTY));
-        v_LineNetAmt:= ROUND(v_PriceActual * (Cur_Lines.QTY - Cur_Lines.ORDEREDQTY), v_stdPre);
+        v_PriceActual:= 0;
+        v_LineNetAmt:= 0;
         IF (v_PriceList = 0) THEN
           v_Discount := 0 ;
         ELSE
diff --git a/src-db/database/model/triggers/C_INVOICELINE_BEFORE_TRG.xml b/src-db/database/model/triggers/C_INVOICELINE_BEFORE_TRG.xml
--- a/src-db/database/model/triggers/C_INVOICELINE_BEFORE_TRG.xml
+++ b/src-db/database/model/triggers/C_INVOICELINE_BEFORE_TRG.xml
@@ -113,17 +113,14 @@
           ELSE -- The last willaccummulate rounding
             v_Line := v_BaseLine - v_LineAcum;
           END IF;
-
-          v_PriceLine := C_GET_NET_PRICE_FROM_GROSS(Cur_BOM.TAX, v_Line, v_Line, v_price_prec, :new.qtyinvoiced);
-          v_CalcLine := ROUND(:new.qtyinvoiced * v_PriceLine, v_std_Prec); -- In price including taxes the net and net alternate are equals.
-
+          v_CalcLine := C_GET_NET_AMOUNT_FROM_GROSS(Cur_BOM.TAX, v_Line, v_Line, v_std_Prec);
           v_NetActual := v_NetActual + v_CalcLine; -- Acum the net
         END LOOP;    
         v_PriceActual := v_NetActual / :new.qtyinvoiced;     
       ELSE
         -- Regular taxes
-        v_PriceActual := C_GET_NET_PRICE_FROM_GROSS(:new.c_tax_id, :new.gross_unit_price * :new.qtyinvoiced, :new.taxbaseamt, v_price_prec, :new.qtyinvoiced);
-        v_NetActual := ROUND(:new.Qtyinvoiced * v_PriceActual, v_std_Prec);
+        v_NetActual := C_GET_NET_AMOUNT_FROM_GROSS(:new.c_tax_id, :new.line_gross_amount, :new.line_gross_amount, v_std_Prec);
+        v_PriceActual := ROUND(v_NetActual / :new.Qtyinvoiced, v_price_prec);
       END IF;      
       
       :NEW.pricestd := v_priceactual;
diff --git a/src-db/database/model/triggers/C_INVOICELINE_TRG2.xml b/src-db/database/model/triggers/C_INVOICELINE_TRG2.xml
--- a/src-db/database/model/triggers/C_INVOICELINE_TRG2.xml
+++ b/src-db/database/model/triggers/C_INVOICELINE_TRG2.xml
@@ -168,8 +168,7 @@
           v_LineAlternate := v_BaseLineAlternate - v_LineAlternateAcum;
         END IF;
         IF (v_istaxincluded = 'Y') THEN
-          v_PriceLine := C_GET_NET_PRICE_FROM_GROSS(Cur_BOM.TAX, v_Line, v_LineAlternate, v_PricePrec, :new.qtyinvoiced);
-          v_CalcLine := ROUND(:new.qtyinvoiced * v_PriceLine, v_Prec); -- In price including taxes the net and net alternate are equals.
+          v_CalcLine := C_GET_NET_AMOUNT_FROM_GROSS(Cur_BOM.TAX, v_Line, v_LineAlternate, v_Prec);
           select coalesce(max(line), 0) into v_maxline from c_invoicelinetax where c_invoiceline_id = :new.C_InvoiceLine_ID;
           C_INVOICELINETAX_INSERT(:new.AD_Org_ID, :new.C_Invoice_ID, :new.C_InvoiceLine_ID, :new.UpdatedBy, Cur_BOM.TAX, Cur_BOM.TAX, v_CalcLine, v_CalcLine, v_Prec);
         ELSE
diff --git a/src-db/database/model/triggers/C_ORDERLINE_TRG.xml b/src-db/database/model/triggers/C_ORDERLINE_TRG.xml
--- a/src-db/database/model/triggers/C_ORDERLINE_TRG.xml
+++ b/src-db/database/model/triggers/C_ORDERLINE_TRG.xml
@@ -223,16 +223,14 @@
         ELSE -- The last willaccummulate rounding
           v_Line := v_BaseLine - v_LineAcum;
         END IF;
-
-        v_PriceLine := C_GET_NET_PRICE_FROM_GROSS(Cur_BOM.TAX, v_Line, v_Line, v_price_prec, :new.qtyordered);     
-        v_CalcLine := ROUND(:new.qtyordered * v_PriceLine, v_Prec); -- In price including taxes the net and net alternate are equals.
+        v_CalcLine := C_GET_NET_AMOUNT_FROM_GROSS(Cur_BOM.TAX, v_Line, v_Line, v_Prec);
         v_NetActual := v_NetActual + v_CalcLine; -- Acum the net
       END LOOP;    
       v_PriceActual := ROUND(v_NetActual / :new.qtyordered, v_price_prec);     
     ELSE
       -- Regular taxes
-      v_PriceActual := C_GET_NET_PRICE_FROM_GROSS(:new.c_tax_id, :new.gross_unit_price * :new.qtyordered, :new.taxbaseamt, v_price_prec, :new.qtyordered);
-      v_NetActual := ROUND(:new.QtyOrdered * v_PriceActual, v_Prec);
+      v_NetActual := C_GET_NET_AMOUNT_FROM_GROSS(:new.c_tax_id, :new.line_gross_amount, :new.taxbaseamt, v_Prec);
+      v_PriceActual := ROUND(v_NetActual / :NEW.qtyordered, v_price_prec);
     END IF;      
     
     :NEW.pricestd := v_priceactual;
diff --git a/src-db/database/model/triggers/C_ORDERLINE_TRG2.xml b/src-db/database/model/triggers/C_ORDERLINE_TRG2.xml
--- a/src-db/database/model/triggers/C_ORDERLINE_TRG2.xml
+++ b/src-db/database/model/triggers/C_ORDERLINE_TRG2.xml
@@ -179,8 +179,7 @@
           v_LineAlternate := v_BaseLineAlternate - v_LineAlternateAcum;
         END IF;
         IF (v_istaxincluded = 'Y') THEN
-          v_PriceLine := C_GET_NET_PRICE_FROM_GROSS(Cur_BOM.TAX, v_Line, v_LineAlternate, v_PricePrec, :new.qtyordered);
-          v_CalcLine := ROUND(:new.qtyordered * v_PriceLine, v_Prec); -- In price including taxes the net and net alternate are equals.
+          v_CalcLine := C_GET_NET_AMOUNT_FROM_GROSS(Cur_BOM.TAX, v_Line, v_LineAlternate, v_Prec);
           select coalesce(max(line), 0) into v_maxline from c_orderlinetax where c_orderline_id = :new.C_OrderLine_ID;
           C_ORDERLINETAX_INSERT(:new.AD_Org_ID, :new.C_Order_ID, :new.C_OrderLine_ID, :new.UpdatedBy, Cur_BOM.TAX, Cur_BOM.TAX, v_CalcLine, v_CalcLine, v_Prec);
         ELSE
diff --git a/src/org/openbravo/common/actionhandler/OrderCreatePOLines.java b/src/org/openbravo/common/actionhandler/OrderCreatePOLines.java
--- a/src/org/openbravo/common/actionhandler/OrderCreatePOLines.java
+++ b/src/org/openbravo/common/actionhandler/OrderCreatePOLines.java
@@ -36,7 +36,6 @@
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
-import org.openbravo.financial.FinancialUtils;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.order.OrderLine;
 import org.openbravo.model.common.plm.Product;
@@ -165,8 +164,9 @@
       if (order.getPriceList().isPriceIncludesTax()) {
         grossPrice = unitPrice;
         grossAmt = grossPrice.multiply(qtyOrdered).setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-        netPrice = FinancialUtils.calculateNetFromGross(tax.getId(), grossAmt, pricePrecision,
-            grossAmt, qtyOrdered);
+        // netPrice = FinancialUtils.calculateNetFromGross(tax.getId(), grossAmt, pricePrecision,
+        // grossAmt, qtyOrdered);
+        netPrice = BigDecimal.ZERO;
         limitPrice = netPrice;
         // selected line standard price is Gross Std Price in this case
         grossStdPrice = unitPrice;
diff --git a/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java b/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java
--- a/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java
+++ b/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java
@@ -254,8 +254,9 @@
         grossPrice = unitPrice;
         grossAmt = grossPrice.multiply(qtyReturned)
             .setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-        netPrice = FinancialUtils.calculateNetFromGross(tax.getId(), grossAmt, pricePrecision,
-            grossAmt, qtyReturned);
+        // netPrice = FinancialUtils.calculateNetFromGross(tax.getId(), grossAmt, pricePrecision,
+        // grossAmt, qtyReturned);
+        netPrice = BigDecimal.ZERO;
         limitPrice = netPrice;
         stdPrice = netPrice;
         netListPrice = netPrice;
diff --git a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice.java b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice.java
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice.java
@@ -160,8 +160,7 @@
                   priceGross = priceStd;
                   lineGrossAmt = priceGross.multiply(invLine.getInvoicedQuantity()).setScale(
                       stdPrecision, BigDecimal.ROUND_HALF_UP);
-                  priceActual = FinancialUtils.calculateNetFromGross(strCTaxID, lineGrossAmt,
-                      pricePrecision, lineGrossAmt, invLine.getInvoicedQuantity());
+                  priceActual = BigDecimal.ZERO;
                   ProductPrice prices = FinancialUtils.getProductPrice(
                       OBDal.getInstance().get(Product.class, strmProductId),
                       invoice.getInvoiceDate(), invoice.isSalesTransaction(),
diff --git a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java
@@ -165,8 +165,7 @@
           BigDecimal qty = new BigDecimal(strQty);
           priceGross = (strLastpriceso.equals("") ? ZERO : new BigDecimal(strLastpriceso));
           amtGross = priceGross.multiply(qty).setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-          priceActual = FinancialUtils.calculateNetFromGross(strcTaxId, amtGross, pricePrecision,
-              amtGross, qty);
+          priceActual = BigDecimal.ZERO;
           priceLimit = priceActual;
           netPriceList = priceActual;
           grossPriceList = priceList;
diff --git a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java
@@ -41,7 +41,6 @@
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.financial.FinancialUtils;
 import org.openbravo.model.ad.process.ProcessInstance;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.service.db.CallProcess;
@@ -184,8 +183,7 @@
             qtyOrdered = (data[i].qtyordered.equals("") ? ZERO : new BigDecimal(data[i].qtyordered));
             grossAmount = qtyOrdered.multiply(grossUnitPrice).setScale(stdPrecision,
                 BigDecimal.ROUND_HALF_UP);
-            priceActual = FinancialUtils.calculateNetFromGross(strCTaxID, grossAmount,
-                pricePrecision, grossAmount, qtyOrdered);
+            priceActual = BigDecimal.ZERO;
 
             strGrossPriceList = strPriceList;
             strPriceActual = priceActual.toString();
diff --git a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
@@ -45,7 +45,6 @@
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.financial.FinancialUtils;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.order.OrderLine;
 import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
@@ -1564,9 +1563,7 @@
                   priceGross = price[0].pricestd;
                   priceListGross = priceList;
                   priceStdGross = priceGross;
-                  BigDecimal grossAmount = new BigDecimal(priceGross).multiply(qty);
-                  final BigDecimal netUnitPrice = FinancialUtils.calculateNetFromGross(C_Tax_ID,
-                      grossAmount, curPrecision, grossAmount, qty);
+                  final BigDecimal netUnitPrice = BigDecimal.ZERO;
                   priceActual = netUnitPrice.toString();
                 }
               }
diff --git a/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java b/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java
+++ b/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java
@@ -33,8 +33,6 @@
 import org.openbravo.erpCommon.utility.OBDateUtils;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
-import org.openbravo.financial.FinancialUtils;
-import org.openbravo.model.common.currency.Currency;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.order.OrderLine;
 import org.openbravo.model.common.order.ReturnReason;
@@ -107,13 +105,10 @@
         newOrderLine.setPriceLimit(productPrice.getPriceLimit());
         newOrderLine.setStandardPrice(productPrice.getStandardPrice());
         if (order.getPriceList().isPriceIncludesTax()) {
-          Currency currency = OBDal.getInstance().get(Currency.class, order.getCurrency().getId());
           newOrderLine.setGrossUnitPrice(productPrice.getStandardPrice());
           newOrderLine.setLineGrossAmount(productPrice.getStandardPrice().multiply(returnedQty)
               .negate());
-          BigDecimal newUnitPrice = FinancialUtils.calculateNetFromGross(strTaxId,
-              productPrice.getStandardPrice(), currency.getPricePrecision().intValue(),
-              newOrderLine.getTaxableAmount(), returnedQty).multiply(returnedQty);
+          BigDecimal newUnitPrice = BigDecimal.ZERO;
           newOrderLine.setUnitPrice(newUnitPrice);
         }
       } else {
@@ -123,12 +118,9 @@
         newOrderLine.setPriceLimit(unitPrice);
         newOrderLine.setStandardPrice(unitPrice);
         if (order.getPriceList().isPriceIncludesTax()) {
-          Currency currency = OBDal.getInstance().get(Currency.class, order.getCurrency().getId());
           newOrderLine.setGrossUnitPrice(unitPrice);
           newOrderLine.setLineGrossAmount(unitPrice.multiply(returnedQty).negate());
-          BigDecimal newUnitPrice = FinancialUtils
-              .calculateNetFromGross(strTaxId, unitPrice, currency.getPricePrecision().intValue(),
-                  newOrderLine.getTaxableAmount(), returnedQty).multiply(returnedQty);
+          BigDecimal newUnitPrice = BigDecimal.ZERO;
           newOrderLine.setUnitPrice(newUnitPrice);
         }
       }
diff --git a/src/org/openbravo/erpCommon/ad_forms/RequisitionToOrder_data.xsql b/src/org/openbravo/erpCommon/ad_forms/RequisitionToOrder_data.xsql
--- a/src/org/openbravo/erpCommon/ad_forms/RequisitionToOrder_data.xsql
+++ b/src/org/openbravo/erpCommon/ad_forms/RequisitionToOrder_data.xsql
@@ -150,12 +150,7 @@
           COALESCE(M_PRODUCTPRICE.PRICELIST, M_REQUISITIONLINE.PRICELIST, LOCKPRICE) AS PRICELIST,
           COALESCE(M_PRODUCTPRICE.PRICELIMIT, LOCKPRICE) AS PRICELIMIT,
           COALESCE(M_PRODUCTPRICE.PRICESTD, LOCKPRICE) AS PRICESTD,
-          CASE WHEN M_Pricelist.istaxincluded = 'Y' then C_GET_NET_PRICE_FROM_GROSS(C_GetTax(M_REQUISITIONLINE.M_PRODUCT_ID, to_date(?), ?, ?, ?, ?, null, 'N'), 
-                                                                                    ROUND(COALESCE(LOCKPRICE, M_PRODUCTPRICE.PRICESTD) * LOCKQTY,
-                                                                                         (SELECT PRICEPRECISION FROM C_CURRENCY WHERE C_CURRENCY_ID = ?)) , 
-                                                                                    ROUND(COALESCE(LOCKPRICE, M_PRODUCTPRICE.PRICESTD) * LOCKQTY,
-                                                                                         (SELECT PRICEPRECISION FROM C_CURRENCY WHERE C_CURRENCY_ID = ?)), 
-                                                                                    (SELECT PRICEPRECISION FROM C_CURRENCY WHERE C_CURRENCY_ID = ?), LOCKQTY) 
+          CASE WHEN M_Pricelist.istaxincluded = 'Y' then 0 
                                                 ELSE ROUND(COALESCE(LOCKPRICE, M_PRODUCTPRICE.PRICESTD),(SELECT PRICEPRECISION FROM C_CURRENCY WHERE C_CURRENCY_ID = ?)) END AS PRICEACTUAL,
           CASE WHEN COALESCE(M_PRODUCTPRICE.PRICELIST, M_REQUISITIONLINE.PRICELIST, LOCKPRICE) = 0 THEN 0 ELSE
                     ROUND((COALESCE(M_PRODUCTPRICE.PRICELIST, M_REQUISITIONLINE.PRICELIST, LOCKPRICE) - COALESCE(LOCKPRICE, M_PRODUCTPRICE.PRICESTD))/
diff --git a/src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java b/src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java
--- a/src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java
+++ b/src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java
@@ -20,6 +20,7 @@
 package org.openbravo.erpCommon.ad_process;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -287,8 +288,10 @@
       if (objOrder.getPriceList().isPriceIncludesTax()) {
         // If is Price Including Taxes, change gross and then Net
         objCloneOrdLine.setGrossListPrice(bdPriceList);
-        objCloneOrdLine.setListPrice(getNetFromGross(bdPriceList, lineTax, objCloneOrder
-            .getCurrency().getPricePrecision(), objCloneOrdLine.getOrderedQuantity()));
+        BigDecimal netAmount = getNetFromGross(bdPriceList, lineTax, objCloneOrder.getCurrency()
+            .getStandardPrecision());
+        objCloneOrdLine.setListPrice(netAmount.divide(objCloneOrdLine.getOrderedQuantity(),
+            objCloneOrder.getCurrency().getPricePrecision().intValue(), RoundingMode.HALF_UP));
       } else {
         // If is not Price Including Taxes, change only net
         objCloneOrdLine.setListPrice(bdPriceList);
@@ -301,8 +304,9 @@
       if (objOrder.getPriceList().isPriceIncludesTax()) {
         // If is Price Including Taxes, change gross and then Net
         objCloneOrdLine.setGrossUnitPrice(bdPriceStd);
-        objCloneOrdLine.setUnitPrice(getNetFromGross(bdPriceStd, lineTax, objCloneOrder
-            .getCurrency().getPricePrecision(), BigDecimal.ONE));
+        BigDecimal netAmount = getNetFromGross(bdPriceStd, lineTax, objCloneOrder.getCurrency()
+            .getPricePrecision());
+        objCloneOrdLine.setUnitPrice(netAmount);
       } else {
         // If is not Price Including Taxes, change only net
         objCloneOrdLine.setUnitPrice(bdPriceStd);
@@ -433,7 +437,7 @@
       olDiscount.setGrossListPrice(discountedAmount.negate());
       BigDecimal net = getNetFromGross(discountedAmount,
           OBDal.getInstance().get(TaxRate.class, e.getKey()), objCloneOrder.getCurrency()
-              .getPricePrecision(), BigDecimal.ONE);
+              .getPricePrecision());
       olDiscount.setUnitPrice(net.negate());
       olDiscount.setLineNetAmount(net.negate());
       olDiscount.setListPrice(net.negate());
@@ -461,17 +465,15 @@
   /**
    * Call Database Procedure to calculate net price based on gross price
    */
-  private BigDecimal getNetFromGross(BigDecimal amount, TaxRate tax, Long pricePrecision,
-      BigDecimal quantity) {
+  private BigDecimal getNetFromGross(BigDecimal amount, TaxRate tax, Long stdPrecision) {
     BigDecimal netPrice = null;
     try {
       final List<Object> parameters = new ArrayList<Object>();
       parameters.add(tax.getId());
       parameters.add(amount);
       parameters.add(amount);
-      parameters.add(pricePrecision);
-      parameters.add(quantity);
-      final String procedureName = "c_get_net_price_from_gross";
+      parameters.add(stdPrecision);
+      final String procedureName = "c_get_net_amount_from_gross";
       netPrice = (BigDecimal) CallStoredProcedure.getInstance().call(procedureName, parameters,
           null);
     } catch (Exception e) {
