From d9d868b911d1ba18c2bac1993e407168164df168 Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Fri, 10 Aug 2018 05:21:56 +0200 Subject: [PATCH] Bug 15971: Add biblioitems to available fields for serial claim notices and fix notices editor display This fixes 2 related problems: 1) The editor only offered 3 entries from biblio for adding to the notice: title, author, serial It was not clear that actually all fields from biblio can be used. 2) It was not possible to use fields from biblioitems in the notices which left out important fields like the ISSN. The patch adds the biblioitems table and changes the editor to show all entries from biblio and biblioitems table are shown on the left. To test: - Create a subscription - Generate next issue a few times to get late issues - Create a new notice in the "Claim serial issue" module - Use fields from different/all tables - Make sure an email address is set for - the vendor (also check for 'receives claims for late issues') - your staff user - Go to serials > claims - Claim multiple issues - Verify the email is generated and contains the correct information Example notice: Title: <> Author: <> ISSN: <> ISBN: <> Issue: <> -- Signed-off-by: Owen Leonard Signed-off-by: Chris Cormack Signed-off-by: Nick Clemens (cherry picked from commit a002d12888c1e56910a32f28514a59d9a1d9363d) Signed-off-by: Martin Renvoize (cherry picked from commit 00422bf33f48c95aac0dc639e42fe958d0de133b) Signed-off-by: Fridolin Somers --- C4/Letters.pm | 9 ++-- t/db_dependent/Letters.t | 96 +++++++++++++++++++++++++++++++++++++++- tools/letter.pl | 10 +---- 3 files changed, 101 insertions(+), 14 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 4d3208b357..49355882ad 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -492,22 +492,23 @@ sub SendAlerts { if ($type eq 'claimissues') { $strsth = qq{ - SELECT serial.*,subscription.*, biblio.*, aqbooksellers.*, + SELECT serial.*,subscription.*, biblio.*, biblioitems.*, aqbooksellers.*, aqbooksellers.id AS booksellerid FROM serial LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid LEFT JOIN biblio ON serial.biblionumber=biblio.biblionumber + LEFT JOIN biblioitems ON serial.biblionumber = biblioitems.biblionumber LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id WHERE serial.serialid IN ( }; if (!@$externalid){ - carp "No Order selected"; - return { error => "no_order_selected" }; + carp "No issues selected"; + return { error => "no_issues_selected" }; } $strsth .= join( ",", ('?') x @$externalid ) . ")"; - $action = "CLAIM ISSUE"; + $action = "SERIAL CLAIM"; $sthorders = $dbh->prepare($strsth); $sthorders->execute( @$externalid ); $dataorders = $sthorders->fetchall_arrayref( {} ); diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 48b91dc4af..84fbaacb67 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 78; +use Test::More tests => 79; use Test::MockModule; use Test::Warn; @@ -527,6 +527,100 @@ is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notificatio is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully'); } +subtest 'SendAlerts - claimissue' => sub { + plan tests => 8; + + use C4::Serials; + + $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('claimissues','TESTSERIALCLAIM','Serial claim test','Serial claim test','<>|<>|<>|<>');}); + + my $bookseller = Koha::Acquisition::Bookseller->new( + { + name => "my vendor", + address1 => "bookseller's address", + phone => "0123456", + active => 1, + deliverytime => 5, + } + )->store; + my $booksellerid = $bookseller->id; + + Koha::Acquisition::Bookseller::Contact->new( { name => 'Leo Tolstoy', phone => '0123456x2', claimissues => 1, booksellerid => $booksellerid } )->store; + + my $bib = MARC::Record->new(); + if (C4::Context->preference('marcflavour') eq 'UNIMARC') { + $bib->append_fields( + MARC::Field->new('011', ' ', ' ', a => 'xxxx-yyyy'), + MARC::Field->new('200', ' ', ' ', a => 'Silence in the library'), + ); + } else { + $bib->append_fields( + MARC::Field->new('022', ' ', ' ', a => 'xxxx-yyyy'), + MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), + ); + } + my ($biblionumber) = AddBiblio($bib, ''); + + $dbh->do(q|UPDATE subscription_numberpatterns SET numberingmethod='No. {X}' WHERE id=1|); + my $subscriptionid = NewSubscription( + undef, "", $booksellerid, undef, undef, $biblionumber, + '2013-01-01', 1, undef, undef, undef, + undef, undef, undef, undef, undef, undef, + 1, 'public',undef, '2013-01-01', undef, 1, + undef, undef, 0, 'internal', 0, + undef, undef, 0, undef, '2013-12-31', 0 + ); + + my ($serials_count, @serials) = GetSerials($subscriptionid); + my @serialids = ($serials[0]->{serialid}); + + my $err; + warning_like { + $err = SendAlerts( 'claimissues', \@serialids, 'TESTSERIALCLAIM' ) } + qr/^Bookseller .* without emails at/, + "Warn on vendor without email address"; + + $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); + $bookseller->contacts->next->email('testemail@mydomain.com')->store; + + # Ensure that the preference 'LetterLog' is set to logging + t::lib::Mocks::mock_preference( 'LetterLog', 'on' ); + + # SendAlerts needs branchemail or KohaAdminEmailAddress as sender + C4::Context->_new_userenv('DUMMY'); + C4::Context->set_userenv( 0, 0, 0, 'firstname', 'surname', $library->{branchcode}, 'My Library', 0, '', ''); + t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' ); + + { + warning_is { + $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) } + "Fake sendmail", + "SendAlerts is using the mocked sendmail routine (claimissues)"; + is($err, 1, "Successfully sent claim"); + is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent claim"); + is($mail{'Message'}, "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", 'Serial claim letter for 1 issue constructed successfully'); + } + + { + my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); + my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0]; + ModSerialStatus( $serials[0]->{serialid}, "No. 1", $publisheddate, $publisheddate, $publisheddate, '3', 'a note' ); + ($serials_count, @serials) = GetSerials($subscriptionid); + push @serialids, ($serials[1]->{serialid}); + + $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ); + is($mail{'Message'}, "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy\n$serialids[1]|2013-01-01|Silence in the library|xxxx-yyyy", "Serial claim letter for 2 issues constructed successfully"); + + $dbh->do(q{DELETE FROM letter WHERE code = 'TESTSERIALCLAIM';}); + warning_like { + $err = SendAlerts( 'orderacquisition', $basketno , 'TESTSERIALCLAIM' ) } + qr/No orderacquisition TESTSERIALCLAIM letter transported by email/, + "GetPreparedLetter warns about missing notice template"; + is($err->{'error'}, 'no_letter', "No TESTSERIALCLAIM letter was defined"); + } + +}; + subtest 'GetPreparedLetter' => sub { plan tests => 4; diff --git a/tools/letter.pl b/tools/letter.pl index 922207958a..d7565e5a6b 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -230,15 +230,7 @@ sub add_form { push @{$field_selection}, add_fields('aqbooksellers', 'aqbasket', 'aqorders', 'biblio', 'biblioitems'); } elsif ($module eq 'claimissues') { - push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription'); - push @{$field_selection}, - { - value => q{}, - text => '---BIBLIO---' - }; - foreach(qw(title author serial)) { - push @{$field_selection}, {value => "biblio.$_", text => ucfirst $_ }; - } + push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription', 'biblio', 'biblioitems'); } elsif ($module eq 'serial') { push @{$field_selection}, add_fields('branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial'); -- 2.39.5