Bugzilla – Attachment 65683 Details for
Bug 17966
TT syntax for notices - Prove that ISSUESLIP is compatible
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17966: TT syntax for notices - Prove that ISSUESLIP is compatible
0001-Bug-17966-TT-syntax-for-notices-Prove-that-ISSUESLIP.patch (text/plain), 10.93 KB, created by
Kyle M Hall (khall)
on 2017-08-08 17:56:11 UTC
(
hide
)
Description:
Bug 17966: TT syntax for notices - Prove that ISSUESLIP is compatible
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2017-08-08 17:56:11 UTC
Size:
10.93 KB
patch
obsolete
>From 5624489942e4810cd12ad831c2434987de56faae Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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 <checkedout> and <overdue>. >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 <kyle@bywatersolutions.com> > >https://bugs.koha-community.org/show_bug.cgi?id=17969 >--- > 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 de8253b..e24d556 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 3726e00..166b051 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 075b6f4..95973ed 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 = <<EOF; >+<h3><<branches.branchname>></h3> >+Checked out to <<borrowers.title>> <<borrowers.firstname>> <<borrowers.initials>> <<borrowers.surname>> <br /> >+(<<borrowers.cardnumber>>) <br /> >+ >+<<today>><br /> >+ >+<h4>Checked Out</h4> >+<checkedout> >+<p> >+<<biblio.title>> <br /> >+Barcode: <<items.barcode>><br /> >+Date due: <<issues.date_due | dateonly>><br /> >+</p> >+</checkedout> >+ >+<h4>Overdues</h4> >+<overdue> >+<p> >+<<biblio.title>> <br /> >+Barcode: <<items.barcode>><br /> >+Date due: <<issues.date_due | dateonly>><br /> >+</p> >+</overdue> >+ >+<hr> >+ >+<h4 style="text-align: center; font-style:italic;">News</h4> >+<news> >+<div class="newsitem"> >+<h5 style="margin-bottom: 1px; margin-top: 1px"><b><<opac_news.title>></b></h5> >+<p style="margin-bottom: 1px; margin-top: 1px"><<opac_news.content>></p> >+<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on <<opac_news.timestamp>></p> >+<hr /> >+</div> >+</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 = <<EOF; >+<h3>[% branch.branchname %]</h3> >+Checked out to [% borrower.title %] [% borrower.firstname %] [% borrower.initials %] [% borrower.surname %] <br /> >+([% borrower.cardnumber %]) <br /> >+ >+[% today | \$KohaDates with_hours => 1 %]<br /> >+ >+<h4>Checked Out</h4> >+[% FOREACH checkout IN checkouts %] >+[%~ SET item = checkout.item %] >+[%~ SET biblio = checkout.item.biblio %] >+<p> >+[% biblio.title %] <br /> >+Barcode: [% item.barcode %]<br /> >+Date due: [% checkout.date_due | \$KohaDates %]<br /> >+</p> >+[% END %] >+ >+<h4>Overdues</h4> >+[% FOREACH overdue IN overdues %] >+[%~ SET item = overdue.item %] >+[%~ SET biblio = overdue.item.biblio %] >+<p> >+[% biblio.title %] <br /> >+Barcode: [% item.barcode %]<br /> >+Date due: [% overdue.date_due | \$KohaDates %]<br /> >+</p> >+[% END %] >+ >+<hr> >+ >+<h4 style="text-align: center; font-style:italic;">News</h4> >+[% FOREACH n IN news %] >+<div class="newsitem"> >+<h5 style="margin-bottom: 1px; margin-top: 1px"><b>[% n.title %]</b></h5> >+<p style="margin-bottom: 1px; margin-top: 1px">[% n.content %]</p> >+<p class="newsfooter" style="font-size: 8pt; font-style:italic; margin-bottom: 1px; margin-top: 1px">Posted on [% n.timestamp | \$KohaDates %]</p> >+<hr /> >+</div> >+[% 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|</p>\n\n\n<p>|</p>\n\n<p>|s; >+ >+ is( $first_tt_slip->{content}, $first_slip->{content}, ); >+ is( $second_tt_slip->{content}, $second_slip->{content}, ); >+ }; > }; > > subtest 'loops' => sub { >-- >2.1.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17966
:
59450
|
63975
|
65683
|
66773