Bugzilla – Attachment 64195 Details for
Bug 18783
Allow automatic claims for serials
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18783: Allow automatic claims for serials
Bug-18783-Allow-automatic-claims-for-serials.patch (text/plain), 17.63 KB, created by
Julian Maurice
on 2017-06-12 10:45:06 UTC
(
hide
)
Description:
Bug 18783: Allow automatic claims for serials
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2017-06-12 10:45:06 UTC
Size:
17.63 KB
patch
obsolete
>From 7bb050c1a3b79fdb200ee45544254a620b21af92 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Mon, 12 Jun 2017 11:51:43 +0200 >Subject: [PATCH] Bug 18783: Allow automatic claims for serials > >This patch adds a new script misc/cronjobs/serialsClaim.pl which send >email notification to all suppliers that have late or missing issues. >This is configurable per subscription and is disabled by default. > >Test plan: >1. Create a new bookseller B1 with a delivery time of 5 days >2. Create a new daily subscription with bookseller B1 and enable > automatic claims (new checkbox on the first page of > subscription-add.pl) >3. Generate some late serials with an expected date in the past (some > with more than 5 days in the past, some with less) >4. Create a notice for module "Claim serial issue" CLAIMSERIAL and write > something in the 'Email' template >5. Run `misc/cronjobs/serialsClaims.pl --letter-code CLAIMSERIAL` and > verify that it sends an email notification only for serials that were > expected more than 5 days ago >--- > C4/Letters.pm | 9 +- > C4/Serials.pm | 30 +++--- > installer/data/mysql/atomicupdate/bug_18783.perl | 12 +++ > installer/data/mysql/kohastructure.sql | 1 + > .../prog/en/modules/serials/subscription-add.tt | 8 ++ > .../prog/en/modules/serials/subscription-detail.tt | 1 + > misc/cronjobs/serialsClaim.pl | 117 +++++++++++++++++++++ > serials/subscription-add.pl | 6 +- > t/db_dependent/Serials.t | 16 ++- > 9 files changed, 181 insertions(+), 19 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_18783.perl > create mode 100755 misc/cronjobs/serialsClaim.pl > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index cd7b785c96..dc963c7d91 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -576,11 +576,18 @@ sub SendAlerts { > $letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; > > # ... then send mail >+ my $from; > my $library = Koha::Libraries->find( $userenv->{branch} ); >+ if ($library and $library->branchemail) { >+ $from = $library->branchemail; >+ } else { >+ $from = C4::Context->preference('KohaAdminEmailAddress'); >+ } >+ > my %mail = ( > To => join( ',', @email), > Cc => join( ',', @cc), >- From => $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'), >+ From => $from, > Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), > Message => $letter->{'is_html'} > ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ), >diff --git a/C4/Serials.pm b/C4/Serials.pm >index 939cc8b8f8..f70a4704f6 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -343,7 +343,8 @@ sub GetFullSubscription { > my $sth = $dbh->prepare($query); > $sth->execute($subscriptionid); > my $subscriptions = $sth->fetchall_arrayref( {} ); >- my $cannotedit = not can_edit_subscription( $subscriptions->[0] ) if scalar @$subscriptions; >+ my $cannotedit; >+ $cannotedit = not can_edit_subscription( $subscriptions->[0] ) if scalar @$subscriptions; > for my $subscription ( @$subscriptions ) { > $subscription->{cannotedit} = $cannotedit; > } >@@ -366,9 +367,6 @@ sub PrepareSerialsData { > my $year; > my @res; > my $startdate; >- my $aqbooksellername; >- my $bibliotitle; >- my @loopissues; > my $first; > my $previousnote = ""; > >@@ -503,7 +501,8 @@ sub GetFullSubscriptionsFromBiblionumber { > my $sth = $dbh->prepare($query); > $sth->execute($biblionumber); > my $subscriptions = $sth->fetchall_arrayref( {} ); >- my $cannotedit = not can_edit_subscription( $subscriptions->[0] ) if scalar @$subscriptions; >+ my $cannotedit; >+ $cannotedit = not can_edit_subscription( $subscriptions->[0] ) if scalar @$subscriptions; > for my $subscription ( @$subscriptions ) { > $subscription->{cannotedit} = $cannotedit; > } >@@ -1348,9 +1347,11 @@ sub ModSubscription { > $biblionumber, $callnumber, $notes, $letter, $manualhistory, > $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, > $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, >- $itemtype, $previousitemtype >+ $itemtype, $previousitemtype, $auto_claim_enabled > ) = @_; > >+ $auto_claim_enabled //= 0; >+ > my $dbh = C4::Context->dbh; > my $query = "UPDATE subscription > SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?, >@@ -1361,7 +1362,8 @@ sub ModSubscription { > callnumber=?, notes=?, letter=?, manualhistory=?, > internalnotes=?, serialsadditems=?, staffdisplaycount=?, > opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, >- skip_serialseq=?, itemtype=?, previousitemtype=? >+ skip_serialseq=?, itemtype=?, previousitemtype=?, >+ auto_claim_enabled=? > WHERE subscriptionid = ?"; > > my $sth = $dbh->prepare($query); >@@ -1375,7 +1377,7 @@ sub ModSubscription { > $letter, ($manualhistory ? $manualhistory : 0), > $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, > $graceperiod, $location, $enddate, $skip_serialseq, >- $itemtype, $previousitemtype, >+ $itemtype, $previousitemtype, $auto_claim_enabled, > $subscriptionid > ); > my $rows = $sth->rows; >@@ -1409,8 +1411,12 @@ sub NewSubscription { > $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, > $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, > $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, >- $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype >+ $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, >+ $auto_claim_enabled > ) = @_; >+ >+ $auto_claim_enabled //= 0; >+ > my $dbh = C4::Context->dbh; > > #save subscription (insert into database) >@@ -1423,8 +1429,8 @@ sub NewSubscription { > irregularity, numberpattern, locale, callnumber, > manualhistory, internalnotes, serialsadditems, staffdisplaycount, > opacdisplaycount, graceperiod, location, enddate, skip_serialseq, >- itemtype, previousitemtype) >- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) >+ itemtype, previousitemtype, auto_claim_enabled) >+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) > |; > my $sth = $dbh->prepare($query); > $sth->execute( >@@ -1435,7 +1441,7 @@ sub NewSubscription { > $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, > $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, > $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, >- $itemtype, $previousitemtype >+ $itemtype, $previousitemtype, $auto_claim_enabled > ); > > my $subscriptionid = $dbh->{'mysql_insertid'}; >diff --git a/installer/data/mysql/atomicupdate/bug_18783.perl b/installer/data/mysql/atomicupdate/bug_18783.perl >new file mode 100644 >index 0000000000..6ed890456e >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_18783.perl >@@ -0,0 +1,12 @@ >+$DBversion = 'XXX'; >+if ( CheckVersion($DBversion) ) { >+ if ( !column_exists('subscription', 'auto_claim_enabled') ) { >+ $dbh->do(q{ >+ ALTER TABLE subscription >+ ADD COLUMN auto_claim_enabled tinyint NOT NULL DEFAULT 0 AFTER previousitemtype >+ }); >+ } >+ >+ SetVersion($DBversion); >+ print "Upgrade to $DBversion done (Bug 18783 - Automatic claims for serials)\n"; >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 4ee93cf01f..3afba93c2f 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -2123,6 +2123,7 @@ CREATE TABLE `subscription` ( -- information related to the subscription > `reneweddate` date default NULL, -- date of last renewal for the subscription > `itemtype` VARCHAR( 10 ) NULL, > `previousitemtype` VARCHAR( 10 ) NULL, >+ `auto_claim_enabled` tinyint NOT NULL DEFAULT 0, -- enable automatic claiming > PRIMARY KEY (`subscriptionid`), > CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE, > CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt >index ff918b057e..5c6918fd53 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt >@@ -684,6 +684,14 @@ $(document).ready(function() { > <input type="text" name="graceperiod" id="graceperiod" value="[% graceperiod %]" size="5"/> day(s) > </li> > <li> >+ <label for="auto_claim_enabled">Enable automatic claims</label> >+ [% IF auto_claim_enabled %] >+ <input type="checkbox" name="auto_claim_enabled" id="auto_claim_enabled" value="1" checked/> >+ [% ELSE %] >+ <input type="checkbox" name="auto_claim_enabled" id="auto_claim_enabled" value="1"/> >+ [% END %] >+ </li> >+ <li> > <label class="widelabel" for="staffdisplaycount">Number of issues to display to staff: </label> > <input type="text" name="staffdisplaycount" id="staffdisplaycount" value="[% staffdisplaycount %]" size="4"/> > </li> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt >index 8c95459d8a..c6c4111170 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt >@@ -110,6 +110,7 @@ $(document).ready(function() { > [% END %] > </li> > <li><span class="label">Grace period:</span> [% graceperiod %]</li> >+ <li><span class="label">Automatic claims:</span> [% IF auto_claim_enabled %]Enabled[% ELSE %]Disabled[% END %]</li> > </ol> > </div> > </div> >diff --git a/misc/cronjobs/serialsClaim.pl b/misc/cronjobs/serialsClaim.pl >new file mode 100755 >index 0000000000..3995f29dea >--- /dev/null >+++ b/misc/cronjobs/serialsClaim.pl >@@ -0,0 +1,117 @@ >+#!/usr/bin/perl >+ >+# Copyright 2017 Biblibre >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+serialsClaims.pl - Send claim notice to suppliers that have late or missing issues >+ >+=head1 SYNOPSIS >+ >+serialsClaims.pl --letter-code LETTER_CODE [--max-claims MAX_CLAIMS] >+ >+Options: >+ --letter-code LETTER_CODE Mandatory. Use letter LETTER_CODE. >+ --max-claims MAX_CLAIMS Send up to MAX_CLAIMS notices >+ >+=cut >+ >+use Modern::Perl; >+ >+use DateTime; >+use Getopt::Long; >+ >+use Koha::Acquisition::Booksellers; >+use Koha::DateUtils; >+use Koha::Subscriptions; >+ >+use C4::Context; >+use C4::Letters; >+use C4::Serials; >+ >+sub usage { >+ return <<EOT >+Usage: $0 --letter-code LETTER_CODE [--max-claims MAX_CLAIMS] >+EOT >+} >+ >+my $letter_code; >+my $max_claims; >+ >+GetOptions( >+ 'letter-code=s' => \$letter_code, >+ 'max-claims=i' => \$max_claims, >+) or die usage(); >+ >+die usage() unless $letter_code; >+ >+my $suppliers = GetSuppliersWithLateIssues(); >+foreach my $supplier (@$suppliers) { >+ my $bookseller = Koha::Acquisition::Booksellers->find($supplier->{id}); >+ my $supplierinfo = $bookseller->name . ' (' . $bookseller->id . ')'; >+ >+ my $deliverytime = $bookseller->deliverytime; >+ unless ($deliverytime) { >+ say STDERR "Warning: There is no delivery time set for supplier $supplierinfo. Automatic claiming is disabled for this supplier."; >+ next; >+ } >+ >+ my @serials = GetLateOrMissingIssues($bookseller->id); >+ my @serialids; >+ foreach my $serial (@serials) { >+ if ($max_claims && $serial->{claims_count} >= $max_claims) { >+ say "Maximum claims count reached for serial " . $serial->{serialid}; >+ next; >+ } >+ >+ my $subscription = Koha::Subscriptions->find($serial->{subscriptionid}); >+ next unless $subscription->auto_claim_enabled; >+ >+ my $claims_count = $serial->{claims_count}; >+ my $date = $serial->{claimdate} ? $serial->{claimdate} : $serial->{planneddate}; >+ my $newclaimdate = dt_from_string($date)->add(days => $deliverytime); >+ my $now = DateTime->now(time_zone => C4::Context->tz); >+ >+ if ($newclaimdate <= $now) { >+ push @serialids, $serial->{serialid}; >+ } >+ } >+ >+ if (@serialids) { >+ my $err; >+ eval { >+ $err = SendAlerts('claimissues', \@serialids, $letter_code); >+ if ( not ref $err or not exists $err->{error} ) { >+ C4::Serials::updateClaim( \@serialids ); >+ } >+ }; >+ if ( $@ ) { >+ say STDERR "Error: $@ while claiming serials " . join(',', @serialids); >+ } elsif ( ref $err and exists $err->{error} ) { >+ if ( $err->{error} eq "no_email" ) { >+ say STDERR "Error: Supplier $supplierinfo has no email"; >+ } elsif ( $err->{error} =~ m|Bad or missing From address| ) { >+ say STDERR "Error: Supplier $supplierinfo has no email"; >+ } else { >+ say STDERR "Error: " . $err->{error}; >+ } >+ } else { >+ say "Claim sent to $supplierinfo for serials " . join(',', @serialids); >+ } >+ } >+} >diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl >index ce7f168e8b..443eab3176 100755 >--- a/serials/subscription-add.pl >+++ b/serials/subscription-add.pl >@@ -321,6 +321,7 @@ sub redirect_add_subscription { > my $itemtype = $query->param('itemtype'); > my $previousitemtype = $query->param('previousitemtype'); > my $skip_serialseq = $query->param('skip_serialseq'); >+ my $auto_claim_enabled = $query->param('auto_claim_enabled'); > > my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } ); > my $enddate = output_pref( { str => scalar $query->param('enddate'), dateonly => 1, dateformat => 'iso' } ); >@@ -342,7 +343,7 @@ sub redirect_add_subscription { > join(";",@irregularity), $numberpattern, $locale, $callnumber, > $manualhistory, $internalnotes, $serialsadditems, > $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, >- $skip_serialseq >+ $skip_serialseq, undef, undef, $auto_claim_enabled > ); > > my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); >@@ -400,6 +401,7 @@ sub redirect_mod_subscription { > my $itemtype = $query->param('itemtype'); > my $previousitemtype = $query->param('previousitemtype'); > my $skip_serialseq = $query->param('skip_serialseq'); >+ my $auto_claim_enabled = $query->param('auto_claim_enabled'); > > # Guess end date > if(!defined $enddate || $enddate eq '') { >@@ -426,7 +428,7 @@ sub redirect_mod_subscription { > $status, $biblionumber, $callnumber, $notes, $letter, > $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, > $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, >- $skip_serialseq, $itemtype, $previousitemtype >+ $skip_serialseq, $itemtype, $previousitemtype, $auto_claim_enabled > ); > > my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); >diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t >index de623fe731..7ec3bcf8e2 100755 >--- a/t/db_dependent/Serials.t >+++ b/t/db_dependent/Serials.t >@@ -355,10 +355,18 @@ $dbh->rollback; > > sub get_biblio { > my $bib = MARC::Record->new(); >- $bib->append_fields( >- MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), >- MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), >- ); >+ >+ if (C4::Context->preference('marcflavour') eq 'UNIMARC') { >+ $bib->append_fields( >+ MARC::Field->new('200', ' ', ' ', f => 'Moffat, Steven'), >+ MARC::Field->new('200', ' ', ' ', a => 'Silence in the library'), >+ ); >+ } else { >+ $bib->append_fields( >+ MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), >+ MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), >+ ); >+ } > my ($bibnum, $bibitemnum) = AddBiblio($bib, ''); > return ($bibnum, $bibitemnum); > } >-- >2.11.0
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 18783
:
64195
|
91428
|
124984
|
155458
|
155462
|
155463