From c758e222428ba6ad69b3d52ee6030d02e17ae964 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 19 Jan 2017 20:14:51 +0100 Subject: [PATCH] Bug 17967: TT syntax for notices - Prove that ODUE is compatible Nothing new here, unless we are introducing a regression. The items.fine is a trick of our historical syntax. We need to provide a way to access this value from the a notice template using the TT syntax. A bug 17976 has been opened for discussion. Test plan: Define ODUE and OVERDUES_SLIP notice templates and use it to generate overdue notices from the cronjob script (misc/cronjobs/overdue_notices.pl) or the interface (members/print_overdues.pl). You should be able to generate the same notices with and without using the TT syntax Signed-off-by: Kyle M Hall Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/Overdues.pm | 3 + t/db_dependent/Letters/TemplateToolkit.t | 138 ++++++++++++++++++++++- 2 files changed, 140 insertions(+), 1 deletion(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index d22914fc84..65b1296295 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -1031,6 +1031,9 @@ sub parse_overdues_letter { branchcode => $params->{'branchcode'}, lang => $patron->lang, tables => \%tables, + loops => { + overdues => [ map { $_->{items}->{itemnumber} } @item_tables ], + }, substitute => $substitute, repeat => { item => \@item_tables }, message_transport_type => $params->{message_transport_type}, diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index 95973ed875..f85825f8a7 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -286,7 +286,7 @@ $prepared_letter = GetPreparedLetter( is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' ); subtest 'regression tests' => sub { - plan tests => 6; + plan tests => 7; my $library = $builder->build( { source => 'Branch' } ); my $patron = $builder->build( { source => 'Borrower' } ); @@ -717,7 +717,143 @@ EOF is( $first_tt_slip->{content}, $first_slip->{content}, ); is( $second_tt_slip->{content}, $second_slip->{content}, ); + + # Cleanup + AddReturn( $item1->{barcode} ); + AddReturn( $item2->{barcode} ); + AddReturn( $item3->{barcode} ); }; + + subtest 'ODUE|items.content|item' => sub { + plan tests => 1; + + my $code = 'ODUE'; + + my $branchcode = $library->{branchcode}; + + # historic syntax + # FIXME items.fine does not work with TT notices + # See bug 17976 + # should contain Fine: <> + my $template = <> <>, + +According to our current records, you have items that are overdue.Your library does not charge late fines, but please return or renew them at the branch below as soon as possible. + +<> +<> +<> <> +Phone: <> +Fax: <> +Email: <> + +If you have registered a password with the library, and you have a renewal available, you may renew online. If an item becomes more than 30 days overdue, you will be unable to use your library card until the item is returned. + +The following item(s) is/are currently overdue: + +"<>" by <>, <>, Barcode: <> + +<> + +Thank-you for your prompt attention to this matter. + +<> Staff +EOF + + reset_template( { template => $template, code => $code, module => 'circulation' } ); + + my $yesterday = dt_from_string->subtract( days => 1 ); + my $two_days_ago = dt_from_string->subtract( days => 2 ); + my $issue1 = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout + my $issue2 = C4::Circulation::AddIssue( $patron, $item2->{barcode}, $yesterday ); # Add an first overdue + my $issue3 = C4::Circulation::AddIssue( $patron, $item3->{barcode}, $two_days_ago ); # Add an second overdue + $issue1 = Koha::Checkout->_new_from_dbic( $issue1 )->unblessed; # ->unblessed should be enough but AddIssue does not return a Koha::Checkout object + $issue2 = Koha::Checkout->_new_from_dbic( $issue2 )->unblessed; + $issue3 = Koha::Checkout->_new_from_dbic( $issue3 )->unblessed; + + # For items.content + my @item_fields = qw( date_due title barcode author itemnumber ); + my $items_content = C4::Letters::get_item_content( { item => { %$item1, %$biblio1, %$issue1 }, item_content_fields => \@item_fields, dateonly => 1 } ); + $items_content .= C4::Letters::get_item_content( { item => { %$item2, %$biblio2, %$issue2 }, item_content_fields => \@item_fields, dateonly => 1 } ); + $items_content .= C4::Letters::get_item_content( { item => { %$item3, %$biblio3, %$issue3 }, item_content_fields => \@item_fields, dateonly => 1 } ); + + my @items = ( $item1, $item2, $item3 ); + my $letter = C4::Overdues::parse_overdues_letter( + { + letter_code => $code, + borrowernumber => $patron->{borrowernumber}, + branchcode => $library->{branchcode}, + items => \@items, + substitute => { + bib => $library->{branchname}, + 'items.content' => $items_content, + count => scalar( @items ), + message_transport_type => 'email', + } + } + ); + + # Cleanup + AddReturn( $item1->{barcode} ); + AddReturn( $item2->{barcode} ); + AddReturn( $item3->{barcode} ); + + + # historic syntax + my $tt_template = < $tt_template, code => $code, module => 'circulation' } ); + + C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout + C4::Circulation::AddIssue( $patron, $item2->{barcode}, $yesterday ); # Add an first overdue + C4::Circulation::AddIssue( $patron, $item3->{barcode}, $two_days_ago ); # Add an second overdue + + my $tt_letter = C4::Overdues::parse_overdues_letter( + { + letter_code => $code, + borrowernumber => $patron->{borrowernumber}, + branchcode => $library->{branchcode}, + items => \@items, + substitute => { + bib => $library->{branchname}, + 'items.content' => $items_content, + count => scalar( @items ), + message_transport_type => 'email', + } + } + ); + + is( $tt_letter->{content}, $letter->{content}, ); + }; + }; subtest 'loops' => sub { -- 2.39.5