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

(-)a/Koha/Booking.pm (-23 / +45 lines)
Lines 153-183 sub store { Link Here
153
153
154
            my $is_modification = $self->in_storage;
154
            my $is_modification = $self->in_storage;
155
            my $old_booking     = $self->get_from_storage;
155
            my $old_booking     = $self->get_from_storage;
156
            if ( $self =
156
            if ( $self = $self->SUPER::store ) {
157
                    $self->SUPER::store
157
                if ( $is_modification
158
                and $is_modification
158
                    and any { $old_booking->$_ ne $self->$_ } qw(pickup_library_id start_date end_date) )
159
                and any { $old_booking->$_ ne $self->$_ } qw(pickup_library_id start_date end_date) )
159
                {
160
            {
160
                    my $patron         = $self->patron;
161
                my $patron         = $self->patron;
161
                    my $pickup_library = $self->pickup_library;
162
                my $pickup_library = $self->pickup_library;
162
163
163
                    my $letter = C4::Letters::GetPreparedLetter(
164
                my $letter = C4::Letters::GetPreparedLetter(
164
                        module                 => 'bookings',
165
                    module                 => 'bookings',
165
                        letter_code            => 'BOOKING_MODIFICATION',
166
                    letter_code            => 'BOOKING_MODIFICATION',
166
                        message_transport_type => 'email',
167
                    message_transport_type => 'email',
167
                        branchcode             => $pickup_library->branchcode,
168
                    branchcode             => $pickup_library->branchcode,
168
                        lang                   => $patron->lang,
169
                    lang                   => $patron->lang,
169
                        objects                => { booking => $self },
170
                    objects                => { booking => $self },
170
                    );
171
                );
172
171
173
                if ($letter) {
172
                    if ($letter) {
174
                    C4::Letters::EnqueueLetter(
173
                        C4::Letters::EnqueueLetter(
175
                        {
174
                            {
176
                            letter                 => $letter,
175
                                letter                 => $letter,
177
                            borrowernumber         => $patron->borrowernumber,
176
                                borrowernumber         => $patron->borrowernumber,
178
                            message_transport_type => 'email',
177
                                message_transport_type => 'email',
179
                        }
178
                            }
179
                        );
180
                    }
181
                } elsif ( !$is_modification ) {
182
                    my $patron         = $self->patron;
183
                    my $pickup_library = $self->pickup_library;
184
185
                    my $letter = C4::Letters::GetPreparedLetter(
186
                        module                 => 'bookings',
187
                        letter_code            => 'BOOKING_CONFIRMATION',
188
                        message_transport_type => 'email',
189
                        branchcode             => $pickup_library->branchcode,
190
                        lang                   => $patron->lang,
191
                        objects                => { booking => $self },
180
                    );
192
                    );
193
194
                    if ($letter) {
195
                        C4::Letters::EnqueueLetter(
196
                            {
197
                                letter                 => $letter,
198
                                borrowernumber         => $patron->borrowernumber,
199
                                message_transport_type => 'email',
200
                            }
201
                        );
202
                    }
181
                }
203
                }
182
            }
204
            }
183
        }
205
        }
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+24 lines)
Lines 90-95 tables: Link Here
90
            - "<br>"
90
            - "<br>"
91
            - "[% booking.pickup_library.branchname %]"
91
            - "[% booking.pickup_library.branchname %]"
92
92
93
        - module: bookings
94
          code: BOOKING_CONFIRMATION
95
          branchcode: ""
96
          name: "Booking confirmation notice"
97
          is_html: 1
98
          title: "A library booking was confirmed"
99
          message_transport_type: email
100
          lang: default
101
          content:
102
            - "[%- PROCESS 'html_helpers.inc' -%]"
103
            - "[%- USE KohaDates -%]"
104
            - "Dear [%- INCLUDE 'patron-title.inc' patron => booking.patron -%],<br>"
105
            - "<br>"
106
            - "Your booking of [%- INCLUDE 'biblio-title.inc' biblio=booking.biblio link = 0 -%] has been confirmed.<br>"
107
            - "<br>"
108
            - "The details are:<br>"
109
            - "<br>"
110
            - "Dates: [% booking.start_date | $KohaDates %] to [% booking.end_date | $KohaDates %]<br>"
111
            - "<br>"
112
            - "Pickup at: [% booking.pickup_library.branchname %]<br>"
113
            - "Kind regards<br>"
114
            - "<br>"
115
            - "[% booking.pickup_library.branchname %]"
116
93
        - module: catalogue
117
        - module: catalogue
94
          code: TICKET_ACKNOWLEDGE
118
          code: TICKET_ACKNOWLEDGE
95
          branchcode: ""
119
          branchcode: ""
(-)a/t/db_dependent/Koha/Booking.t (-3 / +53 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 => 14;
126
    plan tests => 15;
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-328 subtest 'store() tests' => sub { Link Here
322
        # ✓ Any (1)         |--|
322
        # ✓ Any (1)         |--|
323
    };
323
    };
324
324
325
    subtest 'notice trigger' => sub {
325
    subtest 'modification notice trigger' => sub {
326
        plan tests => 3;
326
        plan tests => 3;
327
327
328
        my $original_notices_count = Koha::Notice::Messages->search(
328
        my $original_notices_count = Koha::Notice::Messages->search(
Lines 404-409 subtest 'store() tests' => sub { Link Here
404
        );
404
        );
405
    };
405
    };
406
406
407
    subtest 'confirmation notice trigger' => sub {
408
        plan tests => 2;
409
410
        my $original_notices_count = Koha::Notice::Messages->search(
411
            {
412
                letter_code    => 'BOOKING_CONFIRMATION',
413
                borrowernumber => $patron->borrowernumber,
414
            }
415
        )->count;
416
417
        # Reuse previous booking to produce a clash
418
        eval { $booking = Koha::Booking->new( $booking->unblessed )->store };
419
420
        my $post_notices_count = Koha::Notice::Messages->search(
421
            {
422
                letter_code    => 'BOOKING_CONFIRMATION',
423
                borrowernumber => $patron->borrowernumber,
424
            }
425
        )->count;
426
        is(
427
            $post_notices_count,
428
            $original_notices_count,
429
            'Koha::Booking->store should not have enqueued a BOOKING_CONFIRMATION email if booking creation fails'
430
        );
431
432
        $start_1 = dt_from_string->add( months => 1 )->truncate( to => 'day' );
433
        $end_1   = $start_1->clone()->add( days => 1 );
434
435
        $booking = Koha::Booking->new(
436
            {
437
                patron_id         => $patron->borrowernumber,
438
                biblio_id         => $biblio->biblionumber,
439
                pickup_library_id => $item_2->homebranch,
440
                start_date        => $start_1->datetime(q{ }),
441
                end_date          => $end_1->datetime(q{ }),
442
            }
443
        )->store;
444
445
        $post_notices_count = Koha::Notice::Messages->search(
446
            {
447
                letter_code    => 'BOOKING_CONFIRMATION',
448
                borrowernumber => $patron->borrowernumber,
449
            }
450
        )->count;
451
        is(
452
            $post_notices_count,
453
            $original_notices_count + 1,
454
            'Koha::Booking->store should have enqueued a BOOKING_CONFIRMATION email for a new booking'
455
        );
456
    };
457
407
    $schema->storage->txn_rollback;
458
    $schema->storage->txn_rollback;
408
};
459
};
409
460
410
- 

Return to bug 37803