details:   https://code.openbravo.com/erp/devel/pi/rev/ade92a7ab29b
changeset: 17487:ade92a7ab29b
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Mon Jul 16 19:13:33 2012 +0200
summary:   Related to issue 21077.Adapt copy buttons to calculate discount.

details:   https://code.openbravo.com/erp/devel/pi/rev/5d5370eb46b5
changeset: 17488:5d5370eb46b5
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Mon Jul 16 19:13:51 2012 +0200
summary:   Related to issue 21077.Set gross price list in return orders.

details:   https://code.openbravo.com/erp/devel/pi/rev/70f3ddec1717
changeset: 17489:70f3ddec1717
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Mon Jul 16 19:18:56 2012 +0200
summary:   Fixed issue 21077.Fix net price list labels.

diffstat:

 src-db/database/sourcedata/AD_FIELD.xml                               |  16 +-
 src/org/openbravo/common/actionhandler/SRMOPickEditLines.java         |  12 +-
 src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java        |  32 
+++--
 src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql   |   5 +-
 src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java      |  53 
+++++----
 src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder_data.xsql |   5 +-
 6 files changed, 72 insertions(+), 51 deletions(-)

diffs (298 lines):

diff -r b08c32e4e264 -r 70f3ddec1717 src-db/database/sourcedata/AD_FIELD.xml
--- a/src-db/database/sourcedata/AD_FIELD.xml   Mon Jul 16 17:23:35 2012 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml   Mon Jul 16 19:18:56 2012 +0200
@@ -15568,10 +15568,10 @@
 <!--1137-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--1137-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--1137-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--1137-->  <NAME><![CDATA[List Price]]></NAME>
+<!--1137-->  <NAME><![CDATA[Net List Price]]></NAME>
 <!--1137-->  <DESCRIPTION><![CDATA[The official net price of a product in a 
specified currency.]]></DESCRIPTION>
 <!--1137-->  <HELP><![CDATA[The Net List Price is the official price stated by 
the selected pricelist and the currency of the document.]]></HELP>
-<!--1137-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--1137-->  <ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
 <!--1137-->  <AD_TAB_ID><![CDATA[187]]></AD_TAB_ID>
 <!--1137-->  <AD_COLUMN_ID><![CDATA[2231]]></AD_COLUMN_ID>
 <!--1137-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
@@ -43471,10 +43471,10 @@
 <!--3395-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--3395-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--3395-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--3395-->  <NAME><![CDATA[List Price]]></NAME>
+<!--3395-->  <NAME><![CDATA[Net List Price]]></NAME>
 <!--3395-->  <DESCRIPTION><![CDATA[The official net price of a product in a 
specified currency.]]></DESCRIPTION>
 <!--3395-->  <HELP><![CDATA[The Net List Price is the official price stated by 
the selected pricelist and the currency of the document.]]></HELP>
-<!--3395-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--3395-->  <ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
 <!--3395-->  <AD_TAB_ID><![CDATA[293]]></AD_TAB_ID>
 <!--3395-->  <AD_COLUMN_ID><![CDATA[2231]]></AD_COLUMN_ID>
 <!--3395-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
@@ -175078,10 +175078,10 @@
 <!--0554CE00C06447F2B33889030BC040E3-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--0554CE00C06447F2B33889030BC040E3-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--0554CE00C06447F2B33889030BC040E3-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--0554CE00C06447F2B33889030BC040E3-->  <NAME><![CDATA[List Price]]></NAME>
+<!--0554CE00C06447F2B33889030BC040E3-->  <NAME><![CDATA[Net List 
Price]]></NAME>
 <!--0554CE00C06447F2B33889030BC040E3-->  <DESCRIPTION><![CDATA[The official 
net price of a product in a specified currency.]]></DESCRIPTION>
 <!--0554CE00C06447F2B33889030BC040E3-->  <HELP><![CDATA[The Net List Price is 
the official price stated by the selected pricelist and the currency of the 
document.]]></HELP>
-<!--0554CE00C06447F2B33889030BC040E3-->  
<ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--0554CE00C06447F2B33889030BC040E3-->  
<ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
 <!--0554CE00C06447F2B33889030BC040E3-->  
