Bug 36428: Add Bookings->filter_by_active and use it for display
Currently the bookings tab on a biblio details and patron details use 'filter_by_future' which lists upcoming bookings. Libraries would like to see upcoming, and active bookings in these cases, and we should add a filter for bookings that have not ended. NOTE: This removes the only uses of filter_by_future, but I preserve this for Martin's decision as the creator of the bookings module To test: 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) 10 - Reload patron details, note Bookings(1) and booking is listed 11 - End the booking: UPDATE bookings SET end_date=NOW() WHERE biblio_id={biblionumber}; 12 - Confirm booking no longer listed on biblio or patron details Signed-off-by: Sam Lau <samalau@gmail.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
0dd1f43547
commit
859e84417e
4 changed files with 96 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
[%- ELSE -%]
|
||||
<li>
|
||||
[%- END -%]
|
||||
<a href="/cgi-bin/koha/bookings/list.pl?biblionumber=[% biblio_object_id | url %]">Bookings (<span class="bookings_count">[% biblio.bookings.filter_by_future.count | html %]</span>)</a>
|
||||
<a href="/cgi-bin/koha/bookings/list.pl?biblionumber=[% biblio_object_id | url %]">Bookings (<span class="bookings_count">[% biblio.bookings.filter_by_active.count | html %]</span>)</a>
|
||||
</li>
|
||||
[% END %]
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<span>Holds ([% holds_count || 0 | html %])</span>
|
||||
[% END %]
|
||||
[% WRAPPER tab_item tabname="bookings" %]
|
||||
[% SET bookings_count = patron.bookings.filter_by_future.count %]
|
||||
[% SET bookings_count = patron.bookings.filter_by_active.count %]
|
||||
<span>Bookings ([% bookings_count || 0 | html %])</span>
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue