No subject


Thu May 28 17:10:26 EDT 2009


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-04-01 05:15:19 UTC (rev 16080)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm	2010-04-01 05:15:25 UTC (rev 16081)
@@ -2455,7 +2455,9 @@
         $result->{"lid"}->{$k} = $v;
     }
 
-    # attempt to delete the gathered copies (this will also handle volume deletion, bib deletion, and attempt hold retargeting)
+    # Attempt to delete the gathered copies (this will also handle volume deletion, bib deletion, and attempt hold retargeting)
+    # FIXME: one problem here is that if the transaction for cancel_lineitem gets rolled back later, these copies will remain deleted
+    # Another edge case, if we have a bib but not copies, are we supposed to delete the bib?
     if (scalar(@$copies)>0) {
         my $cat_service = OpenSRF::AppSession->create('open-ils.cat');
         $cat_service->connect;
@@ -2469,6 +2471,38 @@
         }
     }
 
+    # if we have a bib, check to see whether it has been deleted.  if so, cancel any active holds targeting that bib
+    if ($li->eg_bib_id) {
+        my $bib = $mgr->editor->retrieve_biblio_record_entry($li->eg_bib_id) or return new OpenILS::Event(
+            "ACQ_NOT_CANCELABLE", "note" => "Could not retrieve bib " . $li->eg_bib_id . " for lineitem $li_id"
+        );
+        if ($U->is_true($bib->deleted)) {
+            my $holds = $mgr->editor->search_action_hold_request(
+                {   cancel_time => undef,
+                    fulfillment_time => undef,
+                    target => $li->eg_bib_id
+                }
+            );
+
+            for my $hold (@$holds) {
+
+                $logger->info("Cancelling hold ".$hold->id.
+                    " due to acq lineitem cancellation.");
+
+                $hold->cancel_time('now');
+                $hold->cancel_cause(5); # 'Staff forced'--we may want a new hold cancel cause reason for this
+                $hold->cancel_note('Corresponding Acquistion Lineitem/Purchase Order was cancelled.');
+                unless($mgr->editor->update_action_hold_request($hold)) {
+                    my $evt = $mgr->editor->event;
+                    $logger->error("Error updating hold ". $evt->textcode .":". $evt->desc .":". $evt->stacktrace);
+                    return new OpenILS::Event(
+                        "ACQ_NOT_CANCELABLE", "note" => "Could not cancel hold " . $hold->id . " for lineitem $li_id", "payload" => $evt
+                    );
+                }
+            }
+        }
+    }
+
     # TODO delete the associated fund debits?
     # TODO who/what/where/how do we indicate this change for electronic orders?
 



More information about the open-ils-commits mailing list