[Production-Development] fr2325: Select ProductCategory in CopyProduct
authorrafaeldemiguel <rdm@openbravo.com>
Fri, 28 Oct 2011 13:02:05 +0200
changeset 15008 ea1d55936701
parent 15007 63cdf762acb1
child 15009 ad291f0ab41d
[Production-Development] fr 2325: Select ProductCategory in CopyProduct
src-db/database/sourcedata/AD_PROCESS_PARA.xml
src-db/database/sourcedata/AD_VAL_RULE.xml
src/org/openbravo/erpCommon/ad_actionButton/SequenceProductCreate.java
--- a/src-db/database/sourcedata/AD_PROCESS_PARA.xml	Fri Oct 28 11:13:51 2011 +0200
+++ b/src-db/database/sourcedata/AD_PROCESS_PARA.xml	Fri Oct 28 13:02:05 2011 +0200
@@ -4544,4 +4544,21 @@
 <!--FF80818132813610013281789D2E0088-->  <AD_ELEMENT_ID><![CDATA[78D2DD1779FA4787B3C19558E2E65812]]></AD_ELEMENT_ID>
 <!--FF80818132813610013281789D2E0088--></AD_PROCESS_PARA>
 
+<!--FF8081813349BAC3013349D8EB61007D--><AD_PROCESS_PARA>
+<!--FF8081813349BAC3013349D8EB61007D-->  <AD_PROCESS_PARA_ID><![CDATA[FF8081813349BAC3013349D8EB61007D]]></AD_PROCESS_PARA_ID>
+<!--FF8081813349BAC3013349D8EB61007D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813349BAC3013349D8EB61007D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813349BAC3013349D8EB61007D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813349BAC3013349D8EB61007D-->  <NAME><![CDATA[Product Category]]></NAME>
+<!--FF8081813349BAC3013349D8EB61007D-->  <AD_PROCESS_ID><![CDATA[FF8081813219E68E013219ECFE930004]]></AD_PROCESS_ID>
+<!--FF8081813349BAC3013349D8EB61007D-->  <SEQNO><![CDATA[25]]></SEQNO>
+<!--FF8081813349BAC3013349D8EB61007D-->  <AD_REFERENCE_ID><![CDATA[19]]></AD_REFERENCE_ID>
+<!--FF8081813349BAC3013349D8EB61007D-->  <AD_VAL_RULE_ID><![CDATA[FF8081813349F4C801334A0741F40075]]></AD_VAL_RULE_ID>
+<!--FF8081813349BAC3013349D8EB61007D-->  <COLUMNNAME><![CDATA[M_Product_Category_ID]]></COLUMNNAME>
+<!--FF8081813349BAC3013349D8EB61007D-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--FF8081813349BAC3013349D8EB61007D-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
+<!--FF8081813349BAC3013349D8EB61007D-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--FF8081813349BAC3013349D8EB61007D-->  <ISRANGE><![CDATA[N]]></ISRANGE>
+<!--FF8081813349BAC3013349D8EB61007D--></AD_PROCESS_PARA>
+
 </data>
--- a/src-db/database/sourcedata/AD_VAL_RULE.xml	Fri Oct 28 11:13:51 2011 +0200
+++ b/src-db/database/sourcedata/AD_VAL_RULE.xml	Fri Oct 28 13:02:05 2011 +0200
@@ -1817,4 +1817,17 @@
 <!--FF808181321576F301321585D9BD0041-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--FF808181321576F301321585D9BD0041--></AD_VAL_RULE>
 
+<!--FF8081813349F4C801334A0741F40075--><AD_VAL_RULE>
+<!--FF8081813349F4C801334A0741F40075-->  <AD_VAL_RULE_ID><![CDATA[FF8081813349F4C801334A0741F40075]]></AD_VAL_RULE_ID>
+<!--FF8081813349F4C801334A0741F40075-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813349F4C801334A0741F40075-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813349F4C801334A0741F40075-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813349F4C801334A0741F40075-->  <NAME><![CDATA[M_Product_Category in Product Sequene Orgs]]></NAME>
+<!--FF8081813349F4C801334A0741F40075-->  <DESCRIPTION><![CDATA[M_Product_Category in Product Sequene Orgs]]></DESCRIPTION>
+<!--FF8081813349F4C801334A0741F40075-->  <TYPE><![CDATA[S]]></TYPE>
+<!--FF8081813349F4C801334A0741F40075-->  <CODE><![CDATA[AD_ISORGINCLUDED(M_Product_Category.ad_org_id, (SELECT M_PRODUCT.AD_ORG_ID FROM MA_SEQUENCEPRODUCT LEFT JOIN M_PRODUCT ON MA_SEQUENCEPRODUCT.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID WHERE MA_SEQUENCEPRODUCT_ID = @MA_SEQUENCEPRODUCT_ID@
+), M_Product_Category.ad_client_id)<>-1]]></CODE>
+<!--FF8081813349F4C801334A0741F40075-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--FF8081813349F4C801334A0741F40075--></AD_VAL_RULE>
+
 </data>
--- a/src/org/openbravo/erpCommon/ad_actionButton/SequenceProductCreate.java	Fri Oct 28 11:13:51 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/SequenceProductCreate.java	Fri Oct 28 13:02:05 2011 +0200
@@ -20,6 +20,7 @@
 
 import java.math.BigDecimal;
 
+import org.hibernate.Query;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.service.OBDal;
@@ -28,6 +29,7 @@
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.common.plm.AttributeUse;
 import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.plm.ProductCategory;
 import org.openbravo.model.manufacturing.processplan.OperationProduct;
 import org.openbravo.model.manufacturing.processplan.OperationProductAttribute;
 import org.openbravo.scheduling.Process;
@@ -50,6 +52,7 @@
       final String qty = (String) bundle.getParams().get("qty");
       final ConnectionProvider conn = bundle.getConnection();
       final String copyAttribute = (String) bundle.getParams().get("copyattribute");
+      final String productCategoryId = (String) bundle.getParams().get("mProductCategoryId");
 
       // Create new product copy of selected
       OperationProduct opProduct = OBDal.getInstance().get(OperationProduct.class,
@@ -66,6 +69,11 @@
       newProduct.setProductAccountsList(null);
       newProduct.setProductTrlList(null);
 
+      // Product Category
+      ProductCategory pcategory = OBDal.getInstance().get(ProductCategory.class, productCategoryId);
+      if (pcategory != null)
+        newProduct.setProductCategory(pcategory);
+
       // Save product
       OBDal.getInstance().save(newProduct);
 
@@ -78,6 +86,7 @@
       newOpProduct.setMASequence(opProduct.getMASequence());
       newOpProduct.setClient(opProduct.getClient());
       newOpProduct.setOrganization(opProduct.getOrganization());
+      newOpProduct.setLineNo(getLineNum(opProduct.getMASequence().getId()));
       newOpProduct.setProduct(newProduct);
       newOpProduct.setQuantity(new BigDecimal(qty));
       newOpProduct.setUOM(newProduct.getUOM());
@@ -161,4 +170,16 @@
 
   }
 
+  private static Long getLineNum(String SequenceId) throws Exception {
+    String hql = "  SELECT COALESCE(MAX(l.lineNo),0)+10 AS DefaultValue FROM ManufacturingOperationProduct l WHERE l.mASequence.id= '"
+        + SequenceId + "'";
+    Query q = OBDal.getInstance().getSession().createQuery(hql);
+
+    if (q.list().size() > 0) {
+      return new Long(q.list().get(0).toString());
+    } else {
+      return 0L;
+    }
+  }
+
 }