Bugzilla – Attachment 136604 Details for
Bug 30650
Add a curbside pickup module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30650: Prevent pickup to be created on holiday
Bug-30650-Prevent-pickup-to-be-created-on-holiday.patch (text/plain), 11.85 KB, created by
Jonathan Druart
on 2022-06-27 13:26:35 UTC
(
hide
)
Description:
Bug 30650: Prevent pickup to be created on holiday
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-06-27 13:26:35 UTC
Size:
11.85 KB
patch
obsolete
>From f88f1cab9bb97d95b86161096aaf90330f787200 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 10 May 2022 14:01:09 +0200 >Subject: [PATCH] Bug 30650: Prevent pickup to be created on holiday > >We could improve this more and add disable the holiday from the date >picker widget, but it's out of the scope here. > >Sponsored-by: Association KohaLa - https://koha-fr.org/ >--- > Koha/CurbsidePickup.pm | 5 ++++ > Koha/Exceptions/CurbsidePickup.pm | 4 +++ > circ/curbside_pickups.pl | 28 +++++++++++++++++- > .../prog/en/modules/circ/curbside_pickups.tt | 10 +++++++ > .../en/modules/opac-curbside-pickups.tt | 18 ++++++++++-- > opac/opac-curbside-pickups.pl | 29 ++++++++++++++++++- > t/db_dependent/Koha/CurbsidePickups.t | 21 ++++++++++++-- > 7 files changed, 109 insertions(+), 6 deletions(-) > >diff --git a/Koha/CurbsidePickup.pm b/Koha/CurbsidePickup.pm >index 703a11be4f3..8a12531b643 100644 >--- a/Koha/CurbsidePickup.pm >+++ b/Koha/CurbsidePickup.pm >@@ -26,6 +26,7 @@ use base qw(Koha::Object); > use C4::Circulation qw( CanBookBeIssued AddIssue ); > use C4::Members::Messaging qw( GetMessagingPreferences ); > use C4::Letters qw( GetPreparedLetter EnqueueLetter ); >+use Koha::Calendar; > use Koha::DateUtils qw( dt_from_string ); > use Koha::Patron; > use Koha::Library; >@@ -55,6 +56,10 @@ sub new { > Koha::Exceptions::CubsidePickup::NotEnabled->throw > unless $policy && $policy->enabled; > >+ my $calendar = Koha::Calendar->new( branchcode => $params->{branchcode} ); >+ Koha::Exceptions::CubsidePickup::LibraryIsClosed->throw >+ if $calendar->is_holiday( $params->{scheduled_pickup_datetime} ); >+ > if ( $policy->enable_waiting_holds_only ) { > my $patron = Koha::Patrons->find( $params->{borrowernumber} ); > my $waiting_holds = $patron->holds->search( >diff --git a/Koha/Exceptions/CurbsidePickup.pm b/Koha/Exceptions/CurbsidePickup.pm >index a1e10d0c3fb..c6fc93bb901 100644 >--- a/Koha/Exceptions/CurbsidePickup.pm >+++ b/Koha/Exceptions/CurbsidePickup.pm >@@ -28,6 +28,10 @@ use Exception::Class ( > isa => 'Koha::Exceptions::CurbsidePickup', > description => 'Curbside pickups are not enable for this library', > }, >+ 'Koha::Exceptions::CubsidePickup::LibraryIsClosed' => { >+ isa => 'Koha::Exceptions::CurbsidePickup', >+ description => 'Cannot create a pickup on a closed day', >+ }, > 'Koha::Exceptions::CubsidePickup::TooManyPickups' => { > isa => 'Koha::Exceptions::CurbsidePickup', > description => 'Patron already has a scheduled pickup for this library', >diff --git a/circ/curbside_pickups.pl b/circ/curbside_pickups.pl >index a849f8f938d..593fd2e254a 100755 >--- a/circ/curbside_pickups.pl >+++ b/circ/curbside_pickups.pl >@@ -93,12 +93,38 @@ elsif ( $op eq 'create-pickup' ) { > )->store; > $pickup->notify_new_pickup; > } catch { >- if ( $_->isa('Koha::Exceptions::CubsidePickup::TooManyPickups') ) { >+ if ( $_->isa('Koha::Exceptions::CubsidePickup::NotEnabled') ) { >+ push @messages, { >+ type => 'error', >+ code => 'not_enabled', >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::LibraryIsClosed') ) { >+ push @messages, { >+ type => 'error', >+ code => 'library_is_closed', >+ patron => Koha::Patrons->find($borrowernumber) >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::NoWaitingHolds') ) { >+ push @messages, { >+ type => 'error', >+ code => 'no_waiting_holds', >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::TooManyPickups') ) { > push @messages, { > type => 'error', > code => 'too_many_pickups', > patron => Koha::Patrons->find($borrowernumber) > }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::NoMatchingSlots') ) { >+ push @messages, { >+ type => 'error', >+ code => 'no_matching_slots', >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::NoMorePickupsAvailable') ) { >+ push @messages, { >+ type => 'error', >+ code => 'no_more_pickups_available', >+ }; > } else { > warn $_; > push @messages, { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >index 71549834281..58f0767c33a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >@@ -69,8 +69,18 @@ > [% FOR m IN messages %] > <div class="dialog [% m.type | html %]"> > [% SWITCH m.code %] >+ [% CASE 'not_enabled' %] >+ <span>The curbside pickup feature is not enabled for this library.</span> >+ [% CASE 'library_is_closed' %] >+ <span>Cannot create a curbside pickup for this day, it is an holiday.</span> >+ [% CASE 'no_waiting_holds' %] >+ <span>This patron does not have waiting holds.</span> > [% CASE 'too_many_pickups' %] > <span>This patron already has a scheduled pickup for this library.</span> >+ [% CASE 'no_matching_slots' %] >+ <span>Wrong slot selected.</span> >+ [% CASE 'no_more_pickups_available' %] >+ <span>There are no more pickups available for this slot. Please choose another one.</span> > [% CASE 'cannot_checkout' %] > <span>Unable to check the items out to [% INCLUDE 'patron-title.inc' patron=m.patron %]</span> > [% CASE 'no_patron_found' %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >index 1462cfd7266..9dae1b16b23 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >@@ -59,12 +59,26 @@ > <h2>Curbside pickups</h2> > > [% FOR m IN messages %] >- <div class="dialog [% m.type | html %]"> >+ [% IF m.type == "error" %] >+ <div class="alert alert-warning"> >+ [% ELSE %] >+ <div class="alert alert-info"> >+ [% END %] > [% SWITCH m.code %] >+ [% CASE 'not_enabled' %] >+ <span>The curbside pickup feature is not enabled for this library.</span> >+ [% CASE 'library_is_closed' %] >+ <span>Cannot create a curbside pickup for this day, it is an holiday.</span> >+ [% CASE 'no_waiting_holds' %] >+ <span>This patron does not have waiting holds.</span> > [% CASE 'too_many_pickups' %] > <span>You already have a scheduled pickup for this library.</span> >+ [% CASE 'no_matching_slots' %] >+ <span>Wrong slot selected.</span> >+ [% CASE 'no_more_pickups_available' %] >+ <span>There are no more pickups available for this slot. Please choose another one.</span> > [% CASE 'cannot_checkout' %] >- <span>Unable to check the items out. Please contact the library.</span> >+ <span>Unable to check the items out to [% INCLUDE 'patron-title.inc' patron=m.patron %]</span> > [% CASE 'library_notified' %] > <span>The library has been notified of your arrival.</span> > [% CASE %] >diff --git a/opac/opac-curbside-pickups.pl b/opac/opac-curbside-pickups.pl >index 7e32a027294..abd430523b5 100755 >--- a/opac/opac-curbside-pickups.pl >+++ b/opac/opac-curbside-pickups.pl >@@ -64,12 +64,38 @@ if ( $op eq 'create-pickup' ) { > )->store; > $pickup->notify_new_pickup; > } catch { >- if ( $_->isa('Koha::Exceptions::CubsidePickup::TooManyPickups') ) { >+ if ( $_->isa('Koha::Exceptions::CubsidePickup::NotEnabled') ) { >+ push @messages, { >+ type => 'error', >+ code => 'not_enabled', >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::LibraryIsClosed') ) { >+ push @messages, { >+ type => 'error', >+ code => 'library_is_closed', >+ patron => Koha::Patrons->find($borrowernumber) >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::NoWaitingHolds') ) { >+ push @messages, { >+ type => 'error', >+ code => 'no_waiting_holds', >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::TooManyPickups') ) { > push @messages, { > type => 'error', > code => 'too_many_pickups', > patron => Koha::Patrons->find($borrowernumber) > }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::NoMatchingSlots') ) { >+ push @messages, { >+ type => 'error', >+ code => 'no_matching_slots', >+ }; >+ } elsif ( $_->isa('Koha::Exceptions::CubsidePickup::NoMorePickupsAvailable') ) { >+ push @messages, { >+ type => 'error', >+ code => 'no_more_pickups_available', >+ }; > } else { > warn $_; > push @messages, { >@@ -99,6 +125,7 @@ elsif ( $op eq 'arrival-alert' ) { > } > > $template->param( >+ messages => \@messages, > policies => Koha::CurbsidePickupPolicies->search( > { > enabled => 1, >diff --git a/t/db_dependent/Koha/CurbsidePickups.t b/t/db_dependent/Koha/CurbsidePickups.t >index db66d81f89e..3934498e248 100755 >--- a/t/db_dependent/Koha/CurbsidePickups.t >+++ b/t/db_dependent/Koha/CurbsidePickups.t >@@ -20,9 +20,10 @@ use Modern::Perl; > use Test::More tests => 4; > use Test::Exception; > >-use Koha::City; >+use C4::Calendar; > use Koha::CurbsidePickups; > use Koha::CurbsidePickupPolicies; >+use Koha::Calendar; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); > >@@ -77,7 +78,7 @@ $policy->add_opening_slot('1-12:00-18:00'); > my $today = dt_from_string; > > subtest 'Create a pickup' => sub { >- plan tests => 8; >+ plan tests => 9; > > # Day and datetime are ok > my $next_monday = >@@ -144,6 +145,22 @@ subtest 'Create a pickup' => sub { > 'Koha::Exceptions::CubsidePickup::NoMatchingSlots', > 'Cannot create a pickup on a time that is not matching the start of an interval'; > >+ # Day is a holiday >+ Koha::Caches->get_instance->flush_all; >+ C4::Calendar->new( branchcode => $library->branchcode )->insert_week_day_holiday( >+ weekday => 1, >+ title => '', >+ description => 'Mondays', >+ ); >+ my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); >+ throws_ok { >+ Koha::CurbsidePickup->new({%$params, scheduled_pickup_datetime => $schedule_dt})->store; >+ } >+ 'Koha::Exceptions::CubsidePickup::LibraryIsClosed', >+ 'Cannot create a pickup on a holiday'; >+ >+ C4::Context->dbh->do(q{DELETE FROM repeatable_holidays}); >+ Koha::Caches->get_instance->flush_all; > }; > > subtest 'workflow' => sub { >-- >2.25.1
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 30650
:
136584
|
136585
|
136586
|
136587
|
136588
|
136589
|
136590
|
136591
|
136592
|
136593
|
136594
|
136595
|
136596
|
136597
|
136598
|
136599
|
136600
|
136601
|
136602
|
136603
|
136604
|
136605
|
136606
|
136607
|
136608
|
136609
|
136610
|
137095
|
137100
|
137199
|
137211
|
137212
|
137277
|
137278
|
137279
|
137280
|
137281
|
137282
|
137283
|
137284
|
137285
|
137286
|
137287
|
137288
|
137289
|
137290
|
137291
|
137292
|
137293
|
137294
|
137295
|
137296
|
137297
|
137298
|
137299
|
137300
|
137301
|
137302
|
137303
|
137304
|
137305
|
137306
|
137307
|
138261
|
138262
|
138263
|
138264
|
138265
|
138266
|
138267
|
138268
|
138269
|
138270
|
138271
|
138272
|
138273
|
138274
|
138275
|
138276
|
138277
|
138278
|
138279
|
138280
|
138281
|
138282
|
138283
|
138284
|
138285
|
138286
|
138287
|
138288
|
138289
|
138290
|
138291
|
138292
|
138319
|
138320
|
138321
|
138322
|
138323
|
138324
|
138325
|
138330
|
138331
|
138332
|
138333
|
138334
|
138335
|
138336
|
138337
|
138338
|
138339
|
138340
|
138341
|
138342
|
138343
|
138344
|
138345
|
138346
|
138347
|
138348
|
138349
|
138350
|
138351
|
138352
|
138353
|
138354
|
138355
|
138356
|
138357
|
138358
|
138359
|
138360
|
138361
|
138362
|
138363
|
138364
|
138365
|
138366
|
138367
|
138368
|
138369
|
138375
|
138401
|
138610