<AD_TAB_ID><![CDATA[387B6179438D4C4CB40769A77F4C304C]]></AD_TAB_ID>
 <!--0554CE00C06447F2B33889030BC040E3-->  
<AD_COLUMN_ID><![CDATA[2231]]></AD_COLUMN_ID>
 <!--0554CE00C06447F2B33889030BC040E3-->  
<IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
@@ -218789,10 +218789,10 @@
 <!--AF4090093D4A1431E040007F010048A5-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--AF4090093D4A1431E040007F010048A5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--AF4090093D4A1431E040007F010048A5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--AF4090093D4A1431E040007F010048A5-->  <NAME><![CDATA[List Price]]></NAME>
+<!--AF4090093D4A1431E040007F010048A5-->  <NAME><![CDATA[Net List 
Price]]></NAME>
 <!--AF4090093D4A1431E040007F010048A5-->  <DESCRIPTION><![CDATA[The official 
net price of a product in a specified currency.]]></DESCRIPTION>
 <!--AF4090093D4A1431E040007F010048A5-->  <HELP><![CDATA[The Net List Price is 
the official price stated by the selected pricelist and the currency of the 
document.]]></HELP>
-<!--AF4090093D4A1431E040007F010048A5-->  
<ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--AF4090093D4A1431E040007F010048A5-->  
<ISCENTRALLYMAINTAINED><![CDATA[N]]></ISCENTRALLYMAINTAINED>
 <!--AF4090093D4A1431E040007F010048A5-->  
<AD_TAB_ID><![CDATA[AF4090093D471431E040007F010048A5]]></AD_TAB_ID>
 <!--AF4090093D4A1431E040007F010048A5-->  
<AD_COLUMN_ID><![CDATA[2231]]></AD_COLUMN_ID>
 <!--AF4090093D4A1431E040007F010048A5-->  
<IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
diff -r b08c32e4e264 -r 70f3ddec1717 
src/org/openbravo/common/actionhandler/SRMOPickEditLines.java
--- a/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java     Mon Jul 
16 17:23:35 2012 +0200
+++ b/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java     Mon Jul 
16 19:18:56 2012 +0200
@@ -190,8 +190,8 @@
       newOrderLine.setTax(tax);
 
       // Price
-      BigDecimal unitPrice, netPrice, grossPrice, stdPrice, limitPrice, 
listPrice, grossAmt;
-      grossPrice = grossAmt = stdPrice = BigDecimal.ZERO;
+      BigDecimal unitPrice, netPrice, grossPrice, stdPrice, limitPrice, 
listPrice, grossAmt, netListPrice, grossListPrice;
+      grossPrice = grossAmt = stdPrice = grossListPrice = BigDecimal.ZERO;
       final int pricePrecision = 
order.getCurrency().getPricePrecision().intValue();
       final int stdPrecision = 
order.getCurrency().getStandardPrecision().intValue();
 
@@ -224,13 +224,19 @@
             .setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
         netPrice = FinancialUtils.calculateNetFromGross(tax.getId(), grossAmt, 
pricePrecision,
             grossAmt, qtyReturned);
+        grossListPrice = listPrice;
+        limitPrice = netPrice;
+        stdPrice = netPrice;
+        netListPrice = netPrice;
       } else {
         netPrice = unitPrice;
+        netListPrice = listPrice;
       }
 
       newOrderLine.setUnitPrice(netPrice);
       newOrderLine.setGrossUnitPrice(grossPrice);
-      newOrderLine.setListPrice(listPrice);
+      newOrderLine.setListPrice(netListPrice);
+      newOrderLine.setGrossListPrice(grossListPrice);
       newOrderLine.setPriceLimit(limitPrice);
       newOrderLine.setStandardPrice(stdPrice);
       
