details:   https://code.openbravo.com/erp/devel/pi/rev/657fd971187e
changeset: 25247:657fd971187e
user:      Reinaldo Guerra <reinaldo.guerra <at> peoplewalking.com>
date:      Sun Nov 16 16:30:56 2014 -0500
summary:   Fixed bug 27999: Product's image created on create variants can not 
be changed.

Actual creating variants process makes a copy from the entire product's object 
to create the new variants and the new variant's images are the original 
product's image so it is not possible to update them. This behaviour was 
changed to also make a copy from original product image, save it and then 
associate it with the new variant. Now it is possible to update this new 
image's field as it is not related with any other variant or product.
Also a module script was created to fix this problem in already created 
variants through the mentioned process. When executing an ant update database, 
images for products with generic products associated are reinserted and then 
are associated with them.

details:   https://code.openbravo.com/erp/devel/pi/rev/81fbb57834f4
changeset: 25248:81fbb57834f4
user:      Pandeeswari Ramakrishnan <pandeeswari.ramakrishnan <at> 
openbravo.com>
date:      Tue Nov 18 15:24:31 2014 +0530
summary:   Related to Issue 27999: Moved the preference creation outside the 
for loop

diffstat:

 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateVariantImage.class
     |    0 
 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateVariantImageData.class
 |    0 
 src-util/modulescript/src/org/openbravo/modulescript/UpdateVariantImage.java   
             |   53 +++++
 
src-util/modulescript/src/org/openbravo/modulescript/UpdateVariantImage_data.xsql
           |   94 ++++++++++
 src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java          
             |    6 +
 5 files changed, 153 insertions(+), 0 deletions(-)

diffs (176 lines):

diff -r bc9bbb0e83d6 -r 81fbb57834f4 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateVariantImage.class
Binary file 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateVariantImage.class
 has changed
diff -r bc9bbb0e83d6 -r 81fbb57834f4 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateVariantImageData.class
Binary file 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateVariantImageData.class
 has changed
diff -r bc9bbb0e83d6 -r 81fbb57834f4 
src-util/modulescript/src/org/openbravo/modulescript/UpdateVariantImage.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-util/modulescript/src/org/openbravo/modulescript/UpdateVariantImage.java  
    Tue Nov 18 15:24:31 2014 +0530
@@ -0,0 +1,53 @@
+/*
+ *************************************************************************
+ * 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) 2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.modulescript;
+
+import org.apache.log4j.Logger;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.modulescript.ModuleScript;
+
+public class UpdateVariantImage extends ModuleScript {
+
+  private static final Logger log4j = 
Logger.getLogger(UpdateVariantImage.class);
+
+  @Override
+  public void execute() {
+    try {
+      ConnectionProvider cp = getConnectionProvider();
+      boolean executed = UpdateVariantImageData.isModuleScriptExecuted(cp);
+
+      if (!executed) {
+        UpdateVariantImageData[] data = 
UpdateVariantImageData.getVariantsImageId(cp);
+        for (UpdateVariantImageData variantsImage : data) {
+          String generatedId = UpdateVariantImageData.getGeneratedId(cp);
+          int count = UpdateVariantImageData.insertNewProductImage(cp, 
generatedId,
+              variantsImage.adImageId);
+
+          if (count > 0) {
+            UpdateVariantImageData.updateVariantImage(cp, generatedId, 
variantsImage.mProductId);
+          }
+        }
+        UpdateVariantImageData.createPreference(cp);
+      }
+    } catch (Exception e) {
+      handleError(e);
+    }
+  }
+
+}
diff -r bc9bbb0e83d6 -r 81fbb57834f4 
src-util/modulescript/src/org/openbravo/modulescript/UpdateVariantImage_data.xsql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-util/modulescript/src/org/openbravo/modulescript/UpdateVariantImage_data.xsql
 Tue Nov 18 15:24:31 2014 +0530
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ *************************************************************************
+ * 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) 2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+-->
+<SqlClass name="UpdateVariantImageData" package="org.openbravo.modulescript">
+   <SqlClassComment></SqlClassComment>
+  <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+      SELECT '' AS AD_IMAGE_ID, '' AS M_PRODUCT_ID FROM DUAL
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="getVariantsImageId" type="preparedStatement" 
return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+       SELECT AD_IMAGE_ID, M_PRODUCT_ID 
+       FROM M_PRODUCT 
+       WHERE GENERIC_PRODUCT_ID IS NOT NULL
+      ]]></Sql>
+  </SqlMethod>
+  <SqlMethod name="getGeneratedId" type="preparedStatement" return="string">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+       SELECT GET_UUID() AS AD_IMAGE_ID FROM DUAL
+      ]]></Sql>
+  </SqlMethod>
+  <SqlMethod name="insertNewProductImage" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+      INSERT INTO AD_IMAGE (
+          AD_IMAGE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+          CREATED, CREATEDBY, UPDATED, UPDATEDBY,
+          NAME, BINARYDATA, WIDTH, HEIGHT, MIMETYPE
+        ) 
+          SELECT ?, AD_CLIENT_ID, AD_ORG_ID, 'Y',
+                now(), CREATEDBY, now(), UPDATEDBY,
+                NAME, BINARYDATA, WIDTH, HEIGHT, MIMETYPE
+          FROM AD_IMAGE 
+          WHERE AD_IMAGE_ID = ?
+      ]]>
+    </Sql>
+    <Parameter name="generatedId"/>
+    <Parameter name="imageId"/>
+  </SqlMethod>
+  <SqlMethod name="updateVariantImage" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql><![CDATA[
+      UPDATE M_PRODUCT SET AD_IMAGE_ID = ? WHERE M_PRODUCT_ID = ?
+      ]]>
+    </Sql>
+    <Parameter name="imageId"/>
+    <Parameter name="productId"/>
+  </SqlMethod>
+  <SqlMethod name="isModuleScriptExecuted" type="preparedStatement" 
return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+    SELECT COUNT(*) AS EXIST
+    FROM AD_PREFERENCE
+    WHERE ATTRIBUTE = 'UpdateVariantImage' AND ISACTIVE = 'Y'
+      ]]>
+    </Sql>
+  </SqlMethod>
+   <SqlMethod name="createPreference" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+    INSERT INTO AD_PREFERENCE (
+    AD_PREFERENCE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+    CREATEDBY, CREATED, UPDATEDBY, UPDATED, ATTRIBUTE
+    ) VALUES (
+    GET_UUID(), '0', '0', 'Y', 
+    '0', NOW(), '0', NOW(), 'UpdateVariantImage')
+      ]]>
+    </Sql>
+  </SqlMethod>
+</SqlClass>
\ No newline at end of file
diff -r bc9bbb0e83d6 -r 81fbb57834f4 
src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java
--- a/src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java     
Tue Nov 18 10:58:56 2014 +0100
+++ b/src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java     
Tue Nov 18 15:24:31 2014 +0530
@@ -137,6 +137,12 @@
         product = OBDal.getInstance().get(Product.class, recordID);
         Product variant = (Product) DalUtil.copy(product);
 
+        if (product.getImage() != null) {
+          Image newPrImage = (Image) DalUtil.copy(product.getImage(), false);
+          OBDal.getInstance().save(newPrImage);
+          variant.setImage(newPrImage);
+        }
+
         variant.setGenericProduct(product);
         variant.setProductAccountsList(Collections.<ProductAccounts> 
emptyList());
         variant.setGeneric(false);

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to