Related to issue 34082: Code review improvements
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Mon, 09 Jan 2017 12:03:41 +0100
changeset 31465 5b5b3b81aa12
parent 31464 cf3304e1282d
child 31466 5b206910eb99
Related to issue 34082: Code review improvements

N1: Renamed serviceProduct --> product
C6: Javadoc for new method now describes products (and not only services)
C6: Javadoc for old method now points to the new one
G35: Order Date is truncated to day of month instead of formatting and then getting the date
src/org/openbravo/materialmgmt/ProductPriceUtils.java
src/org/openbravo/materialmgmt/ServicePriceUtils.java
--- a/src/org/openbravo/materialmgmt/ProductPriceUtils.java	Thu Jan 05 15:01:44 2017 +0100
+++ b/src/org/openbravo/materialmgmt/ProductPriceUtils.java	Mon Jan 09 12:03:41 2017 +0100
@@ -9,7 +9,7 @@
 
 package org.openbravo.materialmgmt;
 
-import java.text.ParseException;
+import java.util.Calendar;
 import java.util.Date;
 
 import org.apache.commons.lang.time.DateUtils;
@@ -31,37 +31,34 @@
   private static final Logger log = LoggerFactory.getLogger(ProductPriceUtils.class);
 
   /**
-   * Method that returns a warning message if a service of a Return From Customer is not Returnable
-   * of the return period is expired.
+   * Returns a warning message when a Return From Customer product is not Returnable or when the
+   * return period is expired.
    */
-
-  public static JSONObject productReturnAllowedRFC(ShipmentInOutLine shipmentLine,
-      Product serviceProduct, Date rfcOrderDate) {
+  public static JSONObject productReturnAllowedRFC(ShipmentInOutLine shipmentLine, Product product,
+      Date rfcOrderDate) {
     JSONObject result = null;
     OBContext.setAdminMode(true);
     try {
-      if (!serviceProduct.isReturnable()) {
-        throw new OBException("@Product@ '" + serviceProduct.getIdentifier()
+      if (!product.isReturnable()) {
+        throw new OBException("@Product@ '" + product.getIdentifier()
             + "' @ServiceIsNotReturnable@");
       } else {
         try {
-          final Date orderDate = shipmentLine != null && shipmentLine.getSalesOrderLine() != null ? OBDateUtils
-              .getDate(OBDateUtils.formatDate(shipmentLine.getSalesOrderLine().getOrderDate()))
+          final Date orderDate = shipmentLine != null && shipmentLine.getSalesOrderLine() != null ? DateUtils
+              .truncate(shipmentLine.getSalesOrderLine().getOrderDate(), Calendar.DAY_OF_MONTH)
               : null;
           Date returnDate = null;
           String message = null;
-          if (orderDate != null && serviceProduct.getOverdueReturnDays() != null) {
-            returnDate = DateUtils.addDays(orderDate, serviceProduct.getOverdueReturnDays()
-                .intValue());
+          if (orderDate != null && product.getOverdueReturnDays() != null) {
+            returnDate = DateUtils.addDays(orderDate, product.getOverdueReturnDays().intValue());
           }
-          if (serviceProduct.getOverdueReturnDays() != null && returnDate != null
+          if (product.getOverdueReturnDays() != null && returnDate != null
               && rfcOrderDate.after(returnDate)) {
-            message = "@Product@ '" + serviceProduct.getIdentifier() + "' @ServiceReturnExpired@: "
+            message = "@Product@ '" + product.getIdentifier() + "' @ServiceReturnExpired@: "
                 + OBDateUtils.formatDate(returnDate);
           }
-          if (serviceProduct.getOverdueReturnDays() != null && returnDate == null) {
-            message = "@Product@ '" + serviceProduct.getIdentifier()
-                + "' @ServiceMissingReturnDate@";
+          if (product.getOverdueReturnDays() != null && returnDate == null) {
+            message = "@Product@ '" + product.getIdentifier() + "' @ServiceMissingReturnDate@";
           }
           if (message != null) {
             message = OBMessageUtils.parseTranslation(new DalConnectionProvider(false),
@@ -72,8 +69,6 @@
             result.put("title", "Warning");
             result.put("text", message);
           }
-        } catch (ParseException e) {
-          log.error(e.getMessage(), e);
         } catch (JSONException e) {
           log.error(e.getMessage(), e);
         }
--- a/src/org/openbravo/materialmgmt/ServicePriceUtils.java	Thu Jan 05 15:01:44 2017 +0100
+++ b/src/org/openbravo/materialmgmt/ServicePriceUtils.java	Mon Jan 09 12:03:41 2017 +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) 2015-2016 Openbravo SLU 
+ * All portions are Copyright (C) 2015-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -370,8 +370,10 @@
   /**
    * Method that returns a warning message if a service of a Return From Customer is not Returnable
    * of the return period is expired.
+   * 
+   * @deprecated Use
+   *             {@link ProductPriceUtils#productReturnAllowedRFC(ShipmentInOutLine, Product, Date)}
    */
-  @Deprecated
   public static JSONObject serviceReturnAllowedRFC(ShipmentInOutLine shipmentLine,
       Product serviceProduct, Date rfcOrderDate) {
     return ProductPriceUtils.productReturnAllowedRFC(shipmentLine, serviceProduct, rfcOrderDate);