newOrderLine.setLineNetAmount(netPrice.multiply(qtyReturned).setScale(stdPrecision,
diff -r b08c32e4e264 -r 70f3ddec1717 
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java    Mon Jul 
16 17:23:35 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java    Mon Jul 
16 19:18:56 2012 +0200
@@ -111,7 +111,7 @@
       CopyFromOrderRecordData[] orderData = 
CopyFromOrderRecordData.select(this, strKey);
       Order order = OBDal.getInstance().get(Order.class, strKey);
 
-      BigDecimal discount, priceActual, priceList, priceStd, priceLimit, 
priceGross, amtGross;
+      BigDecimal discount, priceActual, priceList, netPriceList, 
grossPriceList, priceStd, priceLimit, priceGross, amtGross;
       while (st.hasMoreTokens()) {
         String strRownum = st.nextToken().trim();
         String strmProductId = vars.getStringParameter("inpmProductId" + 
strRownum);
@@ -144,25 +144,33 @@
           amtGross = priceGross.multiply(qty).setScale(stdPrecision, 
BigDecimal.ROUND_HALF_UP);
           priceActual = FinancialUtils.calculateNetFromGross(strcTaxId, 
amtGross, pricePrecision,
               amtGross, qty);
+          priceLimit = priceActual;
+          netPriceList = priceActual;
+          grossPriceList = priceList;
         } else {
           priceActual = (strLastpriceso.equals("") ? ZERO : new 
BigDecimal(strLastpriceso));
+          netPriceList = priceList;
           priceGross = BigDecimal.ZERO;
           amtGross = BigDecimal.ZERO;
+          grossPriceList = BigDecimal.ZERO;
         }
 
-        if (priceList.compareTo(BigDecimal.ZERO) == 0 || 
order.getPriceList().isPriceIncludesTax()) {
+        if (priceList.compareTo(BigDecimal.ZERO) == 0) {
           discount = ZERO;
         } else {
-          log4j.debug("pricelist:" + Double.toString(priceList.doubleValue()));
-          log4j.debug("priceActual:" + 
Double.toString(priceActual.doubleValue()));
-          // (PL-PA)/PL * 100
-          discount = ((priceList.subtract(priceActual)).divide(priceList, 12,
-              BigDecimal.ROUND_HALF_EVEN)).multiply(new BigDecimal("100"));
+          log4j.debug("pricelist:" + priceList.toString());
+          log4j.debug("priceActual:" + priceActual.toString());
+          BigDecimal unitPrice;
+          if (order.getPriceList().isPriceIncludesTax()) {
+            unitPrice = priceGross;
+          } else {
+            unitPrice = priceActual;
+          }
+          // (PL-UP)/PL * 100
+          discount = ((priceList.subtract(unitPrice)).multiply(new 
BigDecimal("100")).divide(
+              priceList, stdPrecision, BigDecimal.ROUND_HALF_UP));
         }
         log4j.debug("Discount: " + discount.toString());
-        if (discount.scale() > stdPrecision) {
-          discount = discount.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
-        }
         if (priceStd.scale() > pricePrecision) {
           priceStd = priceStd.setScale(pricePrecision, 
BigDecimal.ROUND_HALF_UP);
         }
@@ -173,9 +181,9 @@
               orderData[0].cBpartnerLocationId, orderData[0].dateordered, 
orderData[0].dateordered,
               strmProductId, orderData[0].mWarehouseId.equals("") ? 
vars.getWarehouse()
                   : orderData[0].mWarehouseId, strcUOMId, strQty, 
orderData[0].cCurrencyId,
-              priceList.toString(), priceActual.toString(), 
priceLimit.toString(), priceStd
+              netPriceList.toString(), priceActual.toString(), 
priceLimit.toString(), priceStd
                   .toString(), discount.toString(), strcTaxId, 
strmAttributesetinstanceId,
-              priceGross.toString(), amtGross.toString());
+              grossPriceList.toString(), priceGross.toString(), 
amtGross.toString());
         } catch (ServletException ex) {
           myError = OBMessageUtils.translateError(this, vars, 
vars.getLanguage(), ex.getMessage());
           releaseRollbackConnection(conn);
diff -r b08c32e4e264 -r 70f3ddec1717 
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql       
Mon Jul 16 17:23:35 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql       
Mon Jul 16 19:18:56 2012 +0200
@@ -150,11 +150,11 @@
         INSERT INTO C_ORDERLINE (C_ORDERLINE_ID, AD_CLIENT_ID, AD_ORG_ID, 
CREATED, CREATEDBY, UPDATED, UPDATEDBY,
             C_ORDER_ID, LINE, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, 
DATEORDERED, DATEPROMISED, M_PRODUCT_ID, M_WAREHOUSE_ID, C_UOM_ID,
             QTYORDERED, C_CURRENCY_ID, PRICELIST, PRICEACTUAL, PRICELIMIT, 
PRICESTD, DISCOUNT, C_TAX_ID, M_ATTRIBUTESETINSTANCE_ID,
-            gross_unit_price, line_gross_amount
+            grosspricelist, gross_unit_price, line_gross_amount
         ) VALUES (?,?,?,NOW(),?,NOW(),?,
                 ?,(SELECT (coalesce(Max(Line),0))+10 FROM C_OrderLine WHERE 
C_Order_id = ?),?,?,TO_DATE(?),TO_DATE(?),?,?,?,
                 
TO_NUMBER(?),?,TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?),
 ?, ?,
-            TO_NUMBER(?), TO_NUMBER(?)
+            TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?)
         )
       ]]>
     </Sql>
