[open-ils-commits] r15104 - in trunk/Open-ILS: examples src/perlmods/OpenILS/Application src/perlmods/OpenILS/Application/Circ src/sql/Pg src/sql/Pg/upgrade (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Dec 8 14:08:36 EST 2009


Author: miker
Date: 2009-12-08 14:08:32 -0500 (Tue, 08 Dec 2009)
New Revision: 15104

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql
   trunk/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql
Modified:
   trunk/Open-ILS/examples/fm_IDL.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
   trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql
Log:
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

Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2009-12-08 17:30:05 UTC (rev 15103)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2009-12-08 19:08:32 UTC (rev 15104)
@@ -2507,6 +2507,7 @@
 			<field reporter:label="Return Time" name="return_time" reporter:datatype="timestamp"/>
 			<field reporter:label="Booking Interval" name="booking_interval" reporter:datatype="interval"/>
 			<field reporter:label="Fine Interval" name="fine_interval" reporter:datatype="interval"/>
+			<field reporter:label="Inter-booking Interval" name="elbow_room" reporter:datatype="interval"/>
 			<field reporter:label="Fine Amount" name="fine_amount" reporter:datatype="money"/>
 			<field reporter:label="Max Fine Amount" name="max_fine" reporter:datatype="money"/>
 			<field reporter:label="Target Resource Type" name="target_resource_type" reporter:datatype="link"/>

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm	2009-12-08 17:30:05 UTC (rev 15103)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Booking.pm	2009-12-08 19:08:32 UTC (rev 15104)
@@ -297,7 +297,7 @@
         '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
     };
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2009-12-08 17:30:05 UTC (rev 15103)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2009-12-08 19:08:32 UTC (rev 15104)
@@ -1214,9 +1214,12 @@
     $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)
         unless $self->editor->create_action_circulation($self->circ);
 
@@ -1589,8 +1592,77 @@
 }
 
 
+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 @@
 
             # 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});
+            }
       }
    }
 }

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2009-12-08 17:30:05 UTC (rev 15103)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2009-12-08 19:08:32 UTC (rev 15104)
@@ -51,7 +51,7 @@
     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,

Modified: trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql	2009-12-08 17:30:05 UTC (rev 15103)
+++ trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql	2009-12-08 19:08:32 UTC (rev 15104)
@@ -23,6 +23,7 @@
 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),

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0109.data.org-settings-booking_alter_due_date.sql	2009-12-08 19:08:32 UTC (rev 15104)
@@ -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;
+

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0110.schema.booking_resource_type.elbow_room.sql	2009-12-08 19:08:32 UTC (rev 15104)
@@ -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;
+



More information about the open-ils-commits mailing list