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

(-)a/Koha/CurbsidePickup.pm (+33 lines)
Lines 24-29 use Koha::Database; Link Here
24
use base qw(Koha::Object);
24
use base qw(Koha::Object);
25
25
26
use C4::Circulation qw( CanBookBeIssued AddIssue );
26
use C4::Circulation qw( CanBookBeIssued AddIssue );
27
use C4::Members::Messaging qw( GetMessagingPreferences );
28
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
27
use Koha::DateUtils qw( dt_from_string );
29
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Patron;
30
use Koha::Patron;
29
use Koha::Library;
31
use Koha::Library;
Lines 77-82 sub new { Link Here
77
    return $self->SUPER::new($params);
79
    return $self->SUPER::new($params);
78
}
80
}
79
81
82
=head3 notify_new_pickup
83
84
$pickup->notify_new_pickup
85
86
Will notify the patron that the pickup has been created.
87
Letter 'NEW_CURBSIDE_PICKUP will be used', and depending on 'Hold_Filled' configuration.
88
89
=cut
90
91
sub notify_new_pickup {
92
    my ( $self ) = @_;
93
94
    my $patron = $self->patron;
95
96
    my $library = $self->library;
97
98
    $patron->queue_notice({ letter_params => {
99
        module     => 'reserves',
100
        letter_code => 'NEW_CURBSIDE_PICKUP',
101
        borrowernumber => $patron->borrowernumber,
102
        branchcode => $self->branchcode,
103
        tables     => {
104
            'branches'  => $library->unblessed,
105
            'borrowers' => $patron->unblessed,
106
        },
107
        substitute => {
108
            curbside_pickup => $self,
109
        }
110
    }, message_name => 'Hold_Filled' });
111
}
112
80
=head3 checkouts
113
=head3 checkouts
81
114
82
Return the checkouts linked to this pickup
115
Return the checkouts linked to this pickup
(-)a/circ/curbside_pickups.pl (-3 / +3 lines)
Lines 84-97 elsif ( $op eq 'create-pickup' ) { Link Here
84
    my $notes                     = $input->param('notes');
84
    my $notes                     = $input->param('notes');
85
85
86
    try {
86
    try {
87
        Koha::CurbsidePickup->new(
87
        my $pickup = Koha::CurbsidePickup->new(
88
            {
88
            {
89
                branchcode                => $branchcode,
89
                branchcode                => $branchcode,
90
                borrowernumber            => $borrowernumber,
90
                borrowernumber            => $borrowernumber,
91
                scheduled_pickup_datetime => dt_from_string($scheduled_pickup_datetime),
91
                scheduled_pickup_datetime => dt_from_string($scheduled_pickup_datetime),
92
                notes                     => $notes,
92
                notes                     => $notes,
93
            }
93
            }
94
        )->store();
94
        )->store;
95
        $pickup->notify_new_pickup;
95
    } catch {
96
    } catch {
96
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
97
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
97
            push @messages, {
98
            push @messages, {
Lines 107-113 elsif ( $op eq 'create-pickup' ) { Link Here
107
            };
108
            };
108
        }
109
        }
109
    }
110
    }
110
        # $self->_notify_new_pickup($curbside_pickup); TODO
111
}
111
}
112
elsif ( $op eq 'cancel' ) {
112
elsif ( $op eq 'cancel' ) {
113
    my $id              = $input->param('id');
113
    my $id              = $input->param('id');
(-)a/installer/data/mysql/atomicupdate/bug_30650.pl (+5 lines)
Lines 156-161 return { Link Here
156
                }
156
                }
157
            );
157
            );
158
        }
158
        }
