[Production-Development] Copy Attribute From in Sequence Product Create
authorrafaeldemiguel <rdm@openbravo.com>
Mon, 19 Sep 2011 19:12:18 +0200
changeset 14982 0efd2107a1a5
parent 14981 d60d2439880f
child 14983 fcf3ccf492f3
[Production-Development] Copy Attribute From in Sequence Product Create
src-db/database/sourcedata/AD_PROCESS_PARA.xml
src/org/openbravo/erpCommon/ad_actionButton/SequenceProductCreate.java
src/org/openbravo/erpCommon/ad_callouts/SL_SequenceProduct_Product_Attribute.java
--- a/src-db/database/sourcedata/AD_PROCESS_PARA.xml	Mon Sep 19 12:50:06 2011 +0200
+++ b/src-db/database/sourcedata/AD_PROCESS_PARA.xml	Mon Sep 19 19:12:18 2011 +0200
@@ -4526,4 +4526,21 @@
 <!--FF808181324D007801324D418FD0008E-->  <AD_ELEMENT_ID><![CDATA[800353]]></AD_ELEMENT_ID>
 <!--FF808181324D007801324D418FD0008E--></AD_PROCESS_PARA>
 
+<!--FF80818132813610013281789D2E0088--><AD_PROCESS_PARA>
+<!--FF80818132813610013281789D2E0088-->  <AD_PROCESS_PARA_ID><![CDATA[FF80818132813610013281789D2E0088]]></AD_PROCESS_PARA_ID>
+<!--FF80818132813610013281789D2E0088-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80818132813610013281789D2E0088-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80818132813610013281789D2E0088-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80818132813610013281789D2E0088-->  <NAME><![CDATA[Copy Attributes in Production Process ]]></NAME>
+<!--FF80818132813610013281789D2E0088-->  <AD_PROCESS_ID><![CDATA[FF8081813219E68E013219ECFE930004]]></AD_PROCESS_ID>
+<!--FF80818132813610013281789D2E0088-->  <SEQNO><![CDATA[50]]></SEQNO>
+<!--FF80818132813610013281789D2E0088-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--FF80818132813610013281789D2E0088-->  <COLUMNNAME><![CDATA[Copyattribute]]></COLUMNNAME>
+<!--FF80818132813610013281789D2E0088-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--FF80818132813610013281789D2E0088-->  <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--FF80818132813610013281789D2E0088-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--FF80818132813610013281789D2E0088-->  <ISRANGE><![CDATA[N]]></ISRANGE>
+<!--FF80818132813610013281789D2E0088-->  <DEFAULTVALUE><![CDATA[Y]]></DEFAULTVALUE>
+<!--FF80818132813610013281789D2E0088--></AD_PROCESS_PARA>
+
 </data>
