Fixes Issue 0038558: Cannot add an orphan line in Return
authorAtul Gaware <atul.gaware@openbravo.com>
Wed, 16 May 2018 17:16:05 +0530
changeset 33967 59a5aec24377
parent 33966 a590572e37eb
child 33968 d0cc878c5657
Fixes Issue 0038558: Cannot add an orphan line in Return
From Customer window if the role does not have access to
Product window

Use setAdminMode prior to access product object in
insert RM orphan line process.
src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Wed May 16 23:01:26 2018 +0530
+++ b/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Wed May 16 17:16:05 2018 +0530
@@ -67,25 +67,26 @@
     final String strTaxId = (String) bundle.getParams().get("cTaxId");
     final String strReturnReason = (String) bundle.getParams().get("cReturnReasonId");
 
-    Order order = OBDal.getInstance().get(Order.class, strOrderId);
-    Product product = OBDal.getInstance().get(Product.class, strProductId);
-
-    if (!product.isReturnable()) {
-      throw new OBException("@Product@ '" + product.getIdentifier() + "' @ServiceIsNotReturnable@");
-    }
-    AttributeSetInstance attrSetInstance = null;
-    if (strAttributeSetInstanceId != null) {
-      attrSetInstance = OBDal.getInstance().get(AttributeSetInstance.class,
-          strAttributeSetInstanceId);
-    }
-    if (product.getAttributeSet() != null
-        && (strAttributeSetInstanceId == null || strAttributeSetInstanceId.equals(""))
-        && (product.getUseAttributeSetValueAs() == null || product.getUseAttributeSetValueAs() != "F")) {
-      throw new OBException("@productWithoutAttributeSet@");
-    }
-
     OBContext.setAdminMode(true);
     try {
+      Order order = OBDal.getInstance().get(Order.class, strOrderId);
+      Product product = OBDal.getInstance().get(Product.class, strProductId);
+
+      if (!product.isReturnable()) {
+        throw new OBException("@Product@ '" + product.getIdentifier()
+            + "' @ServiceIsNotReturnable@");
+      }
+      AttributeSetInstance attrSetInstance = null;
+      if (strAttributeSetInstanceId != null) {
+        attrSetInstance = OBDal.getInstance().get(AttributeSetInstance.class,
+            strAttributeSetInstanceId);
+      }
+      if (product.getAttributeSet() != null
+          && (strAttributeSetInstanceId == null || strAttributeSetInstanceId.equals(""))
+          && (product.getUseAttributeSetValueAs() == null || product.getUseAttributeSetValueAs() != "F")) {
+        throw new OBException("@productWithoutAttributeSet@");
+      }
+
       OrderLine newOrderLine = OBProvider.getInstance().get(OrderLine.class);
       newOrderLine.setSalesOrder(order);
       newOrderLine.setOrganization(order.getOrganization());