From 868904789b1be09470fc1deca68cc4789248719a Mon Sep 17 00:00:00 2001
From: Chris Sharp <csharp@georgialibraries.org>
Date: Tue, 7 Nov 2017 16:49:37 -0500
Subject: [PATCH] LP#1269574 - Exclude backordered copies from deletion.

When canceling a lineitem with a cancel reason that
keep debits = true, make sure we don't delete those copies.

Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: John Amundson <jamundson@cwmars.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>
---
 Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
index feacb2f1e1..331baf2dc1 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
@@ -3167,7 +3167,9 @@ sub cancel_lineitem {
             or return 0;
 
         # gathering any real copies for deletion
-        if ($lid->eg_copy_id) {
+        # if there is a copy ID and the cancel reason keeps debits,
+        # do not delete. 
+        if ($lid->eg_copy_id && ! $U->is_true($cancel_reason->keep_debits)) {
             $lid->eg_copy_id->isdeleted('t');
             push @$copies, $lid->eg_copy_id;
         }
-- 
2.11.0