Fixed issue 37603: The CL flow used to fail in some cases with services.
authorAsier Martirena <asier.martirena@openbravo.com>
Wed, 04 Jul 2018 16:09:49 +0200
changeset 34267 6b875b0a1505
parent 34266 8bf896a22664
child 34268 f4e9ff9ed7bb
Fixed issue 37603: The CL flow used to fail in some cases with services.
It was not possible to do a Cancel Layaway proces with one ticket that contains a deleted (and stored) service line, nor a ticket with a delivered service.
src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java
--- a/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Tue Dec 12 18:23:16 2017 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Wed Jul 04 16:09:49 2018 +0200
@@ -1030,15 +1030,19 @@
     final OBCriteria<OrderLine> oldOrderLineCriteria = OBDal.getInstance().createCriteria(
         OrderLine.class);
     oldOrderLineCriteria.add(Restrictions.eq(OrderLine.PROPERTY_SALESORDER, oldOrder));
+    oldOrderLineCriteria.add(Restrictions.eq(OrderLine.PROPERTY_OBPOSISDELETED, false));
     for (final OrderLine oldOrderLine : oldOrderLineCriteria.list()) {
       final StringBuffer where = new StringBuffer();
-      where.append(" WHERE (" + OrderlineServiceRelation.PROPERTY_SALESORDERLINE
+      where.append(" WHERE " + OrderlineServiceRelation.PROPERTY_SALESORDERLINE + "."
+          + OrderLine.PROPERTY_ID + " IN :cancellingLines");
+      where.append(" AND (" + OrderlineServiceRelation.PROPERTY_SALESORDERLINE
           + " = :salesorderline");
       where.append(" OR " + OrderlineServiceRelation.PROPERTY_ORDERLINERELATED
           + " = :salesorderline)");
       final OBQuery<OrderlineServiceRelation> serviceRelationQuery = OBDal.getInstance()
           .createQuery(OrderlineServiceRelation.class, where.toString());
       serviceRelationQuery.setNamedParameter("salesorderline", oldOrderLine);
+      serviceRelationQuery.setNamedParameter("cancellingLines", linesRelations.keySet());
       for (final OrderlineServiceRelation serviceRelation : serviceRelationQuery.list()) {
         if (!createdRelations.contains(serviceRelation.getId())) {
           createdRelations.add(serviceRelation.getId());