From e1e01d68b318fa34a8a5ab4490f9c1445a198399 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Mon, 17 Nov 2025 17:54:57 +0000 Subject: [PATCH] Bug 40255: Fixes for translations and updated unit tests --- Koha/Account/Line.pm | 48 ++++++++++++++++++++++-------- t/db_dependent/Koha/Account/Line.t | 11 +++++-- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 391d95af79c..2188fbf33d6 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); @@ -1099,21 +1100,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 5e6da391fd1..e1a5175d025 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -1475,7 +1475,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( @@ -1559,7 +1566,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; }; -- 2.39.5