Fixed issue 34082
authorJorge Wederago <jorge.wederago@openbravo.com>
Wed, 14 Dec 2016 10:02:22 +0100
changeset 31460 1d69491419cc
parent 31181 e47c128a3513
child 31461 0927675f0e3f
Fixed issue 34082
Returnable services structure has been used to extend the functionality and have returnable products
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_ELEMENT.xml
src-db/database/sourcedata/AD_FIELD.xml
src-db/database/sourcedata/M_OFFER_TYPE.xml
src/org/openbravo/common/actionhandler/RFCServiceReturnableActionHandler.java
src/org/openbravo/common/actionhandler/SRMOPickEditLines.java
src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java
src/org/openbravo/materialmgmt/ServicePriceUtils.java
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Wed Dec 14 00:21:05 2016 +0100
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Wed Dec 14 10:02:22 2016 +0100
@@ -355751,8 +355751,8 @@
 <!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <NAME><![CDATA[Returnable]]></NAME>
-<!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <DESCRIPTION><![CDATA[Indicates is the Service is Returnable or not]]></DESCRIPTION>
-<!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <HELP><![CDATA[Indicates is the Service is Returnable or not]]></HELP>
+<!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <DESCRIPTION><![CDATA[Indicates if the Product is Returnable or not]]></DESCRIPTION>
+<!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <HELP><![CDATA[Indicates if the Product is Returnable or not]]></HELP>
 <!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <COLUMNNAME><![CDATA[Returnable]]></COLUMNNAME>
 <!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <AD_TABLE_ID><![CDATA[208]]></AD_TABLE_ID>
 <!--C93C575B07E74FAD8AAB0F49E6FDA907-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
--- a/src-db/database/sourcedata/AD_ELEMENT.xml	Wed Dec 14 00:21:05 2016 +0100
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml	Wed Dec 14 10:02:22 2016 +0100
@@ -22660,8 +22660,8 @@
 <!--3CB911FAA1D54CABB7A38AF0CC989151-->  <COLUMNNAME><![CDATA[Returnable]]></COLUMNNAME>
 <!--3CB911FAA1D54CABB7A38AF0CC989151-->  <NAME><![CDATA[Returnable]]></NAME>
 <!--3CB911FAA1D54CABB7A38AF0CC989151-->  <PRINTNAME><![CDATA[Returnable]]></PRINTNAME>