@@ -181,6 +181,7 @@
     <Parameter name="discount"/>
     <Parameter name="cTaxId"/>
     <Parameter name="mAttributesetinstanceId"/>
+    <Parameter name="priceListGross"/>
     <Parameter name="priceGross"/>
     <Parameter name="amtGross"/>
   </SqlMethod>
diff -r b08c32e4e264 -r 70f3ddec1717 
src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java  Mon Jul 
16 17:23:35 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java  Mon Jul 
16 19:18:56 2012 +0200
@@ -87,6 +87,8 @@
     String strDiscount = "";
     String strGrossUnitPrice = "0";
     String strGrossAmount = "0";
+    String strNetPriceList = "0";
+    String strGrossPriceList = "0";
     Connection conn = null;
     try {
       conn = getTransactionConnection();
@@ -119,11 +121,8 @@
               discount = ZERO;
             } else {
               // ((PL-PA)/PL)*100
-              discount = ((priceList.subtract(priceActual)).divide(priceList, 
12,
-                  BigDecimal.ROUND_HALF_EVEN)).multiply(new BigDecimal("100"));
-            }
-            if (discount.scale() > stdPrecision) {
-              discount = discount.setScale(stdPrecision, 
BigDecimal.ROUND_HALF_UP);
+              discount = ((priceList.subtract(priceActual)).multiply(new 
BigDecimal("100")).divide(
+                  priceList, stdPrecision, BigDecimal.ROUND_HALF_UP));
             }
             strDiscount = discount.toString();
             strPriceActual = priceActual.toString();
@@ -165,10 +164,13 @@
           priceActual = FinancialUtils.calculateNetFromGross(strCTaxID, 
grossAmount,
               pricePrecision, grossAmount, qtyOrdered);
 
+          strGrossPriceList = strPriceList;
           strPriceActual = priceActual.toString();
-          strPriceList = priceActual.toString();
+          strNetPriceList = priceActual.toString();
           strPriceLimit = priceActual.toString();
           strGrossAmount = grossAmount.toString();
+        } else {
+          strNetPriceList = strPriceList;
         }
 
         int line = Integer.valueOf(orderData[0].line.equals("") ? "0" : 
orderData[0].line)
@@ -185,24 +187,27 @@
                 vars.getUser(), vars.getUser(), 
data[i].mAttributesetinstanceId);
             data[i].mAttributesetinstanceId = strMAttributesetinstanceID;
           }
