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

(-)a/Koha/Booking.pm (-23 / +43 lines)
Lines 153-187 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
157
                    $self->SUPER::store
157
            if ( $self = $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;
158
                my $patron         = $self->patron;
162
                my $pickup_library = $self->pickup_library;
159
                my $pickup_library = $self->pickup_library;
163
                my $branch         = C4::Context->userenv->{'branch'};
160
                my $branch         = C4::Context->userenv->{'branch'};
164
161
165
                my $letter = C4::Letters::GetPreparedLetter(
162
                if ( $is_modification
166
                    module                 => 'bookings',
163
                    and any { $old_booking->$_ ne $self->$_ } qw(pickup_library_id start_date end_date) )
167
                    letter_code            => 'BOOKING_MODIFICATION',
164
                {
168
                    message_transport_type => 'email',
165
                    my $letter = C4::Letters::GetPreparedLetter(
169
                    branchcode             => $branch,
166
                        module                 => 'bookings',
170
                    lang                   => $patron->lang,
167
                        letter_code            => 'BOOKING_MODIFICATION',
171
                    objects                => {
168
                        message_transport_type => 'email',
172
                        old_booking => $old_booking,
169
                        branchcode             => $branch,
173
                        booking     => $self
170
                        lang                   => $patron->lang,
174
                    },
171
                        objects                => {
175
                );
172
                            old_booking => $old_booking,
173
                            booking     => $self
174
                        },
175
                    );
176
176
177
                if ($letter) {
177
                    if ($letter) {
178
                    C4::Letters::EnqueueLetter(
178
                        C4::Letters::EnqueueLetter(
179
                        {
179
                            {
180
                            letter                 => $letter,
180
                                letter                 => $letter,
181
                            borrowernumber         => $patron->borrowernumber,
181
                                borrowernumber         => $patron->borrowernumber,
182
                            message_transport_type => 'email',
182
                                message_transport_type => 'email',
183
                        }
183
                            }
184
                        );
185
                    }
186
                } elsif ( !$is_modification ) {
187
                    my $letter = C4::Letters::GetPreparedLetter(
188
                        module                 => 'bookings',
189
                        letter_code            => 'BOOKING_CONFIRMATION',
190
                        message_transport_type => 'email',
191
                        branchcode             => $branch,
192
                        lang                   => $patron->lang,
193
                        objects                => { booking => $self },
184
                    );
194
                    );
195
196
                    if ($letter) {
197
                        C4::Letters::EnqueueLetter(
198
                            {
199
                                letter                 => $letter,
200
                                borrowernumber         => $patron->borrowernumber,
201
                                message_transport_type => 'email',
202
                            }
203
                        );
204
                    }
185
                }
205
                }
186
            }
206
            }
187
        }
207
        }
(-)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 323-329 subtest 'store() tests' => sub { Link Here
323
        # ✓ Any (1)         |--|
323
        # ✓ Any (1)         |--|
324
    };
324
    };
325
325
326
    subtest 'notice trigger' => sub {
326
    subtest 'modification notice trigger' => sub {
327
        plan tests => 3;
327
        plan tests => 3;
328
328
329
        my $original_notices_count = Koha::Notice::Messages->search(
329
        my $original_notices_count = Koha::Notice::Messages->search(
Lines 405-410 subtest 'store() tests' => sub { Link Here
405
        );
405
        );
406
    };
406
    };
407
407
408
    subtest 'confirmation notice trigger' => sub {
409
        plan tests => 2;
410
411
        my $original_notices_count = Koha::Notice::Messages->search(
412
            {
413
                letter_code    => 'BOOKING_CONFIRMATION',
414
                borrowernumber => $patron->borrowernumber,
415
            }
416
        )->count;
417
418
        # Reuse previous booking to produce a clash
419
        eval { $booking = Koha::Booking->new( $booking->unblessed )->store };
420
421
        my $post_notices_count = Koha::Notice::Messages->search(
422
            {
423
                letter_code    => 'BOOKING_CONFIRMATION',
424
                borrowernumber => $patron->borrowernumber,
425
            }
426
        )->count;
427
        is(
428
            $post_notices_count,
429
            $original_notices_count,
430
            'Koha::Booking->store should not have enqueued a BOOKING_CONFIRMATION email if booking creation fails'
431
        );
432
433
        $start_1 = dt_from_string->add( months => 1 )->truncate( to => 'day' );
434
        $end_1   = $start_1->clone()->add( days => 1 );
435
436
        $booking = Koha::Booking->new(
437
            {
438
                patron_id         => $patron->borrowernumber,
439
                biblio_id         => $biblio->biblionumber,
440
                pickup_library_id => $item_2->homebranch,
441
                start_date        => $start_1->datetime(q{ }),
442
                end_date          => $end_1->datetime(q{ }),
443
            }
444
        )->store;
445
446
        $post_notices_count = Koha::Notice::Messages->search(
447
            {
448
                letter_code    => 'BOOKING_CONFIRMATION',
449
                borrowernumber => $patron->borrowernumber,
450
            }
451
        )->count;
452
        is(
453
            $post_notices_count,
454
            $original_notices_count + 1,
455
            'Koha::Booking->store should have enqueued a BOOKING_CONFIRMATION email for a new booking'
456
        );
457
    };
458
408
    $schema->storage->txn_rollback;
459
    $schema->storage->txn_rollback;
409
};
460
};
410
461
411
- 

Return to bug 37803