Bugzilla – Attachment 161910 Details for
Bug 35248
Bookings needs unit tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35248: Refactor - Move assign_item_for_booking
Bug-35248-Refactor---Move-assignitemforbooking.patch (text/plain), 5.02 KB, created by
Nick Clemens (kidclamp)
on 2024-02-08 13:10:52 UTC
(
hide
)
Description:
Bug 35248: Refactor - Move assign_item_for_booking
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-02-08 13:10:52 UTC
Size:
5.02 KB
patch
obsolete
>From a4eb16c70867d03767f104e21b45055cfec6b269 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 7 Feb 2024 17:10:40 +0000 >Subject: [PATCH] Bug 35248: Refactor - Move assign_item_for_booking > >This routine really belongs inside Koha::Booking rather than >Koha::Biblio. This patch moves it there, renames with _ to highlight >it's private nature. > >Test plan >1) Confirm that t/db_dependant/Koha/Booking.t still passes, specifically > the 'store' test. > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/Biblio.pm | 47 ----------------------------------- > Koha/Booking.pm | 65 +++++++++++++++++++++++++++++++++++++++++++------ > 2 files changed, 57 insertions(+), 55 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 72cbc07e8a5..31213eedae4 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -274,53 +274,6 @@ sub check_booking { > return ( ( $total_bookable - $booked_count ) > 0 ) ? 1 : 0; > } > >-=head3 assign_item_for_booking >- >-=cut >- >-sub assign_item_for_booking { >- my ( $self, $params ) = @_; >- >- my $start_date = dt_from_string( $params->{start_date} ); >- my $end_date = dt_from_string( $params->{end_date} ); >- >- 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) } >- } >- ] >- ); >- >- my $checkouts = $self->current_checkouts->search( { date_due => { '>=' => $dtf->format_datetime($start_date) } } ); >- >- my $bookable_items = $self->bookable_items->search( >- { >- itemnumber => [ >- '-and' => { '-not_in' => $existing_bookings->_resultset->get_column('item_id')->as_query }, >- { '-not_in' => $checkouts->_resultset->get_column('itemnumber')->as_query } >- ] >- }, >- { rows => 1 } >- ); >- return $bookable_items->single->itemnumber; >-} >- > =head3 can_be_transferred > > $biblio->can_be_transferred({ to => $to_library, from => $from_library }) >diff --git a/Koha/Booking.pm b/Koha/Booking.pm >index 44e41ab4859..65d3122b6ee 100644 >--- a/Koha/Booking.pm >+++ b/Koha/Booking.pm >@@ -128,14 +128,7 @@ sub store { > > # Assign item at booking time > if ( !$self->item_id ) { >- $self->item_id( >- $self->biblio->assign_item_for_booking( >- { >- start_date => $self->start_date, >- end_date => $self->end_date >- } >- ) >- ); >+ $self->_assign_item_for_booking; > } > > $self = $self->SUPER::store; >@@ -145,6 +138,62 @@ sub store { > return $self; > } > >+=head3 _assign_item_for_booking >+ >+ $self->_assign_item_for_booking; >+ >+Used internally in Koha::Booking->store to ensure we have an item assigned for the booking. >+ >+=cut >+ >+sub _assign_item_for_booking { >+ my ($self) = @_; >+ >+ my $biblio = $self->biblio; >+ >+ my $start_date = dt_from_string( $self->start_date ); >+ my $end_date = dt_from_string( $self->end_date ); >+ >+ my $dtf = Koha::Database->new->schema->storage->datetime_parser; >+ >+ my $existing_bookings = $biblio->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) } >+ } >+ ] >+ ); >+ >+ my $checkouts = >+ $biblio->current_checkouts->search( { date_due => { '>=' => $dtf->format_datetime($start_date) } } ); >+ >+ my $bookable_items = $biblio->bookable_items->search( >+ { >+ itemnumber => [ >+ '-and' => { '-not_in' => $existing_bookings->_resultset->get_column('item_id')->as_query }, >+ { '-not_in' => $checkouts->_resultset->get_column('itemnumber')->as_query } >+ ] >+ }, >+ { rows => 1 } >+ ); >+ >+ my $itemnumber = $bookable_items->single->itemnumber; >+ return $self->item_id($itemnumber); >+} >+ > =head3 get_items_that_can_fill > > my $items = $bookings->get_items_that_can_fill(); >-- >2.30.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 35248
:
161061
|
161062
|
161608
|
161611
|
161620
|
161621
|
161632
|
161636
|
161651
|
161652
|
161653
|
161654
|
161655
|
161656
|
161657
|
161658
|
161659
|
161660
|
161821
|
161822
|
161823
|
161824
|
161825
|
161826
|
161827
|
161828
|
161829
|
161830
|
161831
|
161861
|
161862
|
161863
|
161864
|
161865
|
161866
|
161867
|
161868
|
161869
|
161870
|
161871
|
161890
|
161891
|
161893
|
161894
|
161895
|
161896
|
161897
|
161898
|
161899
|
161900
|
161901
|
161902
|
161903
|
161904
|
161905
|
161906
|
161907
|
161908
|
161909
| 161910 |
161911
|
161912