-          CopyFromPOOrderData.insertCOrderline(
-              conn,
-              this,
-              strCOrderlineID,
-              orderData[0].adClientId,
-              orderData[0].adOrgId,
-              vars.getUser(),
-              strKey,
-              Integer.toString(line),
-              orderData[0].cBpartnerId,
-              orderData[0].cBpartnerLocationId.equals("") ? 
ExpenseSOrderData.cBPartnerLocationId(
-                  this, orderData[0].cBpartnerId) : 
orderData[0].cBpartnerLocationId,
-              orderData[0].dateordered, orderData[0].datepromised, 
data[i].description,
-              data[i].mProductId, orderData[0].mWarehouseId.equals("") ? 
vars.getWarehouse()
-                  : orderData[0].mWarehouseId, data[i].cUomId, 
data[i].qtyordered,
-              data[i].quantityorder, data[i].cCurrencyId, strPriceList, 
strPriceActual,
-              strPriceLimit, strCTaxID, strDiscount, data[i].mProductUomId, 
data[i].orderline,
-              data[i].mAttributesetinstanceId, strGrossUnitPrice, 
strGrossAmount);
+          CopyFromPOOrderData
+              .insertCOrderline(
+                  conn,
+                  this,
+                  strCOrderlineID,
+                  orderData[0].adClientId,
+                  orderData[0].adOrgId,
+                  vars.getUser(),
+                  strKey,
+                  Integer.toString(line),
+                  orderData[0].cBpartnerId,
+                  orderData[0].cBpartnerLocationId.equals("") ? 
ExpenseSOrderData
+                      .cBPartnerLocationId(this, orderData[0].cBpartnerId)
+                      : orderData[0].cBpartnerLocationId, 
orderData[0].dateordered,
+                  orderData[0].datepromised, data[i].description, 
data[i].mProductId,
+                  orderData[0].mWarehouseId.equals("") ? vars.getWarehouse()
+                      : orderData[0].mWarehouseId, data[i].cUomId, 
data[i].qtyordered,
+                  data[i].quantityorder, data[i].cCurrencyId, strNetPriceList, 
strPriceActual,
+                  strPriceLimit, strCTaxID, strDiscount, 
data[i].mProductUomId, data[i].orderline,
+                  data[i].mAttributesetinstanceId, strGrossPriceList, 
strGrossUnitPrice,
+                  strGrossAmount);
         } catch (ServletException ex) {
           myError = Utility.translateError(this, vars, vars.getLanguage(), 
ex.getMessage());
           releaseRollbackConnection(conn);
diff -r b08c32e4e264 -r 70f3ddec1717 
src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder_data.xsql
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder_data.xsql     
Mon Jul 16 17:23:35 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder_data.xsql     
Mon Jul 16 19:18:56 2012 +0200
@@ -62,7 +62,7 @@
         M_WAREHOUSE_ID, C_UOM_ID, QTYORDERED, QUANTITYORDER, QTYINVOICED, 
QTYDELIVERED, QTYRESERVED, 
         C_CURRENCY_ID, PRICELIST, PRICEACTUAL, 
         PRICELIMIT, C_TAX_ID, DISCOUNT, M_PRODUCT_UOM_ID, PRICESTD, 
M_OFFER_ID, REF_ORDERLINE_ID, M_ATTRIBUTESETINSTANCE_ID,
-          GROSS_UNIT_PRICE, LINE_GROSS_AMOUNT) 
+          GROSSPRICELIST, GROSS_UNIT_PRICE, LINE_GROSS_AMOUNT) 
         VALUES 
           (?,?,?,TO_DATE(NOW()),?,TO_DATE(NOW()),?,
            ?,TO_NUMBER(?),?,?,
@@ -70,7 +70,7 @@
            ?,?,TO_NUMBER(?),TO_NUMBER(?),0,0,0,
            ?,TO_NUMBER(?),M_GET_OFFERS_PRICE(TO_DATE(now()), ?, ?, 
TO_NUMBER(?), TO_NUMBER(?), ?),
            
TO_NUMBER(?),?,TO_NUMBER(?),?,TO_NUMBER(?),M_GET_OFFER(TO_DATE(now()), ?, 
?),?,?,
-           TO_NUMBER(?),TO_NUMBER(?))
+           TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?))
       ]]>
     </Sql>
     <Parameter name="cOrderlineId"/>
@@ -106,6 +106,7 @@
     <Parameter name="mProductId"/>
     <Parameter name="refOrdeline"/>
     <Parameter name="mAttributeSetInstanceId"/>
+    <Parameter name="grosslistprice"/>
     <Parameter name="grossprice"/>
     <Parameter name="grossAmount"/>
   </SqlMethod>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to