--- a/src/org/openbravo/erpCommon/ad_actionButton/SequenceProductCreate.java	Mon Sep 19 12:50:06 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/SequenceProductCreate.java	Mon Sep 19 19:12:18 2011 +0200
@@ -26,13 +26,20 @@
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.model.common.plm.AttributeUse;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.manufacturing.processplan.OperationProduct;
+import org.openbravo.model.manufacturing.processplan.OperationProductAttribute;
 import org.openbravo.scheduling.Process;
 import org.openbravo.scheduling.ProcessBundle;
 
 public class SequenceProductCreate implements Process {
 
+  private static final String specialAttListId = "FF808181322476640132249E3417002F";
+  private static final String lotSearchKey = "LOT";
+  private static final String serialNoSearchKey = "SNO";
+  private static final String expirationDateearchKey = "EXD";
+
   @Override
   public void execute(ProcessBundle bundle) throws Exception {
 
@@ -43,6 +50,7 @@
       final String productionType = (String) bundle.getParams().get("productiontype");
       final String qty = (String) bundle.getParams().get("qty");
       final ConnectionProvider conn = bundle.getConnection();
+      final String copyAttribute = (String) bundle.getParams().get("copyattribute");
 
       // Create new product copy of selected
       OperationProduct opProduct = OBDal.getInstance().get(OperationProduct.class,
@@ -81,8 +89,24 @@
 
       OBDal.getInstance().flush();
 
+      // Copy Attributes
+      if (copyAttribute.equals("Y") && newProduct.getAttributeSet() != null) {
+        // Special Attribute
+        if (newProduct.getAttributeSet().isLot())
+          copyAtt(newOpProduct, opProduct.getProduct(), true, lotSearchKey, null);
+        if (newProduct.getAttributeSet().isSerialNo())
+          copyAtt(newOpProduct, opProduct.getProduct(), true, serialNoSearchKey, null);
+        if (newProduct.getAttributeSet().isExpirationDate())
+          copyAtt(newOpProduct, opProduct.getProduct(), true, expirationDateearchKey, null);
+        // Normal Attribute
+        for (AttributeUse attributeuse : newProduct.getAttributeSet().getAttributeUseList()) {
+          copyAtt(newOpProduct, opProduct.getProduct(), false, "", attributeuse);
+        }
+      }
+
+      OBDal.getInstance().flush();
+
       final OBError msg = new OBError();
-
       msg.setType("Success");
       msg.setTitle(Utility.messageBD(conn, "Success", bundle.getContext().getLanguage()));
       msg.setMessage(Utility.messageBD(conn, "IOProductCreated", bundle.getContext().getLanguage())
@@ -107,4 +131,25 @@
     }
   }
 
+  private void copyAtt(OperationProduct newOpProduct, Product productFrom, boolean isSpecial,
+      String specialValue, AttributeUse attributeuse) throws Exception {
+
+    OperationProductAttribute opProductAtt = OBProvider.getInstance().get(
+        OperationProductAttribute.class);
+    opProductAtt.setSequenceproduct(newOpProduct);
+    opProductAtt.setClient(newOpProduct.getClient());
+    opProductAtt.setOrganization(newOpProduct.getOrganization());
+    opProductAtt.setProduct(productFrom);
+    opProductAtt.setSpecialatt(isSpecial);
+    if (isSpecial) {
+      opProductAtt.setSpecialatt(specialValue);
+    } else {
+      opProductAtt.setAttributeUse(attributeuse);
+      opProductAtt.setAttributeuseto(attributeuse);
+    }
+
+    OBDal.getInstance().save(opProductAtt);
+
+  }
+
 }
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_SequenceProduct_Product_Attribute.java	Mon Sep 19 12:50:06 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_SequenceProduct_Product_Attribute.java	Mon Sep 19 19:12:18 2011 +0200
@@ -76,17 +76,17 @@
         // Serial No.
         if (product.getAttributeSet().isSerialNo()
             && opProduct.getProduct().getAttributeSet().isSerialNo()) {
-          org.openbravo.model.ad.domain.List lot = SpecialAttListValue(serialNoSearchKey);
-          if (lot != null)
-            info.addSelectResult(lot.getSearchKey(), lot.getName());
+          org.openbravo.model.ad.domain.List sn = SpecialAttListValue(serialNoSearchKey);
+          if (sn != null)
+            info.addSelectResult(sn.getSearchKey(), sn.getName());
         }
 
         // ExpirationDate
         if (product.getAttributeSet().isExpirationDate()
             && opProduct.getProduct().getAttributeSet().isExpirationDate()) {
-          org.openbravo.model.ad.domain.List lot = SpecialAttListValue(expirationDateearchKey);
-          if (lot != null)
-            info.addSelectResult(lot.getSearchKey(), lot.getName());
+          org.openbravo.model.ad.domain.List ed = SpecialAttListValue(expirationDateearchKey);
+          if (ed != null)
+            info.addSelectResult(ed.getSearchKey(), ed.getName());
         }
         info.endSelect();
       }