Bugzilla – Attachment 167308 Details for
Bug 36428
Current bookings are not counted in record side bar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36428: Add Bookings->filter_by_active and use it for display
Bug-36428-Add-Bookings-filterbyactive-and-use-it-f.patch (text/plain), 7.03 KB, created by
Nick Clemens (kidclamp)
on 2024-05-31 11:20:37 UTC
(
hide
)
Description:
Bug 36428: Add Bookings->filter_by_active and use it for display
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-05-31 11:20:37 UTC
Size:
7.03 KB
patch
obsolete
>From eed7c74fefb1a2afce8a0fac9f8f6333f64a59e3 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 31 May 2024 11:13:23 +0000 >Subject: [PATCH] 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 >--- > 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(-) > >diff --git a/Koha/Bookings.pm b/Koha/Bookings.pm >index b9bea5072cc..d4c89b42780 100644 >--- a/Koha/Bookings.pm >+++ b/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 >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc >index 74008ba1176..3e5625eff0a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc >@@ -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 %] > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc >index b220d7952af..6ee596767d6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc >@@ -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 %] >diff --git a/t/db_dependent/Koha/Bookings.t b/t/db_dependent/Koha/Bookings.t >index ca409a6123c..9d29e4c2e82 100755 >--- a/t/db_dependent/Koha/Bookings.t >+++ b/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; >+}; >-- >2.39.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36428
:
167308
|
167694
|
167929
|
167930
|
167931