details: https://code.openbravo.com/erp/devel/pi/rev/50fe70db3a66 changeset: 26572:50fe70db3a66 user: Jorge Garcia <jorge.garcia <at> openbravo.com> date: Tue May 05 11:44:51 2015 +0200 summary: Fixed issue 28908: Not possible to delete a variant if has an image
Not possible to delete a variant if the generic product has an image. The problem was that the image is shared among the generic product and its variants. The solution is to check if other products has the same image_id when deleting a record. In case that this check is true, the image isn't deleted from the database, otherwise, the image is deleted from the database. details: https://code.openbravo.com/erp/devel/pi/rev/3689ff974394 changeset: 26573:3689ff974394 user: Unai Martirena <unai.martirena <at> openbravo.com> date: Thu May 07 16:45:23 2015 +0200 summary: Related to bug 28908: Fix copyright and format diffstat: modules/org.openbravo.client.application/src/org/openbravo/client/application/event/RemoveImagesEventHandler.java | 35 +++++++-- 1 files changed, 26 insertions(+), 9 deletions(-) diffs (96 lines): diff -r fd2ea337257b -r 3689ff974394 modules/org.openbravo.client.application/src/org/openbravo/client/application/event/RemoveImagesEventHandler.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/RemoveImagesEventHandler.java Thu May 07 11:04:36 2015 +0200 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/RemoveImagesEventHandler.java Thu May 07 16:45:23 2015 +0200 @@ -11,7 +11,7 @@ * 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 portions are Copyright (C) 2014-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -24,6 +24,7 @@ import javax.enterprise.event.Observes; +import org.hibernate.criterion.Restrictions; import org.openbravo.base.model.Entity; import org.openbravo.base.model.ModelProvider; import org.openbravo.base.model.Property; @@ -31,8 +32,10 @@ import org.openbravo.client.kernel.event.EntityPersistenceEventObserver; import org.openbravo.client.kernel.event.EntityUpdateEvent; import org.openbravo.dal.core.OBContext; +import org.openbravo.dal.service.OBCriteria; import org.openbravo.dal.service.OBDal; import org.openbravo.model.ad.utility.Image; +import org.openbravo.model.common.plm.Product; public class RemoveImagesEventHandler extends EntityPersistenceEventObserver { @@ -43,8 +46,7 @@ return entities; } - public void onDelete(@Observes - EntityDeleteEvent event) { + public void onDelete(@Observes EntityDeleteEvent event) { if (!isValidEvent(event)) { return; } @@ -58,8 +60,9 @@ if (event.getCurrentState(imageProperty) != null) { Image bob = (Image) event.getCurrentState(imageProperty); - - if (bob != null) { + String selectedProduct = event.getId(); + Product product = checkImageUtilization(selectedProduct, bob); + if (bob != null && product == null) { OBContext.setAdminMode(true); try { OBDal.getInstance().remove(bob); @@ -71,8 +74,7 @@ } } - public void onUpdate(@Observes - EntityUpdateEvent event) { + public void onUpdate(@Observes EntityUpdateEvent event) { if (!isValidEvent(event)) { return; } @@ -87,8 +89,9 @@ && event.getCurrentState(imageProperty) != event.getPreviousState(imageProperty)) { Image bob = (Image) event.getPreviousState(imageProperty); - - if (bob != null) { + String selectedProduct = event.getId(); + Product product = checkImageUtilization(selectedProduct, bob); + if (bob != null && product == null) { OBContext.setAdminMode(true); try { OBDal.getInstance().remove(bob); @@ -110,6 +113,20 @@ return (Entity[]) entityArray.toArray(new Entity[entityArray.size()]); } + // Check if this image is used by another product + private static Product checkImageUtilization(String productId, Image bob) { + final OBCriteria<Product> obCriteria = OBDal.getInstance().createCriteria(Product.class); + obCriteria.add(Restrictions.eq(Product.PROPERTY_IMAGE, bob)); + obCriteria.add(Restrictions.ne(Product.PROPERTY_ID, productId)); + obCriteria.setFilterOnActive(false); + obCriteria.setFilterOnReadableClients(false); + obCriteria.setFilterOnReadableOrganization(false); + obCriteria.setMaxResults(1); + Product product = (Product) obCriteria.uniqueResult(); + + return product; + } + private static List<String> getImageProperties(Entity entity) { // Get EntitiesWithImages from ModelProvider return ModelProvider.getInstance().getEntityWithImage().get(entity); ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
