Fixes issue 20682, Fixes issue 20674: Insert Orphan Line.
authorMikel Irurita <mikel.irurita@openbravo.com>
Tue, 05 Jun 2012 18:50:02 +0200
changeset 16735 b11831000f7e
parent 16734 2496fa86d967
child 16736 bfe097444675
Fixes issue 20682, Fixes issue 20674: Insert Orphan Line.
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUISEL_SELECTOR.xml
src-db/database/model/views/M_RM_RECEIPT_PICK_EDIT.xml
src-db/database/sourcedata/AD_PROCESS_PARA.xml
src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java
src/org/openbravo/erpCommon/info/RMProductSelectorFilterExpression.java
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUISEL_SELECTOR.xml	Tue Jun 05 16:02:14 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/OBUISEL_SELECTOR.xml	Tue Jun 05 18:50:02 2012 +0200
@@ -127,6 +127,7 @@
 <!--FF808181312DA8D801312DDE869B000C-->  <AD_TABLE_ID><![CDATA[208]]></AD_TABLE_ID>
 <!--FF808181312DA8D801312DDE869B000C-->  <AD_COLUMN_ID><![CDATA[1402]]></AD_COLUMN_ID>
 <!--FF808181312DA8D801312DDE869B000C-->  <WHERECLAUSE><![CDATA[e.active='Y']]></WHERECLAUSE>
+<!--FF808181312DA8D801312DDE869B000C-->  <FILTER_EXPRESSION><![CDATA[OB.getFilterExpression("org.openbravo.erpCommon.info.RMProductSelectorFilterExpression")]]></FILTER_EXPRESSION>
 <!--FF808181312DA8D801312DDE869B000C-->  <OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID>
 <!--FF808181312DA8D801312DDE869B000C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF808181312DA8D801312DDE869B000C-->  <SUGGESTIONTEXTMATCHSTYLE><![CDATA[startsWith]]></SUGGESTIONTEXTMATCHSTYLE>
--- a/src-db/database/model/views/M_RM_RECEIPT_PICK_EDIT.xml	Tue Jun 05 16:02:14 2012 +0200
+++ b/src-db/database/model/views/M_RM_RECEIPT_PICK_EDIT.xml	Tue Jun 05 18:50:02 2012 +0200
@@ -7,7 +7,7 @@
 END AS ob_selected, ol.c_orderline_id, ol.m_product_id, ol.c_uom_id, ol.m_attributesetinstance_id, (-1) * ol.qtyordered AS returned, (-1) * (ol.qtyordered - ol.qtydelivered) AS pendingqty, (-1) * iol.movementqty AS receivingqty, iol.m_condition_goods_id, iol.m_locator_id, o.documentno AS returnorderno, o.issotrx, ol.line
 FROM c_orderline ol
 JOIN c_order o ON o.c_order_id = ol.c_order_id