-<!--3CB911FAA1D54CABB7A38AF0CC989151-->  <DESCRIPTION><![CDATA[Indicates is the Service is Returnable or not]]></DESCRIPTION>
-<!--3CB911FAA1D54CABB7A38AF0CC989151-->  <HELP><![CDATA[Indicates is the Service is Returnable or not]]></HELP>
+<!--3CB911FAA1D54CABB7A38AF0CC989151-->  <DESCRIPTION><![CDATA[Indicates if the Product is Returnable or not]]></DESCRIPTION>
+<!--3CB911FAA1D54CABB7A38AF0CC989151-->  <HELP><![CDATA[Indicates if the Product is Returnable or not]]></HELP>
 <!--3CB911FAA1D54CABB7A38AF0CC989151-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--3CB911FAA1D54CABB7A38AF0CC989151-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--3CB911FAA1D54CABB7A38AF0CC989151--></AD_ELEMENT>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Wed Dec 14 00:21:05 2016 +0100
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Wed Dec 14 10:02:22 2016 +0100
@@ -212951,12 +212951,11 @@
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <AD_TAB_ID><![CDATA[180]]></AD_TAB_ID>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <AD_COLUMN_ID><![CDATA[5E02C5CF3E894313AE8EF4A35287843D]]></AD_COLUMN_ID>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
-<!--531A555CFD1F41DEBE871293A23DC9C6-->  <AD_FIELDGROUP_ID><![CDATA[AA044EC1D74D4F43A2C7CC7CE3246DC3]]></AD_FIELDGROUP_ID>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
-<!--531A555CFD1F41DEBE871293A23DC9C6-->  <DISPLAYLOGIC><![CDATA[@Returnable@='Y' & @ProductType@='S']]></DISPLAYLOGIC>
+<!--531A555CFD1F41DEBE871293A23DC9C6-->  <DISPLAYLOGIC><![CDATA[@Returnable@='Y' ]]></DISPLAYLOGIC>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <DISPLAYLENGTH><![CDATA[12]]></DISPLAYLENGTH>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--531A555CFD1F41DEBE871293A23DC9C6-->  <SEQNO><![CDATA[1270]]></SEQNO>
+<!--531A555CFD1F41DEBE871293A23DC9C6-->  <SEQNO><![CDATA[590]]></SEQNO>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--531A555CFD1F41DEBE871293A23DC9C6-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -230550,18 +230549,16 @@
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <NAME><![CDATA[Returnable]]></NAME>
-<!--6AB0D715CF1148F083F2E6C1964009C1-->  <DESCRIPTION><![CDATA[Indicates is the Service is Returnable or not]]></DESCRIPTION>
-<!--6AB0D715CF1148F083F2E6C1964009C1-->  <HELP><![CDATA[Indicates is the Service is Returnable or not]]></HELP>
+<!--6AB0D715CF1148F083F2E6C1964009C1-->  <DESCRIPTION><![CDATA[Indicates if the Product is Returnable or not]]></DESCRIPTION>
+<!--6AB0D715CF1148F083F2E6C1964009C1-->  <HELP><![CDATA[Indicates if the Product is Returnable or not]]></HELP>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <AD_TAB_ID><![CDATA[180]]></AD_TAB_ID>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <AD_COLUMN_ID><![CDATA[C93C575B07E74FAD8AAB0F49E6FDA907]]></AD_COLUMN_ID>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
-<!--6AB0D715CF1148F083F2E6C1964009C1-->  <AD_FIELDGROUP_ID><![CDATA[AA044EC1D74D4F43A2C7CC7CE3246DC3]]></AD_FIELDGROUP_ID>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
-<!--6AB0D715CF1148F083F2E6C1964009C1-->  <DISPLAYLOGIC><![CDATA[@ProductType@='S']]></DISPLAYLOGIC>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--6AB0D715CF1148F083F2E6C1964009C1-->  <SEQNO><![CDATA[1260]]></SEQNO>
+<!--6AB0D715CF1148F083F2E6C1964009C1-->  <SEQNO><![CDATA[580]]></SEQNO>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--6AB0D715CF1148F083F2E6C1964009C1-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
--- a/src-db/database/sourcedata/M_OFFER_TYPE.xml	Wed Dec 14 00:21:05 2016 +0100
+++ b/src-db/database/sourcedata/M_OFFER_TYPE.xml	Wed Dec 14 10:02:22 2016 +0100
@@ -8,6 +8,7 @@
 <!--5D4BAF6BB86D4D2C9ED3D5A6FC051579-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--5D4BAF6BB86D4D2C9ED3D5A6FC051579-->  <NAME><![CDATA[Price Adjustment]]></NAME>
 <!--5D4BAF6BB86D4D2C9ED3D5A6FC051579-->  <PL_ORDER_IMPLEMENTOR><![CDATA[M_Promotion_Adjustment]]></PL_ORDER_IMPLEMENTOR>
+<!--5D4BAF6BB86D4D2C9ED3D5A6FC051579-->  <EM_OBPOS_ISCATEGORY><![CDATA[N]]></EM_OBPOS_ISCATEGORY>
 <!--5D4BAF6BB86D4D2C9ED3D5A6FC051579--></M_OFFER_TYPE>
 
 </data>
--- a/src/org/openbravo/common/actionhandler/RFCServiceReturnableActionHandler.java	Wed Dec 14 00:21:05 2016 +0100
+++ b/src/org/openbravo/common/actionhandler/RFCServiceReturnableActionHandler.java	Wed Dec 14 10:02:22 2016 +0100
@@ -29,7 +29,7 @@
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.OBDateUtils;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
-import org.openbravo.materialmgmt.ServicePriceUtils;
+import org.openbravo.materialmgmt.ProductPriceUtils;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.materialmgmt.transaction.ShipmentInOutLine;
 import org.openbravo.service.db.DalConnectionProvider;
@@ -56,7 +56,7 @@
           jsonRequest.getString("goodsShipmentId"));
       final Product serviceProduct = OBDal.getInstance().get(Product.class,
           jsonRequest.getString("productId"));
