From 25b1cd2567fcba00fe99a2046815793c3880f0d8 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 8 Dec 2009 19:08:32 +0000 Subject: [PATCH] adding org unit settings to block or provide default elbow room for circs; logic to shorten circ duration (if not blocked) to reflect bookings on specific resources git-svn-id: svn://svn.open-ils.org/ILS/trunk@15104 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 1 + .../src/perlmods/OpenILS/Application/Booking.pm | 2 +- .../perlmods/OpenILS/Application/Circ/Circulate.pm | 80 +++++++++++++++++++++- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/095.schema.booking.sql | 1 + ...09.data.org-settings-booking_alter_due_date.sql | 20 ++++++ ...110.schema.booking_resource_type.elbow_room.sql | 8 +++ 7 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql create mode 100644 Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 8280fee8b8..7582bfce2d 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2507,6 +2507,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm b/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm index b81e4ca9de..4fddac887d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm @@ -297,7 +297,7 @@ sub reservation_list_by_filters { 'select' => { bresv => [ 'id' ] }, 'from' => { bresv => {} }, 'where' => {}, - 'order_by' => [{ class => bresv => field => start_time => direction => 'asc' }] + 'order_by' => [{ class => bresv => field => start_time => direction => 'asc' }], 'distinct' => 1 }; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index 26ebdeacc1..7a294ce4cc 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -1214,7 +1214,10 @@ sub do_checkout { $self->build_checkout_circ_object(); return if $self->bail_out; - $self->apply_modified_due_date(); + my $modify_to_start = $self->booking_adjusted_due_date(); + return if $self->bail_out; + + $self->apply_modified_due_date($modify_to_start); return if $self->bail_out; return $self->bail_on_events($self->editor->event) @@ -1589,8 +1592,77 @@ sub build_checkout_circ_object { } +sub booking_adjusted_due_date { + my $self = shift; + my $circ = $self->circ; + my $copy = $self->copy; + + + my $changed; + + if( $self->due_date ) { + + return $self->bail_on_events($self->editor->event) + unless $self->editor->allowed('CIRC_OVERRIDE_DUE_DATE', $self->circ_lib); + + $circ->due_date(clense_ISO8601($self->due_date)); + + } else { + + return unless $copy and $circ->due_date; + } + + if (my $booking_item = $self->editor->search_booking_resource( { barcode => $copy->barcode } )) { + my $resource_type = $self->editor->retrieve_booking_resource_type( $booking_item->resource_type ); + + my $stop_circ_setting = $U->ou_ancestor_setting_value( $self->circ_lib, 'circ.booking_reservation.stop_circ', $self->editor ); + my $shorten_circ_setting = $resource_type->elbow_room || + $U->ou_ancestor_setting_value( $self->circ_lib, 'circ.booking_reservation.default_elbow_room', $self->editor ) || + '0 seconds'; + + my $booking_ses = OpenSRF::AppSession->create( 'open-ils.booking' ); + my $bookings = $booking_ses->request( + 'open-ils.booking.reservations.filtered_id_list', + { resource => $booking_item->id, start_time => 'now', end_time => $circ->due_date } + )->gather(1); + $booking_ses->disconnect; + + my $dt_parser = DateTime::Format::ISO8601->new; + my $due_date = $dt_parser->parse_datetime( clense_ISO8601($circ->due_date) ); + + for my $bid (@$bookings) { + + my $booking = $self->editor->retrieve_booking_reservation( $bid ); + + my $booking_start = $dt_parser->parse_datetime( clense_ISO8601($booking->start_time) ); + my $booking_end = $dt_parser->parse_datetime( clense_ISO8601($booking->end_time) ); + + return $self->bail_on_events( OpenILS::Event->new('COPY_RESERVED') ) + if ($booking_start < DateTime->now); + + + if ($U->is_true($stop_circ_setting)) { + $self->bail_on_events( OpenILS::Event->new('COPY_RESERVED') ); + } else { + $due_date = $booking_start->subtract( seconds => interval_to_seconds($shorten_circ_setting) ); + $self->bail_on_events( OpenILS::Event->new('COPY_RESERVED') ) if ($due_date < DateTime->now); + } + + $circ->due_date(clense_ISO8601($due_date->strftime('%FT%T%z'))); + $self->due_date($circ->due_date); + $changed = 1; + } + + return $self->bail_on_events($self->editor->event) + unless $self->editor->allowed('CIRC_OVERRIDE_DUE_DATE', $self->circ_lib); + } + + return $changed; +} + sub apply_modified_due_date { my $self = shift; + my $shift_earlier = shift; my $circ = $self->circ; my $copy = $self->copy; @@ -1625,7 +1697,11 @@ sub apply_modified_due_date { # XXX make the behavior more dynamic # for now, we just push the due date to after the close date - $circ->due_date($dateinfo->{end}); + if ($shift_earlier) { + $circ->due_date($dateinfo->{start}); + } else { + $circ->due_date($dateinfo->{end}); + } } } } diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index e29b0ba6fa..9ed28a438f 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0108'); -- berick +INSERT INTO config.upgrade_log (version) VALUES ('0110'); -- miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/095.schema.booking.sql b/Open-ILS/src/sql/Pg/095.schema.booking.sql index 2b31b3b37f..3a878a8142 100644 --- a/Open-ILS/src/sql/Pg/095.schema.booking.sql +++ b/Open-ILS/src/sql/Pg/095.schema.booking.sql @@ -23,6 +23,7 @@ CREATE SCHEMA booking; CREATE TABLE booking.resource_type ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, + elbow_room INTERVAL, fine_interval INTERVAL, fine_amount DECIMAL(8,2) NOT NULL DEFAULT 0, max_fine DECIMAL(8,2), diff --git a/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql b/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql new file mode 100644 index 0000000000..479f615121 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql @@ -0,0 +1,20 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0109'); --miker + +INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES ( + 'circ.booking_reservation.stop_circ', + 'Disallow circulation of items when they are on booking reserve and that reserve overlaps with the checkout period', + 'When true, items on booking reserve during the proposed checkout period will not be allowed to circulate unless overridden with the COPY_RESERVED.override permission.', + 'bool' +); + +INSERT INTO config.org_unit_setting_type (name, label, description, datatype) VALUES ( + 'circ.booking_reservation.default_elbow_room', + 'Default amount of time by which a circulation should be shortened to allow for booking reservation delivery', + 'When an item is on booking reserve, and that reservation overlaps with the proposed checkout period, and circulations have not been strictly disallowed on reserved items, Evergreen will attempt to adjust the due date of the circulation for this about of time before the beginning of the reservation period. If this is not possible because the due date would end up in the past, the circulation is disallowed.', + 'interval' +); + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql b/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql new file mode 100644 index 0000000000..69e98e5fe7 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql @@ -0,0 +1,8 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0110'); --miker + +ALTER TABLE booking.resource_type ADD COLUMN elbow_room INTERVAL; + +COMMIT; + -- 2.11.0