-JOIN m_product p ON ol.m_product_id = p.m_product_id AND p.producttype = 'I'
+JOIN m_product p ON ol.m_product_id = p.m_product_id 
 JOIN c_doctype dt ON dt.c_doctype_id = o.c_doctypetarget_id AND dt.isreturn = 'Y'
 LEFT JOIN (SELECT il2.m_inoutline_id, il2.ad_client_id, il2.ad_org_id, il2.isactive, il2.created, il2.createdby, il2.updated, il2.updatedby, il2.line, il2.description, il2.m_inout_id, il2.c_orderline_id, il2.m_locator_id, il2.m_product_id, il2.c_uom_id, il2.movementqty, il2.isinvoiced, il2.m_attributesetinstance_id, il2.isdescription, il2.quantityorder, il2.m_product_uom_id, il2.m_condition_goods_id
 FROM m_inoutline il2
--- a/src-db/database/sourcedata/AD_PROCESS_PARA.xml	Tue Jun 05 16:02:14 2012 +0200
+++ b/src-db/database/sourcedata/AD_PROCESS_PARA.xml	Tue Jun 05 18:50:02 2012 +0200
@@ -4291,7 +4291,7 @@
 <!--97266E0DF6A24EC0BC6845B9E305F307-->  <COLUMNNAME><![CDATA[PriceStd]]></COLUMNNAME>
 <!--97266E0DF6A24EC0BC6845B9E305F307-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
 <!--97266E0DF6A24EC0BC6845B9E305F307-->  <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH>
-<!--97266E0DF6A24EC0BC6845B9E305F307-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--97266E0DF6A24EC0BC6845B9E305F307-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
 <!--97266E0DF6A24EC0BC6845B9E305F307-->  <ISRANGE><![CDATA[N]]></ISRANGE>
 <!--97266E0DF6A24EC0BC6845B9E305F307-->  <AD_ELEMENT_ID><![CDATA[957]]></AD_ELEMENT_ID>
 <!--97266E0DF6A24EC0BC6845B9E305F307--></AD_PROCESS_PARA>
@@ -4327,8 +4327,8 @@
 <!--A822BEFB7FB64D3C91F076748714CECE-->  <HELP><![CDATA[Identifies an item which is either purchased or sold in this organization.]]></HELP>
 <!--A822BEFB7FB64D3C91F076748714CECE-->  <AD_PROCESS_ID><![CDATA[23D1B163EC0B41F790CE39BF01DA320E]]></AD_PROCESS_ID>
 <!--A822BEFB7FB64D3C91F076748714CECE-->  <SEQNO><![CDATA[10]]></SEQNO>
-<!--A822BEFB7FB64D3C91F076748714CECE-->  <AD_REFERENCE_ID><![CDATA[30]]></AD_REFERENCE_ID>
-<!--A822BEFB7FB64D3C91F076748714CECE-->  <AD_REFERENCE_VALUE_ID><![CDATA[800060]]></AD_REFERENCE_VALUE_ID>
+<!--A822BEFB7FB64D3C91F076748714CECE-->  <AD_REFERENCE_ID><![CDATA[95E2A8B50A254B2AAE6774B8C2F28120]]></AD_REFERENCE_ID>
+<!--A822BEFB7FB64D3C91F076748714CECE-->  <AD_REFERENCE_VALUE_ID><![CDATA[FF808181312DA8D801312DDDAA750008]]></AD_REFERENCE_VALUE_ID>
 <!--A822BEFB7FB64D3C91F076748714CECE-->  <COLUMNNAME><![CDATA[M_Product_ID]]></COLUMNNAME>
 <!--A822BEFB7FB64D3C91F076748714CECE-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
 <!--A822BEFB7FB64D3C91F076748714CECE-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
--- a/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Tue Jun 05 16:02:14 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/RMInsertOrphanLine.java	Tue Jun 05 18:50:02 2012 +0200
@@ -27,11 +27,9 @@
 
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
-import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
-import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBDateUtils;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
@@ -50,12 +48,10 @@
 
 public class RMInsertOrphanLine implements org.openbravo.scheduling.Process {
 
+  final static String ITEM = "I";
+
   @Override
   public void execute(ProcessBundle bundle) throws Exception {
-    final String language = bundle.getContext().getLanguage();
-    final ConnectionProvider conProvider = bundle.getConnection();
-    final VariablesSecureApp vars = bundle.getContext().toVars();
-
     OBError msg = new OBError();
     msg.setType("Success");
     msg.setTitle(OBMessageUtils.messageBD("Success"));
@@ -72,31 +68,35 @@
     Order order = OBDal.getInstance().get(Order.class, strOrderId);
     Product product = OBDal.getInstance().get(Product.class, strProductId);
     AttributeSetInstance asi = null;
-    if (strASIId.isEmpty()) {
-      asi = OBDal.getInstance().get(AttributeSetInstance.class, "0");
-    } else {
-      asi = OBDal.getInstance().get(AttributeSetInstance.class, strASIId);
+    if (product.isStocked() && ITEM.equals(product.getProductType())) {
+      asi = OBDal.getInstance()
+          .get(AttributeSetInstance.class, strASIId.isEmpty() ? "0" : strASIId);
     }
 
-    // Check attributesetinstance has been used with the product
-    StringBuffer where = new StringBuffer();
-    where.append(" as trx");
-    where.append(" where trx." + MaterialTransaction.PROPERTY_PRODUCT + " = :product");
-    where.append("   and trx." + MaterialTransaction.PROPERTY_ATTRIBUTESETVALUE + " = :asi");
-    OBQuery<MaterialTransaction> attrQry = OBDal.getInstance().createQuery(
-        MaterialTransaction.class, where.toString());
-    attrQry.setNamedParameter("product", product);
-    attrQry.setNamedParameter("asi", asi);
-    if (attrQry.count() == 0) {
-      Map<String, String> parameters = new HashMap<String, String>();
-      parameters.put("product", product.getName());
-      parameters.put("attribute", asi.getDescription());
-      String message = OBMessageUtils.messageBD("WrongAttributeForProduct");
-      msg.setMessage(OBMessageUtils.parseTranslation(message, parameters));
-      msg.setTitle(OBMessageUtils.messageBD("Error"));
-      msg.setType("Error");
-      bundle.setResult(msg);
-      return;
+    if (asi != null) {
+      // Check attributesetinstance has been used with the product
+      StringBuffer where = new StringBuffer();
+      where.append(" as trx");
+      where.append(" where trx." + MaterialTransaction.PROPERTY_PRODUCT + " = :product");
+      where.append("   and trx." + MaterialTransaction.PROPERTY_ATTRIBUTESETVALUE + " = :asi");
+      OBQuery<MaterialTransaction> attrQry = OBDal.getInstance().createQuery(
+          MaterialTransaction.class, where.toString());
+      attrQry.setNamedParameter("product", product);
+      attrQry.setNamedParameter("asi", asi);
+      if (attrQry.count() == 0) {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("product", product.getName());
+        parameters.put("attribute", asi.getDescription());
+        String message = OBMessageUtils.messageBD("WrongAttributeForProduct");
+        msg.setMessage(OBMessageUtils.parseTranslation(message, parameters));
+        msg.setTitle(OBMessageUtils.messageBD("Error"));
+        msg.setType("Error");
+        bundle.setResult(msg);
+        return;
+      }
+      if ("0".equals(asi.getId())) {
+        asi = null;
+      }
     }
 
     OBContext.setAdminMode(true);
@@ -165,9 +165,9 @@
       newOrderLine.setTax(tax);
 
       if (strReturnReason.isEmpty()) {
+        newOrderLine.setReturnReason(order.getReturnReason());
+      } else {
         newOrderLine.setReturnReason(OBDal.getInstance().get(ReturnReason.class, strReturnReason));
-      } else {
-        newOrderLine.setReturnReason(order.getReturnReason());
       }
 
       List<OrderLine> orderLines = order.getOrderLineList();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/info/RMProductSelectorFilterExpression.java	Tue Jun 05 18:50:02 2012 +0200
@@ -0,0 +1,48 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * 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 Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.erpCommon.info;
+
+import java.util.Map;
+
+import org.openbravo.client.application.FilterExpression;
+import org.openbravo.client.kernel.RequestContext;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.erpCommon.utility.Utility;
+
+public class RMProductSelectorFilterExpression implements FilterExpression {
+
+  final static String RETURN_FROM_CUSTOMER_WINDOW = "FF808081330213E60133021822E40007";
+
+  @Override
+  public String getExpression(Map<String, String> requestMap) {
+    if (!RETURN_FROM_CUSTOMER_WINDOW.equals(requestMap.get("inpwindowId"))) {
+      return "";
+    }
+    StringBuilder whereClause = new StringBuilder();
+    String orgId = (String) RequestContext.get().getSession()
+        .getAttribute(RETURN_FROM_CUSTOMER_WINDOW + "|AD_ORG_ID");
+    String orgList = Utility.getInStrSet(OBContext.getOBContext()
+        .getOrganizationStructureProvider().getNaturalTree(orgId));
+    if (!orgList.isEmpty()) {
+      whereClause.append("e.organization.id in (" + orgList + ")");
+    }
+    return whereClause.toString();
+  }
+
+}