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

(-)a/Koha/Booking.pm (-1 / +31 lines)
Lines 27-32 use Koha::Libraries; Link Here
27
27
28
use C4::Letters;
28
use C4::Letters;
29
29
30
use List::Util qw(any);
31
30
use base qw(Koha::Object);
32
use base qw(Koha::Object);
31
33
32
=head1 NAME
34
=head1 NAME
Lines 149-155 sub store { Link Here
149
                $self->_assign_item_for_booking;
151
                $self->_assign_item_for_booking;
150
            }
152
            }
151
153
152
            $self = $self->SUPER::store;
154
            my $is_modification = $self->in_storage;
155
            my $old_booking     = $self->get_from_storage;
156
            if ( $self =
157
                    $self->SUPER::store
158
                and $is_modification
159
                and any { $old_booking->$_ ne $self->$_ } qw(pickup_library_id start_date end_date) )
160
            {
161
                my $patron         = $self->patron;
162
                my $pickup_library = $self->pickup_library;
163
164
                my $letter = C4::Letters::GetPreparedLetter(
165
                    module                 => 'bookings',
166
                    letter_code            => 'BOOKING_MODIFICATION',
167
                    message_transport_type => 'email',
168
                    branchcode             => $pickup_library->branchcode,
169
                    lang                   => $patron->lang,
170
                    objects                => { booking => $self },
171
                );
172
173
                if ($letter) {
174
                    C4::Letters::EnqueueLetter(
175
                        {
176
                            letter                 => $letter,
177
                            borrowernumber         => $patron->borrowernumber,
178
                            message_transport_type => 'email',
179
                        }
180
                    );
181
                }
182
            }
153
        }
183
        }
154
    );
184
    );
155
185
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+24 lines)
Lines 66-71 tables: Link Here
66
            - "<br>"
66
            - "<br>"
67
            - "[% booking.pickup_library.branchname %]"
67
            - "[% booking.pickup_library.branchname %]"
68
68
69
        - module: bookings
70
          code: BOOKING_MODIFICATION
71
          branchcode: ""
72
          name: "Booking modification notice"
73
          is_html: 1
74
          title: "A library booking was modified"
75
          message_transport_type: email
76
          lang: default
77
          content:
78
            - "[%- PROCESS 'html_helpers.inc' -%]"
79
            - "[%- USE KohaDates -%]"
80
            - "Dear [%- INCLUDE 'patron-title.inc' patron => booking.patron -%],<br>"
81
            - "<br>"
82
            - "Your booking of [%- INCLUDE 'biblio-title.inc' biblio=booking.biblio link = 0 -%] has been modified.<br>"
83
            - "<br>"
84
            - "The new details are:<br>"
85
            - "<br>"
86
            - "Dates: [% booking.start_date | $KohaDates %] to [% booking.end_date | $KohaDates %]<br>"
87
            - "<br>"
88
            - "Pickup at: [% booking.pickup_library.branchname %]<br>"
89
            - "Kind regards<br>"
90
            - "<br>"
91
            - "[% booking.pickup_library.branchname %]"
92
69
        - module: catalogue
93
        - module: catalogue
70
          code: TICKET_ACKNOWLEDGE
94
          code: TICKET_ACKNOWLEDGE
71
          branchcode: ""
95
          branchcode: ""
(-)a/t/db_dependent/Koha/Booking.t (-2 / +83 lines)
Lines 123-129 subtest 'Relation accessor tests' => sub { Link Here
123
};
123
};
124
124
125
subtest 'store() tests' => sub {
125
subtest 'store() tests' => sub {
126
    plan tests => 13;
126
    plan tests => 14;
127
    $schema->storage->txn_begin;
127
    $schema->storage->txn_begin;
128
128
129
    my $patron  = $builder->build_object( { class => "Koha::Patrons" } );
129
    my $patron  = $builder->build_object( { class => "Koha::Patrons" } );
Lines 322-327 subtest 'store() tests' => sub { Link Here
322
        # ✓ Any (1)         |--|
322
        # ✓ Any (1)         |--|
323
    };
323
    };
324
324
325
    subtest 'notice trigger' => sub {
326
        plan tests => 3;
327
328
        my $original_notices_count = Koha::Notice::Messages->search(
329
            {
330
                letter_code    => 'BOOKING_MODIFICATION',
331
                borrowernumber => $patron->borrowernumber,
332
            }
333
        )->count;
334
335
        $start_1 = dt_from_string->add( months => 1 )->truncate( to => 'day' );
336
        $end_1   = $start_1->clone()->add( days => 1 );
337
338
        # Use datetime formatting so that we don't get DateTime objects
339
        $booking = Koha::Booking->new(
340
            {
341
                patron_id         => $patron->borrowernumber,
342
                biblio_id         => $biblio->biblionumber,
343
                pickup_library_id => $item_2->homebranch,
344
                start_date        => $start_1->datetime(q{ }),
345
                end_date          => $end_1->datetime(q{ }),
346
            }
347
        )->store;
348
349
        my $post_notices_count = Koha::Notice::Messages->search(
350
            {
351
                letter_code    => 'BOOKING_MODIFICATION',
352
                borrowernumber => $patron->borrowernumber,
353
            }
354
        )->count;
355
        is(
356
            $post_notices_count,
357
            $original_notices_count,
358
            'Koha::Booking->store should not have enqueued a BOOKING_MODIFICATION email for a new booking'
359
        );
360
361
        my $item_4 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } );
362
363
        $booking->update(
364
            {
365
                item_id => $item_4->itemnumber,
366
            }
367
        );
368
369
        $post_notices_count = Koha::Notice::Messages->search(
370
            {
371
                letter_code    => 'BOOKING_MODIFICATION',
372
                borrowernumber => $patron->borrowernumber,
373
            }
374
        )->count;
375
        is(
376
            $post_notices_count,
377
            $original_notices_count,
378
            'Koha::Booking->store should not have enqueued a BOOKING_MODIFICATION email for a booking with modified item_id'
379
        );
380
381
        $booking->update(
382
            {
383
                start_date => $start_1->clone()->add( days => 1 )->datetime(q{ }),
384
            }
385
        );
386
387
        # start_date, end_date and pickup_library_id should behave identical
388
        $post_notices_count = Koha::Notice::Messages->search(
389
            {
390
                letter_code    => 'BOOKING_MODIFICATION',
391
                borrowernumber => $patron->borrowernumber,
392
            }
393
        )->count;
394
        is(
395
            $post_notices_count,
396
            $original_notices_count + 1,
397
            'Koha::Booking->store should have enqueued a BOOKING_MODIFICATION email for a booking with modified start_date'
398
        );
399
400
        $booking->update(
401
            {
402
                end_date => $end_1->clone()->add( days => 1 )->datetime(q{ }),
403
            }
404
        );
405
    };
406
325
    $schema->storage->txn_rollback;
407
    $schema->storage->txn_rollback;
326
};
408
};
327
409
328
- 

Return to bug 37204