From be4f624b326574a14260c94c90aeb10a9ab56d91 Mon Sep 17 00:00:00 2001
From: Jonathan Druart
Date: Tue, 17 Jan 2017 04:32:58 +0100
Subject: [PATCH] Bug 17966: TT syntax for notices - Prove that ISSUESLIP is
compatible
Here we go, you will notice at the dependency list that this one is a
bit different.
In our former syntax we have 2 custom tags and .
These tags were allowed to permit loop on the checked out items and the
overdue items.
In this patch, we will use the "loops" parameter, introduced by bug
17971, to pass the list of checkouts and overdues to the template.
Note that Kyle suggested another approach on bug 15283: all the
checkouts were send into the same array and each element of this
array calls the is_from_today method, to know if the checkout is an
overdue.
I don't think we should rely on the Koha API, that's why I suggest to
pass 2 differents object list, 1 which contains the checkouts and
another one with the overdues.
Note that we do rely on the Koha API, we call the Koha::Checkout->item
and Koha::Item->biblio to propose an equivalent TT notice. But I think
we can accept that.
Test plan:
Define the ISSUESLIP and ISSUEQSLIP notice templates to generate the
same notices you generated with the historical syntax.
Signed-off-by: Kyle M Hall
https://bugs.koha-community.org/show_bug.cgi?id=17969
Signed-off-by: Kyle M Hall
Signed-off-by: Jonathan Druart
---
C4/Letters.pm | 6 +
C4/Members.pm | 58 ++++++----
t/db_dependent/Letters/TemplateToolkit.t | 138 ++++++++++++++++++++++-
3 files changed, 178 insertions(+), 24 deletions(-)
diff --git a/C4/Letters.pm b/C4/Letters.pm
index 4c25330503..8c6fe854b2 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -1566,6 +1566,12 @@ sub _get_tt_params {
plural => 'old_checkouts',
fk => 'itemnumber',
},
+ overdues => {
+ module => 'Koha::Checkouts',
+ singular => 'overdue',
+ plural => 'overdues',
+ fk => 'itemnumber',
+ },
borrower_modifications => {
module => 'Koha::Patron::Modifications',
singular => 'patron_modification',
diff --git a/C4/Members.pm b/C4/Members.pm
index 3726e002c6..166b051e74 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -1136,39 +1136,50 @@ sub IssueSlip {
$b->{issuedate} <=> $a->{issuedate} : $s;
} @issues;
- my ($letter_code, %repeat);
+ my ($letter_code, %repeat, %loops);
if ( $quickslip ) {
$letter_code = 'ISSUEQSLIP';
- %repeat = (
- 'checkedout' => [ map {
+ my @checkouts = map {
'biblio' => $_,
'items' => $_,
'biblioitems' => $_,
'issues' => $_,
- }, grep { $_->{'now'} } @issues ],
+ }, grep { $_->{'now'} } @issues;
+ %repeat = (
+ checkedout => \@checkouts, # History syntax
+ );
+ %loops = (
+ issues => [ map { $_->{issues}{itemnumber} } @checkouts ], # TT syntax
);
}
else {
+ my @checkouts = map {
+ 'biblio' => $_,
+ 'items' => $_,
+ 'biblioitems' => $_,
+ 'issues' => $_,
+ }, grep { !$_->{'overdue'} } @issues;
+ my @overdues = map {
+ 'biblio' => $_,
+ 'items' => $_,
+ 'biblioitems' => $_,
+ 'issues' => $_,
+ }, grep { $_->{'overdue'} } @issues;
+ my $news = GetNewsToDisplay( "slip", $branch );
+ my @news = map {
+ $_->{'timestamp'} = $_->{'newdate'};
+ { opac_news => $_ }
+ } @$news;
$letter_code = 'ISSUESLIP';
- %repeat = (
- 'checkedout' => [ map {
- 'biblio' => $_,
- 'items' => $_,
- 'biblioitems' => $_,
- 'issues' => $_,
- }, grep { !$_->{'overdue'} } @issues ],
-
- 'overdue' => [ map {
- 'biblio' => $_,
- 'items' => $_,
- 'biblioitems' => $_,
- 'issues' => $_,
- }, grep { $_->{'overdue'} } @issues ],
-
- 'news' => [ map {
- $_->{'timestamp'} = $_->{'newdate'};
- { opac_news => $_ }
- } @{ GetNewsToDisplay("slip",$branch) } ],
+ %repeat = (
+ checkedout => \@checkouts,
+ overdue => \@overdues,
+ news => \@news,
+ );
+ %loops = (
+ issues => [ map { $_->{issues}{itemnumber} } @checkouts ],
+ overdues => [ map { $_->{issues}{itemnumber} } @overdues ],
+ opac_news => [ map { $_->{opac_news}{idnew} } @news ],
);
}
@@ -1182,6 +1193,7 @@ sub IssueSlip {
'borrowers' => $borrowernumber,
},
repeat => \%repeat,
+ loops => \%loops,
);
}
diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t
index 075b6f4250..95973ed875 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 => 5;
+ plan tests => 6;
my $library = $builder->build( { source => 'Branch' } );
my $patron = $builder->build( { source => 'Borrower' } );
@@ -316,6 +316,19 @@ subtest 'regression tests' => sub {
itemcallnumber => 'itemcallnumber2',
}
)->store->unblessed;
+ my $biblio3 = Koha::Biblio->new({title => 'Test Biblio 3'})->store->unblessed;
+ my $biblioitem3 = Koha::Biblioitem->new({biblionumber => $biblio3->{biblionumber}})->store()->unblessed;
+ my $item3 = Koha::Item->new(
+ {
+ biblionumber => $biblio3->{biblionumber},
+ biblioitemnumber => $biblioitem3->{biblioitemnumber},
+ barcode => 'another_t_barcode_3',
+ homebranch => $library->{branchcode},
+ holdingbranch => $library->{branchcode},
+ itype => 'BK',
+ itemcallnumber => 'itemcallnumber3',
+ }
+ )->store->unblessed;
C4::Context->_new_userenv('xxx');
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', '');
@@ -582,6 +595,129 @@ EOF
is( $tt_letter_for_item1->{content}, $letter_for_item1->{content}, );
is( $tt_letter_for_item2->{content}, $letter_for_item2->{content}, );
};
+
+ subtest 'ISSUESLIP|checkedout|repeat' => sub {
+ plan tests => 2;
+
+ my $code = 'ISSUESLIP';
+
+ my $branchcode = $library->{branchcode};
+
+ Koha::News->delete;
+ my $news_item = Koha::NewsItem->new({ branchcode => $branchcode, title => "A wonderful news", content => "This is the wonderful news." })->store;
+
+ # historic syntax
+ my $template = <<>
+Checked out to <> <> <> <>
+(<>)
+
+<>
+
+Checked Out
+
+
+<>
+Barcode: <>
+Date due: <>
+
+
+
+Overdues
+
+
+<>
+Barcode: <>
+Date due: <>
+
+
+
+
+
+News
+
+
+
+EOF
+
+ reset_template( { template => $template, code => $code, module => 'circulation' } );
+
+ C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
+ my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
+
+ C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
+ my $yesterday = dt_from_string->subtract( days => 1 );
+ C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
+ my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
+
+ # Cleanup
+ AddReturn( $item1->{barcode} );
+ AddReturn( $item2->{barcode} );
+ AddReturn( $item3->{barcode} );
+
+ # TT syntax
+ my $tt_template = <[% branch.branchname %]
+Checked out to [% borrower.title %] [% borrower.firstname %] [% borrower.initials %] [% borrower.surname %]
+([% borrower.cardnumber %])
+
+[% today | \$KohaDates with_hours => 1 %]
+
+Checked Out
+[% FOREACH checkout IN checkouts %]
+[%~ SET item = checkout.item %]
+[%~ SET biblio = checkout.item.biblio %]
+
+[% biblio.title %]
+Barcode: [% item.barcode %]
+Date due: [% checkout.date_due | \$KohaDates %]
+
+[% END %]
+
+Overdues
+[% FOREACH overdue IN overdues %]
+[%~ SET item = overdue.item %]
+[%~ SET biblio = overdue.item.biblio %]
+
+[% biblio.title %]
+Barcode: [% item.barcode %]
+Date due: [% overdue.date_due | \$KohaDates %]
+
+[% END %]
+
+
+
+News
+[% FOREACH n IN news %]
+
+
[% n.title %]
+
[% n.content %]
+
+
+
+[% END %]
+EOF
+
+ reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
+
+ C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
+ my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
+
+ C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
+ C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
+ my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
+
+ # There is too many line breaks generated by the historic syntax
+ $second_slip->{content} =~ s|
\n\n\n|
\n\n|s;
+
+ is( $first_tt_slip->{content}, $first_slip->{content}, );
+ is( $second_tt_slip->{content}, $second_slip->{content}, );
+ };
};
subtest 'loops' => sub {
--
2.20.1