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

(-)a/Koha/Account/Line.pm (-13 / +35 lines)
Lines 28-33 use Koha::Database; Link Here
28
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
29
use Koha::Exceptions::Account;
29
use Koha::Exceptions::Account;
30
use Koha::Patron::Debarments;
30
use Koha::Patron::Debarments;
31
use Koha::Notice::Templates;
31
use C4::Letters;
32
use C4::Letters;
32
33
33
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
34
use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields);
Lines 1099-1119 sub store { Link Here
1099
    }
1100
    }
1100
1101
1101
    #if there is a matching debit description letter, pull that content and render it for the accountline.description
1102
    #if there is a matching debit description letter, pull that content and render it for the accountline.description
1102
    if ( $self->is_debit && !$self->in_storage && !$self->description ) {
1103
    if ( $self->is_debit && !$self->in_storage ) {
1103
        my $debit_type = $self->debit_type;
1104
        my $debit_type = $self->debit_type;
1104
        if ($debit_type) {
1105
        if ($debit_type) {
1105
            my $letter = C4::Letters::GetPreparedLetter(
1106
1106
                module      => 'debit_description',
1107
            # get the patron's prederred lang
1107
                letter_code => $debit_type->code,
1108
            my $patron = $self->patron;
1108
                tables      => {
1109
            my $lang   = $patron ? $patron->lang : 'default';
1109
                    borrowers   => $self->borrowernumber,
1110
1110
                    branches    => $self->branchcode,
1111
            # check to make sure the custom notice exists
1111
                    accountline => $self,
1112
            my $notice_exists = Koha::Notice::Templates->search(
1112
                },
1113
                {
1113
            );
1114
                    module                 => 'debit_description',
1114
1115
                    code                   => $debit_type->code,
1115
            if ( $letter && $letter->{content} ) {
1116
                    message_transport_type => 'email',
1116
                $self->description( $letter->{content} );
1117
                    lang                   => $lang,
1118
                }
1119
            )->count;
1120
1121
            if ($notice_exists) {
1122
                my $letter = C4::Letters::GetPreparedLetter(
1123
                    module                 => 'debit_description',
1124
                    letter_code            => $debit_type->code,
1125
                    message_transport_type => 'email',
1126
                    lang                   => $lang,
1127
                    tables                 => {
1128
                        borrowers => $self->borrowernumber,
1129
                        branches  => $self->branchcode,
1130
                    },
1131
                    substitute => {
1132
                        accountline => $self,
1133
                    },
1134
                );
1135
1136
                if ( $letter && $letter->{content} ) {
1137
                    $self->description( $letter->{content} );
1138
                }
1117
            }
1139
            }
1118
        }
1140
        }
1119
    }
1141
    }
(-)a/t/db_dependent/Koha/Account/Line.t (-3 / +9 lines)
Lines 1475-1481 subtest 'debit description from notice' => sub { Link Here
1475
1475
1476
    $schema->storage->txn_begin;
1476
    $schema->storage->txn_begin;
1477
1477
1478
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1478
    my $patron = $builder->build_object(
1479
        {
1480
            class => 'Koha::Patrons',
1481
            value => {
1482
                lang => 'default',
1483
            }
1484
        }
1485
    );
1479
1486
1480
    # Create a debit type
1487
    # Create a debit type
1481
    my $debit_type = $builder->build_object(
1488
    my $debit_type = $builder->build_object(
Lines 1559-1565 subtest 'debit description from notice' => sub { Link Here
1559
        }
1566
        }
1560
    )->store;
1567
    )->store;
1561
1568
1562
    is( $account_line3->description, 'Manual description', 'System defined description is used' );
1569
    is( $account_line3->description, 'From notice', 'Notice overrides manual description' );
1563
1570
1564
    $schema->storage->txn_rollback;
1571
    $schema->storage->txn_rollback;
1565
};
1572
};
1566
- 

Return to bug 40255