@@ -, +, @@
---
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(-)
--- a/Koha/CurbsidePickup.pm
+++ a/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(
--- a/Koha/Exceptions/CurbsidePickup.pm
+++ a/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',
--- a/circ/curbside_pickups.pl
+++ a/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, {
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt
@@ -69,8 +69,18 @@
[% FOR m IN messages %]
[% SWITCH m.code %]
+ [% CASE 'not_enabled' %]
+
The curbside pickup feature is not enabled for this library.
+ [% CASE 'library_is_closed' %]
+
Cannot create a curbside pickup for this day, it is an holiday.
+ [% CASE 'no_waiting_holds' %]
+
This patron does not have waiting holds.
[% CASE 'too_many_pickups' %]
This patron already has a scheduled pickup for this library.
+ [% CASE 'no_matching_slots' %]
+
Wrong slot selected.
+ [% CASE 'no_more_pickups_available' %]
+
There are no more pickups available for this slot. Please choose another one.
[% CASE 'cannot_checkout' %]
Unable to check the items out to [% INCLUDE 'patron-title.inc' patron=m.patron %]
[% CASE 'no_patron_found' %]
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt
@@ -59,12 +59,26 @@
Curbside pickups
[% FOR m IN messages %]
-
+ [% IF m.type == "error" %]
+
+ [% ELSE %]
+
+ [% END %]
[% SWITCH m.code %]
+ [% CASE 'not_enabled' %]
+ The curbside pickup feature is not enabled for this library.
+ [% CASE 'library_is_closed' %]
+ Cannot create a curbside pickup for this day, it is an holiday.
+ [% CASE 'no_waiting_holds' %]
+ This patron does not have waiting holds.
[% CASE 'too_many_pickups' %]
You already have a scheduled pickup for this library.
+ [% CASE 'no_matching_slots' %]
+ Wrong slot selected.
+ [% CASE 'no_more_pickups_available' %]
+ There are no more pickups available for this slot. Please choose another one.
[% CASE 'cannot_checkout' %]
- Unable to check the items out. Please contact the library.
+ Unable to check the items out to [% INCLUDE 'patron-title.inc' patron=m.patron %]
[% CASE 'library_notified' %]
The library has been notified of your arrival.
[% CASE %]
--- a/opac/opac-curbside-pickups.pl
+++ a/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,
--- a/t/db_dependent/Koha/CurbsidePickups.t
+++ a/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 {
--