LP#1206649 un-cancel received lineitems / copies
authorBill Erickson <berick@esilibrary.com>
Tue, 20 Aug 2013 13:33:49 +0000 (09:33 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 16 Sep 2013 16:16:02 +0000 (12:16 -0400)
Clear the cancel reason when a canceled lineitem is marked as received.
With items, clear the cancel reason and re-generate fund debits if they
were removed during cancelation (because the keep_debits flag in the
cancel reason was set to false).

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm

index c8ca798..eac934b 100644 (file)
@@ -601,6 +601,8 @@ sub receive_lineitem {
 
     return 0 unless $li->state eq 'on-order' or $li->state eq 'cancelled'; # sic
 
+    $li->clear_cancel_reason; # un-cancel on receive
+
     my $lid_ids = $mgr->editor->search_acq_lineitem_detail(
         {lineitem => $li_id, recv_time => undef}, {idlist => 1});
 
@@ -728,6 +730,19 @@ sub receive_lineitem_detail {
 
     return 1 if $lid->recv_time;
 
+    # if the LID is marked as canceled, remove the cancel reason,
+    # and reinstate fund debits where deleted by cancelation.
+    if ($lid->cancel_reason) {
+        my $cr = $e->retrieve_acq_cancel_reason($lid->cancel_reason);
+
+        if (!$U->is_true($cr->keep_debits)) {
+            # debits were removed during cancelation.
+            create_lineitem_detail_debit(
+                $mgr, $lid->lineitem, $lid) or return 0;
+        }
+        $lid->clear_cancel_reason;
+    }
+
     $lid->receiver($e->requestor->id);
     $lid->recv_time('now');
     $e->update_acq_lineitem_detail($lid) or return 0;