diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 4b8d2a63d4..dfb6571f0f 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -28,6 +28,7 @@ use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Exceptions::Account; use Koha::Patron::Debarments; +use Koha::Notice::Templates; use C4::Letters; use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields); @@ -1116,21 +1117,42 @@ sub store { } #if there is a matching debit description letter, pull that content and render it for the accountline.description - if ( $self->is_debit && !$self->in_storage && !$self->description ) { + if ( $self->is_debit && !$self->in_storage ) { my $debit_type = $self->debit_type; if ($debit_type) { - my $letter = C4::Letters::GetPreparedLetter( - module => 'debit_description', - letter_code => $debit_type->code, - tables => { - borrowers => $self->borrowernumber, - branches => $self->branchcode, - accountline => $self, - }, - ); - if ( $letter && $letter->{content} ) { - $self->description( $letter->{content} ); + # get the patron's prederred lang + my $patron = $self->patron; + my $lang = $patron ? $patron->lang : 'default'; + + # check to make sure the custom notice exists + my $notice_exists = Koha::Notice::Templates->search( + { + module => 'debit_description', + code => $debit_type->code, + message_transport_type => 'email', + lang => $lang, + } + )->count; + + if ($notice_exists) { + my $letter = C4::Letters::GetPreparedLetter( + module => 'debit_description', + letter_code => $debit_type->code, + message_transport_type => 'email', + lang => $lang, + tables => { + borrowers => $self->borrowernumber, + branches => $self->branchcode, + }, + substitute => { + accountline => $self, + }, + ); + + if ( $letter && $letter->{content} ) { + $self->description( $letter->{content} ); + } } } } diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index 25b14731d9..fc4549f8b8 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -1581,7 +1581,14 @@ subtest 'debit description from notice' => sub { $schema->storage->txn_begin; - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + lang => 'default', + } + } + ); # Create a debit type my $debit_type = $builder->build_object( @@ -1665,7 +1672,7 @@ subtest 'debit description from notice' => sub { } )->store; - is( $account_line3->description, 'Manual description', 'System defined description is used' ); + is( $account_line3->description, 'From notice', 'Notice overrides manual description' ); $schema->storage->txn_rollback; };