details:   https://code.openbravo.com/erp/devel/pi/rev/d8e4486f08d7
changeset: 32999:d8e4486f08d7
user:      Nono Carballo <nonofce <at> gmail.com>
date:      Mon Nov 13 13:27:49 2017 +0100
summary:   Fixes issue 37222: Goods receipt created with Generate Receipt From 
Invoice still
linked to the invoice after reactivating and deleting its lines

When deleting all lines of Purchase Invoice, if exists a Good Receipt 
referencing
that invoice, the reference is removed.

diffstat:

 src/org/openbravo/event/InvoiceLineEventHandler.java |  16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diffs (43 lines):

diff -r ea74193b74fa -r d8e4486f08d7 
src/org/openbravo/event/InvoiceLineEventHandler.java
--- a/src/org/openbravo/event/InvoiceLineEventHandler.java      Thu Nov 09 
10:41:46 2017 +0100
+++ b/src/org/openbravo/event/InvoiceLineEventHandler.java      Mon Nov 13 
13:27:49 2017 +0100
@@ -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) 2013 Openbravo SLU
+ * All portions are Copyright (C) 2013-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -30,6 +30,7 @@
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
 
 public class InvoiceLineEventHandler extends EntityPersistenceEventObserver {
   private static Entity[] entities = { ModelProvider.getInstance().getEntity(
@@ -59,8 +60,21 @@
       if (ObjInvoice != null) {
         ObjInvoice.setSalesOrder(null);
         OBDal.getInstance().save(ObjInvoice);
+        unlinkInvoiceFromGoodsReceipt(ObjInvoice);
         OBDal.getInstance().flush();
       }
     }
   }
+
+  private void unlinkInvoiceFromGoodsReceipt(Invoice objInvoice) {
+    OBCriteria<ShipmentInOut> criteria = 
OBDal.getInstance().createCriteria(ShipmentInOut.class);
+    criteria.add(Restrictions.eq(ShipmentInOut.PROPERTY_SALESTRANSACTION, 
Boolean.FALSE));
+    criteria.add(Restrictions.eq(ShipmentInOut.PROPERTY_INVOICE, objInvoice));
+
+    ShipmentInOut goodsReceipt = (ShipmentInOut) criteria.uniqueResult();
+    if (goodsReceipt != null) {
+      goodsReceipt.setInvoice(null);
+      OBDal.getInstance().save(goodsReceipt);
+    }
+  }
 }
\ No newline at end of file

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to