details:   https://code.openbravo.com/erp/devel/pi/rev/d685ef0795fa
changeset: 20301:d685ef0795fa
user:      Javier Etxarri <javier.echarri <at> openbravo.com>
date:      Thu May 09 12:13:33 2013 +0200
summary:   issue 23754: Goods receipt lines can not be deleted in Oracle

diffstat:

 src/org/openbravo/event/MInOutLineEventHandler.java |  71 +++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diffs (76 lines):

diff -r 0f26e49c3593 -r d685ef0795fa 
src/org/openbravo/event/MInOutLineEventHandler.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/event/MInOutLineEventHandler.java       Thu May 09 
12:13:33 2013 +0200
@@ -0,0 +1,71 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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) 2013 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+package org.openbravo.event;
+
+import javax.enterprise.event.Observes;
+
+import org.apache.log4j.Logger;
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.base.model.Entity;
+import org.openbravo.base.model.ModelProvider;
+import org.openbravo.client.kernel.event.EntityDeleteEvent;
+import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
+import org.openbravo.model.materialmgmt.transaction.ShipmentInOutLine;
+import org.openbravo.service.db.DalConnectionProvider;
+
+public class MInOutLineEventHandler extends EntityPersistenceEventObserver {
+  private static Entity[] entities = { ModelProvider.getInstance().getEntity(
+      ShipmentInOutLine.ENTITY_NAME) };
+  protected Logger logger = Logger.getLogger(this.getClass());
+
+  @Override
+  protected Entity[] getObservedEntities() {
+    return entities;
+  }
+
+  public void onDelete(@Observes EntityDeleteEvent event) {
+    if (!isValidEvent(event)) {
+      return;
+    }
+    checkShipmentOrderRelation((ShipmentInOutLine) event.getTargetInstance());
+  }
+
+  private void checkShipmentOrderRelation(ShipmentInOutLine shipmentInOutLine) 
{
+    ConnectionProvider conn = new DalConnectionProvider(false);
+    String language = OBContext.getOBContext().getLanguage().getLanguage();
+    OBCriteria<ShipmentInOutLine> criteria = 
OBDal.getInstance().createCriteria(
+        ShipmentInOutLine.class);
+    criteria.add(Restrictions.eq(ShipmentInOutLine.PROPERTY_SHIPMENTRECEIPT,
+        shipmentInOutLine.getShipmentReceipt()));
+
+    if (criteria.count() == 1) {
+      ShipmentInOut shipmentInOut = 
OBDal.getInstance().get(ShipmentInOut.class,
+          shipmentInOutLine.getShipmentReceipt().getId());
+      shipmentInOut.setSalesOrder(null);
+      OBDal.getInstance().save(shipmentInOut);
+      OBDal.getInstance().flush();
+    }
+  }
+
+}
\ No newline at end of file

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to