159
        $dbh->do(
160
            q{
161
                INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES ('reserves','NEW_CURBSIDE_PICKUP','',0,"You have schedule a curbside pickup for [% branch.branchname %]","[%- USE KohaDates -%]\n[%- SET cp = curbside_pickup -%]\n\nYou have a curbside pickup scheduled for [% cp.scheduled_pickup_datetime | $KohaDates with_hours => 1 %] at [% cp.library.branchname %].\n\nAny holds waiting for you at the pickup time will be included in this pickup. At this time, that list includes:\n[%- FOREACH h IN cp.patron.holds %]\n    [%- IF h.branchcode == cp.branchcode && h.found == 'W' %]\n* [% h.biblio.title %], [% h.biblio.author %] ([% h.item.barcode %])\n    [%- END %]\n[%- END %]\n\nOnce you have arrived, please call your library or log into your account and click the \"Alert staff of your arrival\" button to let them know you are there.",'email','default');
162
            }
163
        );
159
164
160
        $dbh->do(q{
165
        $dbh->do(q{
161
            INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type` )
166
            INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type` )
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+11 lines)
Lines 1317-1322 tables: Link Here
1317
          content:
1317
          content:
1318
            - "Dear [% borrower.firstname %] [% borrower.surname %],\n\nThe following holds are waiting at [% branch.branchname %]:\n\n[% FOREACH hold IN holds %]\n    [% hold.biblio.title %] : waiting since [% hold.waitingdate | $KohaDates %]\n[% END %]"
1318
            - "Dear [% borrower.firstname %] [% borrower.surname %],\n\nThe following holds are waiting at [% branch.branchname %]:\n\n[% FOREACH hold IN holds %]\n    [% hold.biblio.title %] : waiting since [% hold.waitingdate | $KohaDates %]\n[% END %]"
1319
1319
1320
        - module: reserves
1321
          code: NEW_CURBSIDE_PICKUP
1322
          branchcode: ""
1323
          name: "Curbside pickups"
1324
          is_html: 0
1325
          title: "You have schedule a curbside pickup for [% branch.branchname %]."
1326
          message_transport_type: email
1327
          lang: default
1328
          content:
1329
            - "[%- USE KohaDates -%]\n[%- SET cp = curbside_pickup -%]\n\nYou have a curbside pickup scheduled for [% cp.scheduled_pickup_datetime | $KohaDates with_hours => 1 %] at [% cp.library.branchname %].\n\nAny holds waiting for you at the pickup time will be included in this pickup. At this time, that list includes:\n[%- FOREACH h IN cp.patron.holds %]\n    [%- IF h.branchcode == cp.branchcode && h.found == 'W' %]\n* [% h.biblio.title %], [% h.biblio.author %] ([% h.item.barcode %])\n    [%- END %]\n[%- END %]\n\nOnce you have arrived, please call your library or log into your account and click the \"Alert staff of your arrival\" button to let them know you are there."
1330
1320
        - module: serial
1331
        - module: serial
1321
          code: SERIAL_ALERT
1332
          code: SERIAL_ALERT
1322
          branchcode: ""
1333
          branchcode: ""
(-)a/opac/opac-curbside-pickups.pl (-3 / +3 lines)
Lines 54-67 if ( $op eq 'create-pickup' ) { Link Here
54
    my $notes                     = $input->param('notes');
54
    my $notes                     = $input->param('notes');
55
55
56
    try {
56
    try {
57
        Koha::CurbsidePickup->new(
57
        my $pickup = Koha::CurbsidePickup->new(
58
            {
58
            {
59
                branchcode                => $branchcode,
59
                branchcode                => $branchcode,
60
                borrowernumber            => $borrowernumber,
60
                borrowernumber            => $borrowernumber,
61
                scheduled_pickup_datetime => dt_from_string($scheduled_pickup_datetime),
61
                scheduled_pickup_datetime => dt_from_string($scheduled_pickup_datetime),
62
                notes                     => $notes,
62
                notes                     => $notes,
63
            }
63
            }
64
        )->store();
64
        )->store;
65
        $pickup->notify_new_pickup;
65
    } catch {
66
    } catch {
66
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
67
        if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
67
            push @messages, {
68
            push @messages, {
Lines 77-83 if ( $op eq 'create-pickup' ) { Link Here
77
            };
78
            };
78
        }
79
        }
79
    }
80
    }
80
        # $self->_notify_new_pickup($curbside_pickup); TODO
81
}
81
}
82
elsif ( $op eq 'cancel-pickup' ) {
82
elsif ( $op eq 'cancel-pickup' ) {
83
    my $id              = $input->param('pickup_id');
83
    my $id              = $input->param('pickup_id');
(-)a/t/db_dependent/Koha/CurbsidePickups.t (-3 / +62 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 3;
20
use Test::More tests => 4;
21
use Test::Exception;
21
use Test::Exception;
22
22
23
use Koha::City;
23
use Koha::City;
Lines 193-198 subtest 'workflow' => sub { Link Here
193
    $cp->mark_as_delivered;
193
    $cp->mark_as_delivered;
194
    is( $cp->status, 'delivered' );
194
    is( $cp->status, 'delivered' );
195
    is( $pickups->filter_by_delivered->count, 1 );
195
    is( $pickups->filter_by_delivered->count, 1 );
196
197
    $cp->delete;
196
};
198
};
197
199
198
subtest 'mark_as_delivered' => sub {
200
subtest 'mark_as_delivered' => sub {
Lines 230-236 subtest 'mark_as_delivered' => sub { Link Here
230
232
231
    is( $hold->get_from_storage, undef, 'Hold has been filled' );
233
    is( $hold->get_from_storage, undef, 'Hold has been filled' );
232
    my $checkout = Koha::Checkouts->find({ itemnumber => $item->itemnumber });
234
    my $checkout = Koha::Checkouts->find({ itemnumber => $item->itemnumber });
233
    is( $checkout->borrowernumber, $patron->borrowernumber, 'Item has correctly been checked out' )
235
    is( $checkout->borrowernumber, $patron->borrowernumber, 'Item has correctly been checked out' );
236
237
    $cp->delete;
238
};
239
240
subtest 'notify_new_pickup' => sub {
241
    plan tests => 2;
242
243
    my $item =
244
      $builder->build_sample_item( { library => $library->branchcode } );
245
    my $reserve_id = C4::Reserves::AddReserve(
246
        {
247
            branchcode     => $library->branchcode,
248
            borrowernumber => $patron->borrowernumber,
249
            biblionumber   => $item->biblionumber,
250
            priority       => 1,
251
            itemnumber     => $item->itemnumber,
252
        }
253
    );
254
    my $hold = Koha::Holds->find($reserve_id);
255
    $hold->set_waiting;
256
257
    my $next_monday =
258
      $today->clone->add( days => ( 1 - $today->day_of_week ) % 7 );
259
    my $schedule_dt =
260
      $next_monday->set_hour(15)->set_minute(00)->set_second(00);
261
    my $cp = Koha::CurbsidePickup->new(
262
        {
263
            branchcode                => $library->branchcode,
264
            borrowernumber            => $patron->borrowernumber,
265
            scheduled_pickup_datetime => $schedule_dt,
266
            notes                     => 'just a note'
267
        }
268
    )->store;
269
270
    $patron->set( { email => 'test@example.org' } )->store;
271
    my $dbh = C4::Context->dbh;
272
    $dbh->do( q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ?)|,
273
        undef, $patron->borrowernumber, 4
274
    );
275
    my $borrower_message_preference_id =
276
      $dbh->last_insert_id( undef, undef, "borrower_message_preferences", undef );
277
    $dbh->do(
278
        q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|,
279
        undef, $borrower_message_preference_id, 'email'
280
    );
281
282
    $cp->notify_new_pickup;
283
284
    my $messages = C4::Letters::GetQueuedMessages(
285
        { borrowernumber => $patron->borrowernumber } );
286
    is(
287
        $messages->[0]->{subject},
288
        sprintf ("You have schedule a curbside pickup for %s.", $library->branchname),
289
        "Notice correctly generated"
290
    );
291
    my $biblio_title = $item->biblio->title;
292
    like( $messages->[0]->{content},
293
        qr{$biblio_title}, "Content contains the list of waiting holds" );
234
};
294
};
235
295
236
$schema->storage->txn_rollback;
296
$schema->storage->txn_rollback;
237
- 

Return to bug 30650