[open-ils-commits] r15224 - in trunk/Open-ILS/src: extras perlmods/OpenILS/Application (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Dec 22 12:57:19 EST 2009
Author: miker
Date: 2009-12-22 12:57:15 -0500 (Tue, 22 Dec 2009)
New Revision: 15224
Modified:
trunk/Open-ILS/src/extras/ils_events.xml
trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm
Log:
method and associated event definition (not A/T ... OpenILS::Event) for capturing, and transiting as needed, a resource targeted by a booking reservation
Modified: trunk/Open-ILS/src/extras/ils_events.xml
===================================================================
--- trunk/Open-ILS/src/extras/ils_events.xml 2009-12-22 17:56:15 UTC (rev 15223)
+++ trunk/Open-ILS/src/extras/ils_events.xml 2009-12-22 17:57:15 UTC (rev 15224)
@@ -848,6 +848,9 @@
<event code='7021' textcode='RESERVATION_NOT_FOUND'>
<desc xml:lang="en-US">Booking reservation not found</desc>
</event>
+ <event code='7022' textcode='RESERVATION_CAPTURE_FAILED'>
+ <desc xml:lang="en-US">Booking reservation capture failed</desc>
+ </event>
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm 2009-12-22 17:56:15 UTC (rev 15223)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm 2009-12-22 17:57:15 UTC (rev 15224)
@@ -521,4 +521,94 @@
NOTES
);
+sub capture_reservation {
+ my $self = shift;
+ my $client = shift;
+ my $auth = shift;
+ my $res_id = shift;
+
+ my $e = new_editor(xact => 1, authtoken => $auth);
+ return $e->event unless $e->checkauth;
+ return $e->event unless $e->allowed('CAPTURE_RESERVATION');
+ my $here = $e->requestor->ws_ou;
+
+ my $reservation = $e->retrieve_booking_reservation( $res_id );
+ return OpenILS::Event->new('RESERVATION_NOT_FOUND') unless $reservation;
+
+ return OpenILS::Event->new('RESERVATION_CAPTURE_FAILED', payload => { captured => 0, fail_cause => 'no-resource' })
+ if (!$reservation->current_resource); # no resource
+
+ return OpenILS::Event->new('RESERVATION_CAPTURE_FAILED', payload => { captured => 0, fail_cause => 'cancelled' })
+ if ($reservation->cancel_time); # canceled
+
+ my $resource = $e->retrieve_booking_resource( $reservation->current_resource );
+ my $type = $e->retrieve_booking_resource( $resource->type );
+
+ $reservation->capture_staff( $e->requestor->id );
+ $reservation->capture_time( 'now' );
+
+ return $e->event unless ( $e->update_booking_reservation( $reservation ) and $reservation = $e->data );
+
+ my $ret = { captured => 1, reservation => $reservation };
+
+ if ($here <> $reservation->pickup_lib) {
+ return OpenILS::Event->new('RESERVATION_CAPTURE_FAILED', payload => { captured => 0, fail_cause => 'not-transferable' })
+ if (!$U->is_true($type->transferable)); # non-transferable resource
+
+ # need to transit the item ... is it already in transit?
+ my $transit = $e->search_action_reservation_transit_copy( { reservation => $res_id, dest_recv_time => undef } )->[0];
+
+ if (!$transit) { # not yet in transit
+ $transit = new Fieldmapper::action::reservation_transit_copy ();
+
+ $transit->copy($resource->id);
+ $transit->copy_status(15);
+ $transit->source_send_time('now');
+ $transit->source($here);
+ $transit->dest($reservation->pickup_lib);
+
+ $e->create_action_reservation_transit_copy( $transit );
+
+ if ($U->is_true($type->catalog_item)) {
+ my $copy = $e->search_asset_copy( { barcode => $resource->barcode, deleted => 'f' } )->[0];
+
+ if ($copy) {
+ return OpenILS::Event->new('OPEN_CIRCULATION_EXISTS', payload => $copy) if ($copy->status == 1);
+ $copy->status(6);
+ $e->update_asset_copy( $copy );
+ $$ret{catalog_item} = $e->data;
+ }
+ }
+ }
+
+ $$ret{transit} = $transit;
+ } elsif ($U->is_true($type->catalog_item)) {
+ my $copy = $e->search_asset_copy( { barcode => $resource->barcode, deleted => 'f' } )->[0];
+
+ if ($copy) {
+ return OpenILS::Event->new('OPEN_CIRCULATION_EXISTS', payload => { captured => 0, copy => $copy }) if ($copy->status == 1);
+ $copy->status(15);
+ $e->update_asset_copy( $copy );
+ $$ret{catalog_item} = $e->data;
+ }
+ }
+
+ $e->commit;
+
+ return OpenILS::Event->new('SUCCESS', payload => $ret);
+}
+__PACKAGE__->register_method(
+ method => "capture_reservation",
+ api_name => "open-ils.booking.reservation.capture",
+ argc => 2,
+ signature=> {
+ params => [
+ {type => 'string', desc => 'Authentication token'},
+ {type => 'number', desc => 'Reservation ID'}
+ ],
+ return => { desc => "An OpenILS Event object describing the outcome of the capture, with relevant payload." },
+ }
+);
+
+
1;
More information about the open-ils-commits
mailing list