View | Details | Raw Unified | Return to bug 30650
Collapse All | Expand All

(-)a/Koha/CurbsidePickup.pm (+5 lines)
Lines 26-31 use base qw(Koha::Object); Link Here
26
use C4::Circulation qw( CanBookBeIssued AddIssue );
26
use C4::Circulation qw( CanBookBeIssued AddIssue );
27
use C4::Members::Messaging qw( GetMessagingPreferences );
27
use C4::Members::Messaging qw( GetMessagingPreferences );
28
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
28
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
29
use Koha::Calendar;
29
use Koha::DateUtils qw( dt_from_string );
30
use Koha::DateUtils qw( dt_from_string );
30
use Koha::Patron;
31
use Koha::Patron;
31
use Koha::Library;
32
use Koha::Library;
Lines 55-60 sub new { Link Here
55
    Koha::Exceptions::CurbsidePickup::NotEnabled->throw
56
    Koha::Exceptions::CurbsidePickup::NotEnabled->throw
56
      unless $policy && $policy->enabled;
57
      unless $policy && $policy->enabled;
57
58
59
    my $calendar = Koha::Calendar->new( branchcode => $params->{branchcode} );
60
    Koha::Exceptions::CurbsidePickup::LibraryIsClosed->throw
61
      if $calendar->is_holiday( $params->{scheduled_pickup_datetime} );
62
58
    if ( $policy->enable_waiting_holds_only ) {
63
    if ( $policy->enable_waiting_holds_only ) {
59
        my $patron        = Koha::Patrons->find( $params->{borrowernumber} );
64
        my $patron        = Koha::Patrons->find( $params->{borrowernumber} );
60
        my $waiting_holds = $patron->holds->search(
65
        my $waiting_holds = $patron->holds->search(
(-)a/Koha/Exceptions/CurbsidePickup.pm (+4 lines)
Lines 28-33 use Exception::Class ( Link Here
28
        isa         => 'Koha::Exceptions::CurbsidePickup',
28
        isa         => 'Koha::Exceptions::CurbsidePickup',
29
        description => 'Curbside pickups are not enable for this library',
29
        description => 'Curbside pickups are not enable for this library',
30
    },
30
    },
31
    'Koha::Exceptions::CurbsidePickup::LibraryIsClosed' => {
32
        isa         => 'Koha::Exceptions::CurbsidePickup',
33
        description => 'Cannot create a pickup on a closed day',
34
    },
31
    'Koha::Exceptions::CurbsidePickup::TooManyPickups' => {
35
    'Koha::Exceptions::CurbsidePickup::TooManyPickups' => {
32
        isa         => 'Koha::Exceptions::CurbsidePickup',
36
        isa         => 'Koha::Exceptions::CurbsidePickup',
33
        description => 'Patron already has a scheduled pickup for this library',
37
        description => 'Patron already has a scheduled pickup for this library',
(-)a/circ/curbside_pickups.pl (-1 / +27 lines)
Lines 93-104 elsif ( $op eq 'create-pickup' ) { Link Here
93
        )->store;
93
        )->store;
94
        $pickup->notify_new_pickup;
94
        $pickup->notify_new_pickup;
95
    } catch {
95
    } catch {
96
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
96
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::NotEnabled') ) {
97
            push @messages, {
98
                type   => 'error',
99
                code   => 'not_enabled',
100
            };
101
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::LibraryIsClosed') ) {
102
            push @messages, {
103
                type   => 'error',
104
                code   => 'library_is_closed',
105
                patron => Koha::Patrons->find($borrowernumber)
106
            };
107
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoWaitingHolds') ) {
108
            push @messages, {
109
                type   => 'error',
110
                code   => 'no_waiting_holds',
111
            };
112
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
97
            push @messages, {
113
            push @messages, {
98
                type   => 'error',
114
                type   => 'error',
99
                code   => 'too_many_pickups',
115
                code   => 'too_many_pickups',
100
                patron => Koha::Patrons->find($borrowernumber)
116
                patron => Koha::Patrons->find($borrowernumber)
101
            };
117
            };
118
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoMatchingSlots') ) {
119
            push @messages, {
120
                type   => 'error',
121
                code   => 'no_matching_slots',
122
            };
123
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoMorePickupsAvailable') ) {
124
            push @messages, {
125
                type   => 'error',
126
                code   => 'no_more_pickups_available',
127
            };
102
        } else {
128
        } else {
103
            warn $_;
129
            warn $_;
104
            push @messages, {
130
            push @messages, {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt (+10 lines)
Lines 69-76 Link Here
69
                [% FOR m IN messages %]
69
                [% FOR m IN messages %]
70
                    <div class="dialog [% m.type | html %]">
70
                    <div class="dialog [% m.type | html %]">
71
                        [% SWITCH m.code %]
71
                        [% SWITCH m.code %]
72
                        [% CASE 'not_enabled' %]
73
                            <span>The curbside pickup feature is not enabled for this library.</span>
74
                        [% CASE 'library_is_closed' %]
75
                            <span>Cannot create a curbside pickup for this day, it is an holiday.</span>
76
                        [% CASE 'no_waiting_holds' %]
77
                            <span>This patron does not have waiting holds.</span>
72
                        [% CASE 'too_many_pickups' %]
78
                        [% CASE 'too_many_pickups' %]
73
                            <span>This patron already has a scheduled pickup for this library.</span>
79
                            <span>This patron already has a scheduled pickup for this library.</span>
80
                        [% CASE 'no_matching_slots' %]
81
                            <span>Wrong slot selected.</span>
82
                        [% CASE 'no_more_pickups_available' %]
83
                            <span>There are no more pickups available for this slot. Please choose another one.</span>
74
                        [% CASE 'cannot_checkout' %]
84
                        [% CASE 'cannot_checkout' %]
75
                            <span>Unable to check the items out to [% INCLUDE 'patron-title.inc' patron=m.patron %]</span>
85
                            <span>Unable to check the items out to [% INCLUDE 'patron-title.inc' patron=m.patron %]</span>
76
                        [% CASE 'no_patron_found' %]
86
                        [% CASE 'no_patron_found' %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt (-2 / +16 lines)
Lines 59-70 Link Here
59
                    <h2>Curbside pickups</h2>
59
                    <h2>Curbside pickups</h2>
60
60
61
                    [% FOR m IN messages %]
61
                    [% FOR m IN messages %]
62
                        <div class="dialog [% m.type | html %]">
62
                        [% IF m.type == "error" %]
63
                        <div class="alert alert-warning">
64
                        [% ELSE %]
65
                        <div class="alert alert-info">
66
                        [% END %]
63
                            [% SWITCH m.code %]
67
                            [% SWITCH m.code %]
68
                            [% CASE 'not_enabled' %]
69
                                <span>The curbside pickup feature is not enabled for this library.</span>
70
                            [% CASE 'library_is_closed' %]
71
                                <span>Cannot create a curbside pickup for this day, it is an holiday.</span>
72
                            [% CASE 'no_waiting_holds' %]
73
                                <span>This patron does not have waiting holds.</span>
64
                            [% CASE 'too_many_pickups' %]
74
                            [% CASE 'too_many_pickups' %]
65
                                <span>You already have a scheduled pickup for this library.</span>
75
                                <span>You already have a scheduled pickup for this library.</span>
76
                            [% CASE 'no_matching_slots' %]
77
                                <span>Wrong slot selected.</span>
78
                            [% CASE 'no_more_pickups_available' %]
79
                                <span>There are no more pickups available for this slot. Please choose another one.</span>
66
                            [% CASE 'cannot_checkout' %]
80
                            [% CASE 'cannot_checkout' %]
67
                                <span>Unable to check the items out. Please contact the library.</span>
81
                                <span>Unable to check the items out to [% INCLUDE 'patron-title.inc' patron=m.patron %]</span>
68
                            [% CASE 'library_notified' %]
82
                            [% CASE 'library_notified' %]
69
                                <span>The library has been notified of your arrival.</span>
83
                                <span>The library has been notified of your arrival.</span>
70
                            [% CASE %]
84
                            [% CASE %]
(-)a/opac/opac-curbside-pickups.pl (-1 / +28 lines)
Lines 64-75 if ( $op eq 'create-pickup' ) { Link Here
64
        )->store;
64
        )->store;
65
        $pickup->notify_new_pickup;
65
        $pickup->notify_new_pickup;
66
    } catch {
66
    } catch {
67
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
67
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::NotEnabled') ) {
68
            push @messages, {
69
                type   => 'error',
70
                code   => 'not_enabled',
71
            };
72
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::LibraryIsClosed') ) {
73
            push @messages, {
74
                type   => 'error',
75
                code   => 'library_is_closed',
76
                patron => Koha::Patrons->find($borrowernumber)
77
            };
78
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoWaitingHolds') ) {
79
            push @messages, {
80
                type   => 'error',
81
                code   => 'no_waiting_holds',
82
            };
83
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
68
            push @messages, {
84
            push @messages, {
69
                type   => 'error',
85
                type   => 'error',
70
                code   => 'too_many_pickups',
86
                code   => 'too_many_pickups',
71
                patron => Koha::Patrons->find($borrowernumber)
87
                patron => Koha::Patrons->find($borrowernumber)
72
            };
88
            };
89
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoMatchingSlots') ) {
90
            push @messages, {
91
                type   => 'error',
92
                code   => 'no_matching_slots',
93
            };
94
        } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoMorePickupsAvailable') ) {
95
            push @messages, {
96
                type   => 'error',
97
                code   => 'no_more_pickups_available',
98
            };
73
        } else {
99
        } else {
74
            warn $_;
100
            warn $_;
75
            push @messages, {
101
            push @messages, {
Lines 99-104 elsif ( $op eq 'arrival-alert' ) { Link Here
99
}
125
}
100
126
101
$template->param(
127
$template->param(
128
    messages => \@messages,
102
    policies => Koha::CurbsidePickupPolicies->search(
129
    policies => Koha::CurbsidePickupPolicies->search(
103
        {
130
        {
104
            enabled                 => 1,
131
            enabled                 => 1,
(-)a/t/db_dependent/Koha/CurbsidePickups.t (-3 / +19 lines)
Lines 20-28 use Modern::Perl; Link Here
20
use Test::More tests => 4;
20
use Test::More tests => 4;
21
use Test::Exception;
21
use Test::Exception;
22
22
23
use Koha::City;
23
use C4::Calendar;
24
use Koha::CurbsidePickups;
24
use Koha::CurbsidePickups;
25
use Koha::CurbsidePickupPolicies;
25
use Koha::CurbsidePickupPolicies;
26
use Koha::Calendar;
26
use Koha::Database;
27
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
28
29
Lines 77-83 $policy->add_opening_slot('1-12:00-18:00'); Link Here
77
my $today = dt_from_string;
78
my $today = dt_from_string;
78
79
79
subtest 'Create a pickup' => sub {
80
subtest 'Create a pickup' => sub {
80
    plan tests => 8;
81
    plan tests => 9;
81
82
82
    # Day and datetime are ok
83
    # Day and datetime are ok
83
    my $next_monday =
84
    my $next_monday =
Lines 144-149 subtest 'Create a pickup' => sub { Link Here
144
    'Koha::Exceptions::CurbsidePickup::NoMatchingSlots',
145
    'Koha::Exceptions::CurbsidePickup::NoMatchingSlots',
145
'Cannot create a pickup on a time that is not matching the start of an interval';
146
'Cannot create a pickup on a time that is not matching the start of an interval';
146
147
148
    # Day is a holiday
149
    Koha::Caches->get_instance->flush_all;
150
    C4::Calendar->new( branchcode => $library->branchcode )->insert_week_day_holiday(
151
        weekday     => 1,
152
        title       => '',
153
        description => 'Mondays',
154
    );
155
    my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
156
    throws_ok {
157
        Koha::CurbsidePickup->new({%$params, scheduled_pickup_datetime => $schedule_dt})->store;
158
    }
159
    'Koha::Exceptions::CurbsidePickup::LibraryIsClosed',
160
      'Cannot create a pickup on a holiday';
161
162
    C4::Context->dbh->do(q{DELETE FROM repeatable_holidays});
163
    Koha::Caches->get_instance->flush_all;
147
};
164
};
148
165
149
subtest 'workflow' => sub {
166
subtest 'workflow' => sub {
150
- 

Return to bug 30650