Bugzilla – Attachment 173177 Details for
Bug 38175
Improve bookings behavior with new status field
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38175: (QA follow-up) Ensure we handle cancelled in clash detection
Bug-38175-QA-follow-up-Ensure-we-handle-cancelled-.patch (text/plain), 7.01 KB, created by
Martin Renvoize (ashimema)
on 2024-10-22 16:31:32 UTC
(
hide
)
Description:
Bug 38175: (QA follow-up) Ensure we handle cancelled in clash detection
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-10-22 16:31:32 UTC
Size:
7.01 KB
patch
obsolete
>From 19bc0bba4b30c0bd9df6b33eefc7c48e8bfc703c Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 22 Oct 2024 17:09:39 +0100 >Subject: [PATCH] Bug 38175: (QA follow-up) Ensure we handle cancelled in clash > detection > >We need to ensure we handle the new status tracking cancelled/completed >in our clash detection code too. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Biblio.pm | 43 +++++++++++++++++++++--------------- > Koha/Bookings.pm | 4 ++-- > Koha/Item.pm | 43 +++++++++++++++++++++--------------- > t/db_dependent/Koha/Biblio.t | 16 +++++++++++++- > t/db_dependent/Koha/Item.t | 16 +++++++++++++- > 5 files changed, 82 insertions(+), 40 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 8829a3e63c5..67242a33088 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -296,24 +296,31 @@ sub check_booking { > > my $dtf = Koha::Database->new->schema->storage->datetime_parser; > my $existing_bookings = $self->bookings( >- [ >- start_date => { >- '-between' => [ >- $dtf->format_datetime($start_date), >- $dtf->format_datetime($end_date) >- ] >- }, >- end_date => { >- '-between' => [ >- $dtf->format_datetime($start_date), >- $dtf->format_datetime($end_date) >- ] >- }, >- { >- start_date => { '<' => $dtf->format_datetime($start_date) }, >- end_date => { '>' => $dtf->format_datetime($end_date) } >- } >- ] >+ { >+ '-and' => [ >+ { >+ '-or' => [ >+ start_date => { >+ '-between' => [ >+ $dtf->format_datetime($start_date), >+ $dtf->format_datetime($end_date) >+ ] >+ }, >+ end_date => { >+ '-between' => [ >+ $dtf->format_datetime($start_date), >+ $dtf->format_datetime($end_date) >+ ] >+ }, >+ { >+ start_date => { '<' => $dtf->format_datetime($start_date) }, >+ end_date => { '>' => $dtf->format_datetime($end_date) } >+ } >+ ] >+ }, >+ { status => { '-not_in' => [ 'cancelled', 'completed' ] } } >+ ] >+ } > ); > > my $booked_count = >diff --git a/Koha/Bookings.pm b/Koha/Bookings.pm >index d63e063647d..ca89e8eacb7 100644 >--- a/Koha/Bookings.pm >+++ b/Koha/Bookings.pm >@@ -44,8 +44,8 @@ sub filter_by_active { > my ($self) = @_; > return $self->search( > { >- end_date => { '>=' => \'NOW()' }, >- status => { q{!=} => [ -and => qw(cancelled completed) ] } >+ end_date => { '>=' => \'NOW()' }, >+ status => { '-not_in' => [ 'cancelled', 'completed' ] } > } > ); > } >diff --git a/Koha/Item.pm b/Koha/Item.pm >index b325570910a..6ccaa75b070 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -702,24 +702,31 @@ sub check_booking { > my $dtf = Koha::Database->new->schema->storage->datetime_parser; > > my $existing_bookings = $self->bookings( >- [ >- start_date => { >- '-between' => [ >- $dtf->format_datetime($start_date), >- $dtf->format_datetime($end_date) >- ] >- }, >- end_date => { >- '-between' => [ >- $dtf->format_datetime($start_date), >- $dtf->format_datetime($end_date) >- ] >- }, >- { >- start_date => { '<' => $dtf->format_datetime($start_date) }, >- end_date => { '>' => $dtf->format_datetime($end_date) } >- } >- ] >+ { >+ '-and' => [ >+ { >+ '-or' => [ >+ start_date => { >+ '-between' => [ >+ $dtf->format_datetime($start_date), >+ $dtf->format_datetime($end_date) >+ ] >+ }, >+ end_date => { >+ '-between' => [ >+ $dtf->format_datetime($start_date), >+ $dtf->format_datetime($end_date) >+ ] >+ }, >+ { >+ start_date => { '<' => $dtf->format_datetime($start_date) }, >+ end_date => { '>' => $dtf->format_datetime($end_date) } >+ } >+ ] >+ }, >+ { status => { '-not_in' => [ 'cancelled', 'completed' ] } } >+ ] >+ } > ); > > my $bookings_count = >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index f768f8a6f71..0fde70957f8 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -1851,7 +1851,7 @@ sub host_record { > } > > subtest 'check_booking tests' => sub { >- plan tests => 4; >+ plan tests => 5; > > $schema->storage->txn_begin; > >@@ -1952,5 +1952,19 @@ subtest 'check_booking tests' => sub { > "Koha::Biblio->check_booking returns true if we pass the booking_id of one of the bookings that we would conflict with" > ); > >+ # Cancelled booking >+ $current_bookings[0]->update( { status => 'cancelled' } ); >+ $can_book = $biblio->check_booking( >+ { >+ start_date => dt_from_string(), >+ end_date => dt_from_string()->add( days => 7 ), >+ } >+ ); >+ is( >+ $can_book, >+ 1, >+ "Koha::Item->check_booking takes account of cancelled status in bookings check" >+ ); >+ > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index 9fa642be693..ebb86a2c8f7 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -3006,7 +3006,7 @@ subtest 'find_booking' => sub { > }; > > subtest 'check_booking tests' => sub { >- plan tests => 5; >+ plan tests => 6; > > $schema->storage->txn_begin; > >@@ -3095,6 +3095,20 @@ subtest 'check_booking tests' => sub { > "Koha::Item->check_booking returns true if we pass the booking_id that would conflict" > ); > >+ # Cancelled booking >+ $booking2->update( { status => 'cancelled' } ); >+ $can_book = $item->check_booking( >+ { >+ start_date => dt_from_string(), >+ end_date => dt_from_string()->add( days => 7 ), >+ } >+ ); >+ is( >+ $can_book, >+ 1, >+ "Koha::Item->check_booking returns true if the conflicting booking is cancelled" >+ ); >+ > $booking2->delete(); > > # Future booking >-- >2.47.0
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 38175
:
172770
|
172771
|
172772
|
172773
|
172814
|
172815
|
172816
|
172817
|
172880
|
172881
|
172882
|
172883
|
172884
|
173172
|
173173
|
173174
|
173175
|
173176
| 173177 |
173178
|
173201
|
173202
|
173203
|
173346
|
173915