Bugzilla – Attachment 59428 Details for
Bug 17962
TT syntax for notices - Prove that ACQ_NOTIF_ON_RECEIV is compatible
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17962: TT syntax for notices - Prove that ACQ_NOTIF_ON_RECEIV is compatible
Bug-17962-TT-syntax-for-notices---Prove-that-ACQNO.patch (text/plain), 6.14 KB, created by
Jonathan Druart
on 2017-01-23 15:25:33 UTC
(
hide
)
Description:
Bug 17962: TT syntax for notices - Prove that ACQ_NOTIF_ON_RECEIV is compatible
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-01-23 15:25:33 UTC
Size:
6.14 KB
patch
obsolete
>From c6f95738f925e138aceabc0f062df16eeb1a5c6d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 16 Jan 2017 13:25:31 +0100 >Subject: [PATCH] Bug 17962: TT syntax for notices - Prove that > ACQ_NOTIF_ON_RECEIV is compatible > >To make ACQ_NOTIF_ON_RECEIV TT compatible, we need to expose data from >the aqorders table. We already have a package for it in the Koha >namespace but it is based on Koha::Object[s]. >The other path creates dummy Koha::Tmp::Order[s] packages to make it >usable. Of course we should use a valid Koha::Acquisition::Order[s] >based on Koha::Object, but it's outside the scope of this bug report. > >This notice template is quite simple, and it's a good one to start. >From C4::Acq::NotifyOrderUsers, GetPreparedLetter is called with 4 >elements: the library, the patron to notify, the biblio and the order >information. >Note that prior to this patch aqorders was filled from GetOrder, which >retrieved a lot of information from the acquisition table (aqbasket, >aqbookseller). The idea with the TT syntax is to access the data from >where it really exists. So if a user wants to display the basket name, >[% order.basket.basketname %] should be used instead. >Note that this will not work at the moment, the basket method is not >defined in the order package. > >However the basic template should work as before. >The test added to TemplateToolkit proves that. > >Test plan: >Use the default ACQ_NOTIF_ON_RECEIV to notify a patron that an order has >been received. >That generated template should be exactly the same as prior to this >patch. >--- > C4/Letters.pm | 6 +++ > t/db_dependent/Letters/TemplateToolkit.t | 88 +++++++++++++++++++++++++++++++- > 2 files changed, 93 insertions(+), 1 deletion(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 3ff39b1..29e54c8 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -1498,6 +1498,12 @@ sub _get_tt_params { > plural => 'news', > pk => 'idnew', > }, >+ aqorders => { >+ module => 'Koha::Tmp::Orders', # Should Koha::Acquisition::Orders when will be based on Koha::Objects >+ singular => 'order', >+ plural => 'orders', >+ pk => 'ordernumber', >+ }, > reserves => { > module => 'Koha::Holds', > singular => 'hold', >diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t >index bdcfb96..9bf8033 100644 >--- a/t/db_dependent/Letters/TemplateToolkit.t >+++ b/t/db_dependent/Letters/TemplateToolkit.t >@@ -18,7 +18,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 15; >+use Test::More tests => 16; > use Test::Warn; > > use MARC::Record; >@@ -39,6 +39,7 @@ use Koha::Serial; > use Koha::Subscription; > use Koha::Suggestion; > use Koha::Checkout; >+use Koha::Notice::Templates; > use Koha::Patron::Modification; > > my $schema = Koha::Database->schema; >@@ -279,3 +280,88 @@ $prepared_letter = GetPreparedLetter( > ) > ); > is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' ); >+ >+subtest 'regression tests' => sub { >+ plan tests => 1; >+ >+ my $library = $builder->build( { source => 'Branch' } ); >+ my $patron = $builder->build( { source => 'Borrower' } ); >+ my $biblio = Koha::Biblio->new({title => 'Test Biblio'})->store->unblessed; >+ my $biblioitem = Koha::Biblioitem->new({biblionumber => $biblio->{biblionumber}})->store()->unblessed; >+ my $item1 = Koha::Item->new( >+ { >+ biblionumber => $biblio->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ } >+ )->store->unblessed; >+ my $item2 = Koha::Item->new( >+ { >+ biblionumber => $biblio->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ } >+ )->store->unblessed; >+ >+ subtest 'ACQ_NOTIF_ON_RECEIV ' => sub { >+ plan tests => 1; >+ my $code = 'ACQ_NOTIF_ON_RECEIV'; >+ my $branchcode = $library->{branchcode}; >+ my $order = $builder->build({ source => 'Aqorder' }); >+ >+ my $template = q| >+ Dear <<borrowers.firstname>> <<borrowers.surname>>, >+ The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received. >+ Your library. >+ |; >+ my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron, biblio => $biblio, aqorders => $order } }; >+ my $letter = process_letter( { template => $template, %$params }); >+ my $tt_template = q| >+ Dear [% borrower.firstname %] [% borrower.surname %], >+ The order [% order.ordernumber %] ([% biblio.title %]) has been received. >+ Your library. >+ |; >+ my $tt_letter = process_letter( { template => $tt_template, %$params }); >+ >+ is( $tt_letter->{content}, $letter->{content}, ); >+ }; >+}; >+ >+sub reset_template { >+ my ( $params ) = @_; >+ my $template = $params->{template}; >+ my $code = $params->{code}; >+ my $module = $params->{module} || 'test_module'; >+ >+ Koha::Notice::Templates->search( { code => $code } )->delete; >+ Koha::Notice::Template->new( >+ { >+ module => $module, >+ code => $code, >+ branchcode => '', >+ name => $code, >+ title => $code, >+ message_transport_type => 'email', >+ content => $template >+ } >+ )->store; >+} >+ >+sub process_letter { >+ my ($params) = @_; >+ my $template = $params->{template}; >+ my $tables = $params->{tables}; >+ my $substitute = $params->{substitute}; >+ my $code = $params->{code}; >+ my $module = $params->{module} || 'test_module'; >+ my $branchcode = $params->{branchcode}; >+ >+ reset_template( $params ); >+ >+ my $letter = C4::Letters::GetPreparedLetter( >+ module => $module, >+ letter_code => $code, >+ branchcode => '', >+ tables => $tables, >+ substitute => $substitute, >+ ); >+ return $letter; >+} >-- >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 17962
:
59428
|
59429
|
59525
|
59526