@@ -, +, @@
display
1 - Make an item bookable from the items tab on a record details
2 - Return to details view and place a booking
3 - Note sidebar says "Bookings (1)"
4 - Make the booking current from the DB:
UPDATE bookings SET start_date=NOW() WHERE biblio_id={biblionumber};
5 - Reload the page
6 - Note the count is now "Bookings (0)"
7 - View the patron's details page - note "Bookings (0)" and none listed
8 - Apply patch
9 - Reload biblio details, note Bookings(1)
UPDATE bookings SET end_date=NOW() WHERE biblio_id={biblionumber};
---
Koha/Bookings.pm | 13 +++
.../prog/en/includes/biblio-view-menu.inc | 2 +-
.../prog/en/includes/patron-detail-tabs.inc | 2 +-
t/db_dependent/Koha/Bookings.t | 85 ++++++++++++++++++-
4 files changed, 96 insertions(+), 6 deletions(-)
--- a/Koha/Bookings.pm
+++ a/Koha/Bookings.pm
@@ -45,6 +45,19 @@ sub filter_by_future {
return $self->search( { start_date => { '>' => \'NOW()' } } );
}
+=head3 filter_by_active
+
+ $bookings->filter_by_active;
+
+Will return the bookings that have not ended.
+
+=cut
+
+sub filter_by_active {
+ my ($self) = @_;
+ return $self->search( { end_date => { '>=' => \'NOW()' } } );
+}
+
=head2 Internal Methods
=head3 _type
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc
+++ a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc
@@ -56,7 +56,7 @@
[%- ELSE -%]
[%- END -%]
- Bookings ([% biblio.bookings.filter_by_future.count | html %])
+ Bookings ([% biblio.bookings.filter_by_active.count | html %])
[% END %]
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc
+++ a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc
@@ -30,7 +30,7 @@
Holds ([% holds_count || 0 | html %])
[% END %]
[% WRAPPER tab_item tabname="bookings" %]
- [% SET bookings_count = patron.bookings.filter_by_future.count %]
+ [% SET bookings_count = patron.bookings.filter_by_active.count %]
Bookings ([% bookings_count || 0 | html %])
[% END %]
[% END %]
--- a/t/db_dependent/Koha/Bookings.t
+++ a/t/db_dependent/Koha/Bookings.t
@@ -19,7 +19,7 @@
use Modern::Perl;
-use Test::More tests => 1;
+use Test::More tests => 2;
use Koha::Bookings;
use Koha::Database;
@@ -37,9 +37,7 @@ subtest 'filter_by_future' => sub {
$schema->storage->txn_begin;
- my $biblio = $builder->build_sample_biblio;
- my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' );
- my $end_0 = dt_from_string->add( days => 4 )->truncate( to => 'day' );
+ my $biblio = $builder->build_sample_biblio;
$builder->build_object(
{
class => 'Koha::Bookings',
@@ -90,3 +88,82 @@ subtest 'filter_by_future' => sub {
$schema->storage->txn_rollback;
};
+
+subtest 'filter_by_active' => sub {
+
+ plan tests => 5;
+
+ $schema->storage->txn_begin;
+
+ my $biblio = $builder->build_sample_biblio;
+ my $start_ago = dt_from_string->subtract( hours => 1 );
+ my $start_hour = dt_from_string->add( hours => 1 );
+ my $start_day = dt_from_string->add( days => 1 );
+ my $end_ago = dt_from_string->subtract( minutes => 1 );
+ my $end_hour = dt_from_string->add( hours => 1 );
+ my $end_day = dt_from_string->add( days => 1 );
+ $builder->build_object(
+ {
+ class => 'Koha::Bookings',
+ value => {
+ biblio_id => $biblio->biblionumber,
+ start_date => $start_ago,
+ end_date => $end_hour
+ }
+ }
+ );
+ is( $biblio->bookings->filter_by_active->count, 1, 'Booking started in past, ending in future is counted' );
+
+ $builder->build_object(
+ {
+ class => 'Koha::Bookings',
+ value => {
+ biblio_id => $biblio->biblionumber,
+ start_date => $start_ago,
+ end_date => $end_ago
+ }
+ }
+ );
+ is( $biblio->bookings->filter_by_active->count, 1, 'Booking started in past, ended now is not counted' );
+
+ $builder->build_object(
+ {
+ class => 'Koha::Bookings',
+ value => {
+ biblio_id => $biblio->biblionumber,
+ start_date => $start_hour,
+ end_date => $end_hour
+ }
+ }
+ );
+ is( $biblio->bookings->filter_by_active->count, 2, 'Booking starting soon, ending soon is still counted' );
+
+ $builder->build_object(
+ {
+ class => 'Koha::Bookings',
+ value => {
+ biblio_id => $biblio->biblionumber,
+ start_date => $start_day,
+ end_date => $end_day
+ }
+ }
+ );
+ is( $biblio->bookings->filter_by_active->count, 3, 'Booking starting tomorrow, ending tomorrow is counted' );
+
+ $builder->build_object(
+ {
+ class => 'Koha::Bookings',
+ value => {
+ biblio_id => $biblio->biblionumber,
+ start_date => $start_day,
+ end_date => $end_ago
+ }
+ }
+ );
+ is(
+ $biblio->bookings->filter_by_active->count, 3,
+ 'EDGE CASE: Booking starting in future, already ended is not counted - should be impossible, but good check'
+ );
+
+ $schema->storage->txn_rollback;
+};
--