Fixed issue 37407: Error in server when doing a CL of a layaway with a related canceled service
authorAsier Martirena <asier.martirena@openbravo.com>
Tue, 28 Nov 2017 13:01:27 +0100
changeset 32423 800b5983140c
parent 32422 faaa2e336015
child 32424 8c44968006a4
Fixed issue 37407: Error in server when doing a CL of a layaway with a related canceled service
src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java
--- a/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Tue Jul 04 17:35:43 2017 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Tue Nov 28 13:01:27 2017 +0100
@@ -968,10 +968,23 @@
                   && linesRelations.containsKey(serviceRelation.getOrderlineRelated().getId())
                   && serviceRelation.getOrderlineRelated().getSalesOrder().getId()
                       .equals(oldOrder.getId())) {
-                // A product with a related delivered service (in the same ticket) is being
-                // canceled. The relation between the original product and the service must be
-                // removed.
-                relationsToRemove.add(serviceRelation);
+                if (serviceRelation.getSalesOrderLine().getSalesOrder().getId()
+                    .equals(oldOrder.getId())) {
+                  // A product with a related delivered service (in the same ticket) is being
+                  // canceled. The relation between the original product and the service must be
+                  // removed.
+                  relationsToRemove.add(serviceRelation);
+                } else {
+                  if (serviceRelation.getSalesOrderLine().getSalesOrder().isCancelled()
+                      && serviceRelation.getSalesOrderLine().getSalesOrder().getCancelledorder() != null) {
+                    // A product is being canceled that contains a deferred service that has been
+                    // already canceled. The relation created from the canceled service to the
+                    // original product must be moved to the canceled product.
+                    final OrderLine inverseProductLine = OBDal.getInstance().get(OrderLine.class,
+                        linesRelations.get(serviceRelation.getOrderlineRelated().getId()));
+                    serviceRelation.setOrderlineRelated(inverseProductLine);
+                  }
+                }
               } else {
                 // The CL has a service that is being canceled, which is related to a product in
                 // other ticket (the product is deferred) or to a product that have been delivered