-      JSONObject returnAllowedRFC = ServicePriceUtils.serviceReturnAllowedRFC(shipmentLine,
+      JSONObject returnAllowedRFC = ProductPriceUtils.productReturnAllowedRFC(shipmentLine,
           serviceProduct, rfcOrderDate);
       result.put("message", returnAllowedRFC);
     } catch (Exception e) {
--- a/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java	Wed Dec 14 00:21:05 2016 +0100
+++ b/src/org/openbravo/common/actionhandler/SRMOPickEditLines.java	Wed Dec 14 10:02:22 2016 +0100
@@ -143,8 +143,8 @@
       log.debug(selectedLine);
 
       Product product = OBDal.getInstance().get(Product.class, selectedLine.getString("product"));
-      if (SERVICEPRODUCT.equals(product.getProductType()) && !product.isReturnable()) {
-        throw new OBException("@Service@ '" + product.getIdentifier()
+      if (!product.isReturnable()) {
+        throw new OBException("@Product@ '" + product.getIdentifier()
             + "' @ServiceIsNotReturnable@");
       }
 
--- a/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Wed Dec 14 00:21:05 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Wed Dec 14 10:02:22 2016 +0100
@@ -71,8 +71,8 @@
     Order order = OBDal.getInstance().get(Order.class, strOrderId);
     Product product = OBDal.getInstance().get(Product.class, strProductId);
 
-    if (SERVICE.equals(product.getProductType()) && !product.isReturnable()) {
-      throw new OBException("@Service@ '" + product.getIdentifier() + "' @ServiceIsNotReturnable@");
+    if (!product.isReturnable()) {
+      throw new OBException("@Product@ '" + product.getIdentifier() + "' @ServiceIsNotReturnable@");
     }
     AttributeSetInstance attrSetInstance = null;
     if (strAttributeSetInstanceId != null) {
--- a/src/org/openbravo/materialmgmt/ServicePriceUtils.java	Wed Dec 14 00:21:05 2016 +0100
+++ b/src/org/openbravo/materialmgmt/ServicePriceUtils.java	Wed Dec 14 10:02:22 2016 +0100
@@ -52,13 +52,13 @@
 public class ServicePriceUtils {
   private static final Logger log = LoggerFactory.getLogger(ServicePriceUtils.class);
   private static final String PERCENTAGE = "P";
-  private static String SERVICEPRODUCT = "S";
   public static final String UNIQUE_QUANTITY = "UQ";
 
   /**
    * Method to obtain Service Amount to be added for a certain service order line based on selected
    * product lines amount
    */
+
   public static BigDecimal getServiceAmount(OrderLine orderline, BigDecimal linesTotalAmount,
       BigDecimal totalDiscounts, BigDecimal totalPrice, BigDecimal relatedQty,
       BigDecimal unitDiscountsAmt) {
@@ -371,55 +371,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
   public static JSONObject serviceReturnAllowedRFC(ShipmentInOutLine shipmentLine,
       Product serviceProduct, Date rfcOrderDate) {
-    JSONObject result = null;
-    OBContext.setAdminMode(true);
-    try {
-      if (SERVICEPRODUCT.equals(serviceProduct.getProductType())) {
-        if (!serviceProduct.isReturnable()) {
-          throw new OBException("@Service@ '" + serviceProduct.getIdentifier()
-              + "' @ServiceIsNotReturnable@");
-        } else {
-          try {
-            final Date orderDate = shipmentLine != null && shipmentLine.getSalesOrderLine() != null ? OBDateUtils
-                .getDate(OBDateUtils.formatDate(shipmentLine.getSalesOrderLine().getOrderDate()))
-                : null;
-            Date returnDate = null;
-            String message = null;
-            if (orderDate != null && serviceProduct.getOverdueReturnDays() != null) {
-              returnDate = DateUtils.addDays(orderDate, serviceProduct.getOverdueReturnDays()
-                  .intValue());
-            }
-            if (serviceProduct.getOverdueReturnDays() != null && returnDate != null
-                && rfcOrderDate.after(returnDate)) {
-              message = "@Service@ '" + serviceProduct.getIdentifier()
-                  + "' @ServiceReturnExpired@: " + OBDateUtils.formatDate(returnDate);
-            }
-            if (serviceProduct.getOverdueReturnDays() != null && returnDate == null) {
-              message = "@Service@ '" + serviceProduct.getIdentifier()
-                  + "' @ServiceMissingReturnDate@";
-            }
-            if (message != null) {
-              message = OBMessageUtils.parseTranslation(new DalConnectionProvider(false),
-                  RequestContext.get().getVariablesSecureApp(), OBContext.getOBContext()
-                      .getLanguage().getLanguage(), message);
-              result = new JSONObject();
-              result.put("severity", "warning");
-              result.put("title", "Warning");
-              result.put("text", message);
-            }
-          } catch (ParseException e) {
-            log.error(e.getMessage(), e);
-          } catch (JSONException e) {
-            log.error(e.getMessage(), e);
-          }
-        }
-      }
-      return result;
-    } finally {
-      OBContext.restorePreviousMode();
-    }
+    return ProductPriceUtils.productReturnAllowedRFC(shipmentLine, serviceProduct, rfcOrderDate);
   }
 
   /**