Fixes issue 23560: Insert Orphan Line when using Price List including taxes
authorPandeeswari Ramakrishnan <pandeeswari.ramakrishnan@openbravo.com>
Tue, 28 May 2013 16:08:36 +0530
changeset 20484 d31e48e598fb
parent 20483 14c8d925fdc6
child 20485 5e89abb03c8d
Fixes issue 23560: Insert Orphan Line when using Price List including taxes
src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Tue May 28 13:07:15 2013 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Tue May 28 16:08:36 2013 +0530
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2012 Openbravo SLU 
+ * All portions are Copyright (C) 2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -33,6 +33,8 @@
 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;
@@ -87,9 +89,14 @@
         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);
+          newOrderLine.setUnitPrice(newUnitPrice);
         }
       } else {
         BigDecimal unitPrice = new BigDecimal(strUnitPrice);
@@ -98,8 +105,13 @@
         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);
+          newOrderLine.setUnitPrice(newUnitPrice);
         }
       }
       // tax