details:   https://code.openbravo.com/erp/devel/pi/rev/92d905a6c013
changeset: 28062:92d905a6c013
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Thu Nov 26 17:08:45 2015 +0100
summary:   Fixes issue 31415: Valued Stock Report is not filtering by CR 
startingdate

The valued stock report was not taking into account the starting date of the 
costing rule.

diffstat:

 src/org/openbravo/erpCommon/ad_reports/ReportValuationStock.java      |  20 
+++++++++-
 src/org/openbravo/erpCommon/ad_reports/ReportValuationStock_data.xsql |   4 +-
 src/org/openbravo/erpCommon/utility/OBDateUtils.java                  |  19 
+++++++++-
 3 files changed, 40 insertions(+), 3 deletions(-)

diffs (114 lines):

diff -r 90a660b52e07 -r 92d905a6c013 
src/org/openbravo/erpCommon/ad_reports/ReportValuationStock.java
--- a/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock.java  Fri Nov 
27 10:48:02 2015 +0100
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock.java  Thu Nov 
26 17:08:45 2015 +0100
@@ -29,6 +29,7 @@
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.costing.CostingBackground;
 import org.openbravo.costing.CostingStatus;
+import org.openbravo.costing.CostingUtils;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
@@ -49,6 +50,7 @@
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.enterprise.Warehouse;
 import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.materialmgmt.cost.CostingRule;
 import org.openbravo.model.materialmgmt.transaction.MaterialTransaction;
 import org.openbravo.xmlEngine.XmlDocument;
 
@@ -119,13 +121,29 @@
         Organization legalEntity = OBContext.getOBContext()
             .getOrganizationStructureProvider(wh.getClient().getId())
             .getLegalEntity(wh.getOrganization());
+        String strDateFrom = DateTimeData.nDaysAfter(this, strDate, "1");
         if (legalEntity == null) {
           advise(request, response, "ERROR",
               Utility.messageBD(this, "WarehouseNotInLE", vars.getLanguage()), 
"");
+        } else {
+          try {
+            CostingRule costingRule = 
CostingUtils.getCostDimensionRule(legalEntity,
+                OBDateUtils.getDate(strDate));
+            strDateFrom = OBDateUtils.formatDateTime(CostingUtils
+                .getCostingRuleStartingDate(costingRule));
+          } catch (Exception exception) {
+            advise(
+                request,
+                response,
+                "ERROR",
+                Utility.messageBD(this, 
"NoCostingRuleFoundForOrganizationAndDate",
+                    vars.getLanguage()), "");
+          }
         }
         data = ReportValuationStockData.select(this, vars.getLanguage(), 
strCurrencyId,
             (legalEntity == null) ? null : legalEntity.getId(),
-            DateTimeData.nDaysAfter(this, strDate, "1"), strWarehouse, 
strCategoryProduct);
+            DateTimeData.nDaysAfter(this, strDate, "1"), strDateFrom, 
strWarehouse,
+            strCategoryProduct);
         boolean hasTrxWithNoCost = hasTrxWithNoCost(strDate, strWarehouse, 
strCategoryProduct);
         if (hasTrxWithNoCost) {
           OBError warning = new OBError();
diff -r 90a660b52e07 -r 92d905a6c013 
src/org/openbravo/erpCommon/ad_reports/ReportValuationStock_data.xsql
--- a/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock_data.xsql     
Fri Nov 27 10:48:02 2015 +0100
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock_data.xsql     
Thu Nov 26 17:08:45 2015 +0100
@@ -12,7 +12,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) 2001-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -51,6 +51,7 @@
                                 WHERE COALESCE(DATEACCT, COSTDATE) < to_date(?)
                                 GROUP BY m_transaction_id, C_CURRENCY_ID, 
COALESCE(DATEACCT, COSTDATE)) TC ON TRX.M_TRANSACTION_ID = TC.M_TRANSACTION_ID
                  WHERE TRX.MOVEMENTDATE < to_date(?)
+                 AND TRX.TRXPROCESSDATE > to_date(?)
                  AND L.M_WAREHOUSE_ID = ?
                  GROUP BY TRX.M_TRANSACTION_ID, TRX.M_PRODUCT_ID, 
TRX.C_UOM_ID, TRX.AD_CLIENT_ID, TRX.ISCOSTCALCULATED, TC.C_CURRENCY_ID, 
TC.MOVEMENTDATE) A ON TR.M_TRANSACTION_ID = A.M_TRANSACTION_ID,
                 C_UOM,
@@ -72,6 +73,7 @@
       <Parameter name="legalEntity"/>
       <Parameter name="datePlus"/>
       <Parameter name="datePlus"/>
+      <Parameter name="dateFrom"/>
       <Parameter name="warehouse"/>
       <Parameter name="categoryProduct" optional="true" after="AND   1 = 
1"><![CDATA[ AND M_PRODUCT.M_PRODUCT_CATEGORY_ID= ? ]]></Parameter>
   </SqlMethod>
diff -r 90a660b52e07 -r 92d905a6c013 
src/org/openbravo/erpCommon/utility/OBDateUtils.java
--- a/src/org/openbravo/erpCommon/utility/OBDateUtils.java      Fri Nov 27 
10:48:02 2015 +0100
+++ b/src/org/openbravo/erpCommon/utility/OBDateUtils.java      Thu Nov 26 
17:08:45 2015 +0100
@@ -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) 2012-2015 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -51,6 +51,23 @@
   }
 
   /**
+   * Returns an String with the date in the <i>dateTimeFormat.java</i> format 
defined in
+   * Openbravo.properties
+   * 
+   * @see OBDateUtils#formatDate(Date, String)
+   * 
+   * @param date
+   *          Date to be formatted.
+   * @return String formatted.
+   */
+  public static String formatDateTime(Date date) {
+    final String pattern = 
OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("dateTimeFormat.java");
+    final SimpleDateFormat dateFormatter = new SimpleDateFormat(pattern);
+    return dateFormatter.format(date);
+  }
+
+  /**
    * Returns an String with the date in the specified format
    * 
    * @param date

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to