Description
Alex Arnaud
2018-02-01 10:23:10 UTC
Created attachment 71106 [details] [review] Bug 20119 - Ability to print claims for late orders Created attachment 71107 [details] [review] Bug 20119 - Add a script to claim late orders (ordersClaim.pl) Hi Alex, maybe this should be 2 bugs? Also please make sure to add test plans and a bit more information to your commit messages! By splitting into 2 bugs with better descriptions this will also stand out more in the release notes :) (In reply to Katrin Fischer from comment #4) > By splitting into 2 bugs with better descriptions this will also stand out > more in the release notes :) You are right. Comment on attachment 71107 [details] [review] Bug 20119 - Add a script to claim late orders (ordersClaim.pl) >From 2c7a930cf6e6cb12b4a7963d34e86bbfde0ceb42 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Wed, 31 Jan 2018 15:16:16 +0000 >Subject: [PATCH] Bug 20119 - Add a script to claim late orders > (ordersClaim.pl) > >--- > misc/cronjobs/ordersClaim.pl | 162 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 162 insertions(+) > create mode 100755 misc/cronjobs/ordersClaim.pl > >diff --git a/misc/cronjobs/ordersClaim.pl b/misc/cronjobs/ordersClaim.pl >new file mode 100755 >index 0000000..a0d046c >--- /dev/null >+++ b/misc/cronjobs/ordersClaim.pl >@@ -0,0 +1,162 @@ >+#!/usr/bin/perl >+ >+# Copyright 2018 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 >+ >+ordersClaim.pl - cron script that put late orders in message queue grouped by basket. >+ >+=head1 SYNOPSIS >+ >+./ordersClaim.pl --delay 40 --claimed-for 10 --max-claims 3 >+ >+=head1 DESCRIPTION >+ >+This script get all late orders (depending on --delay parameter, >+group them by basket and put an entry in message_queue table. >+ >+=cut >+ >+use Modern::Perl; >+ >+use Getopt::Long; >+use Pod::Usage; >+ >+use C4::Letters; >+use C4::Acquisition; >+ >+=head1 NAME >+ >+ordersClaim.pl - cron script that put late orders in message queue grouped by basket. >+ >+=head1 SYNOPSIS >+ >+perl ordersClaim.pl >+ [ --delay|d <number of days> ][ --claimed-for|c <number of days> ][ --max-claims <number of claims> ] >+ >+=head1 OPTIONS >+ >+=over >+ >+=item B<--help> >+ >+Print a brief help message and exits. >+ >+=item B<--delay> >+ >+Number of days from which an orders is considered as late. >+Default is the booseller's delivery time or 0. >+ >+=item B<--claimed-for> >+ >+Minimum number of days since the last claim. Default is 0. >+ >+=item B<--max-claim> >+ >+Number of claims beyond which we stop sending others. >+Default is 1; >+ >+=cut >+ >+my $help; >+my $delay; >+my $claimed_for = 0; >+my $max_claims = 1; >+ >+GetOptions( >+ 'help|?' => \$help, >+ 'delay|d:i' => \$delay, >+ 'claimed-for|c:i' => \$claimed_for, >+ 'max-claims|m:i' => \$max_claims, >+) or pod2usage(1); >+ >+pod2usage(1) if $help; >+ >+my @lateorders = GetLateOrders( ($delay) ); >+ >+# Sort orders by basket >+my $baskets_orders; >+push @{ $baskets_orders->{ $_->{basketno} } }, $_->{ordernumber} for @lateorders; >+ >+while (my ($basketno, $orderids) = each %$baskets_orders) { >+ my $schema = Koha::Database->new->schema; >+ >+ my $basket = $schema->resultset('Aqbookseller')->find( >+ { id => $basketno }, >+ { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); >+ >+ my $booksellerid = $basket->{booksellerid}; >+ my $bookseller = $schema->resultset('Aqbookseller')->find( >+ { id => $booksellerid }, >+ { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); >+ >+ my $contact = $schema->resultset('Aqcontact')->find( >+ { booksellerid => $booksellerid, claimacquisition => 1 }, >+ { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); >+ >+ unless ( defined( $delay ) ) { >+ $delay = $bookseller->{deliverytime} || 0; >+ } >+ >+ my $dbh = C4::Context->dbh; >+ >+ my $orderids_str = join(',', ('?') x @$orderids); >+ my $orders = $dbh->selectall_arrayref(qq{ >+ SELECT aqorders.*, aqbasket.*, biblio.* >+ FROM aqorders >+ LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber >+ LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno >+ WHERE aqorders.ordernumber IN ($orderids_str) >+ AND aqorders.claims_count < $max_claims >+ AND (aqorders.claimed_date IS NULL or aqorders.claimed_date <= DATE_SUB(CAST(now() AS date),INTERVAL $claimed_for DAY)) >+ }, {Slice => {}}, @$orderids); >+ >+ next unless @$orders; >+ >+ my $letter = GetPreparedLetter( >+ module => 'claimacquisition', >+ letter_code => 'ACQCLAIM', >+ message_transport_type => 'email', >+ tables => { >+ 'aqbooksellers' => $bookseller, >+ 'aqcontacts' => $contact, >+ 'aqbasket' => $basket >+ }, >+ repeat => $orders, >+ ) or next; >+ >+ my $admin_address = C4::Context->preference('KohaAdminEmailAddress'); >+ my $id = C4::Letters::EnqueueLetter({ >+ letter => $letter, >+ from_address => $admin_address, >+ to_address => $contact->{email}, >+ message_transport_type => $letter->{message_transport_type} >+ }); >+ >+ continue unless $id >+ >+ my $today = Koha::DateUtils::dt_from_string; >+ foreach my $o ( @$orders ) { >+ my $order = $schema->resultset('Aqorder')->find($o->{ordernumber}); >+ my $count = $order->get_column('claims_count') || 0; >+ $order->set_columns({ >+ claimed_date => $today->ymd, >+ claims_count => $count+1 >+ })->update_or_insert; >+ } >+} >-- >2.7.4 Created attachment 71150 [details] [review] Bug 20119 - Ability to print claims for late orders Test plan: - create a notice: module: claimacquisition, code: ACQCLAIM: transport: print - create at least a bookseller, basket and orders, - close the basket and change the closedate to make orders late, - go to cgi-bin/koha/acqui/lateorders.pl, - select one or more order(s) to claim and click on "Print claim", - check the pdf downloaded Created attachment 71151 [details] [review] Bug 20119 - Add unit tests Applying: Bug 20119 - Ability to print claims for late orders Using index info to reconstruct a base tree... M C4/Letters.pm M koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt Falling back to patching base and 3-way merge... Auto-merging koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt CONFLICT (content): Merge conflict in koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt Auto-merging C4/Letters.pm Failed to merge in the changes. Patch failed at 0001 Bug 20119 - Ability to print claims for late orders The copy of the patch that failed is found in: /var/repositories/koha/.git/rebase-apply/patch When you have resolved this problem run "git bz apply --continue". If you would prefer to skip this patch, instead run "git bz apply --skip". To restore the original branch and stop patching run "git bz apply --abort". Patch left in /tmp/Bug-20119---Ability-to-print-claims-for-late-order-II3tjp.patch Created attachment 72928 [details] [review] Bug 20119 - Ability to print claims for late orders Test plan: - create a notice: module: claimacquisition, code: ACQCLAIM: transport: print - create at least a bookseller, basket and orders, - close the basket and change the closedate to make orders late, - go to cgi-bin/koha/acqui/lateorders.pl, - select one or more order(s) to claim and click on "Print claim", - check the pdf downloaded [2018-03-15] Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> Created attachment 72929 [details] [review] Bug 20119 - Add unit tests [2018-03-15] Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> Created attachment 72944 [details] [review] Bug 20119 - Ability to print claims for late orders Test plan: - create a notice: module: claimacquisition, code: ACQCLAIM: transport: print - create at least a bookseller, basket and orders, - close the basket and change the closedate to make orders late, - go to cgi-bin/koha/acqui/lateorders.pl, - select one or more order(s) to claim and click on "Print claim", - check the pdf downloaded [2018-03-15] Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> Created attachment 72945 [details] [review] Bug 20119 - Add unit tests [2018-03-15] Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> The current patch (that works perfectly for pdf export) doesn't update the claims count nor the claimed date. Is it a behaviour we want to keep ? In that case, as the claims count is update only when emailing the vendor, there is no way in Koha to trace the "paper claims". But, in the other hand, there is no garanty that the claim pdf will be send to the vendor, or the date of sending can be different of the one in Koha so it's not necesarly a good idea to update these informations at the printing moment. I don't know which behaviour is better. Could we add a checkbox or a confirmation question? That way the library could decide when the count is updated. (In reply to Katrin Fischer from comment #15) > Could we add a checkbox or a confirmation question? That way the library > could decide when the count is updated. That's a good idea ! Created attachment 125823 [details] [review] Bug 20119 - Ability to print claims for late orders Test plan: - create a notice: module: claimacquisition, code: ACQCLAIM: transport: print - create at least a bookseller, basket and orders, - close the basket and change the closedate to make orders late, - go to cgi-bin/koha/acqui/lateorders.pl, - select one or more order(s) to claim and click on "Print claim", - check the pdf downloaded [2018-03-15] Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> Created attachment 125824 [details] [review] Bug 20119 - Add unit tests [2018-03-15] Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> Created attachment 125825 [details] [review] Bug 20119: Add option to update claims count and claim date Patches rebased on master. I attached a new one that add an option for updating claims count and claim date. Hi Alex, could you please rebase? Apply? [(y)es, (n)o, (i)nteractive] y Applying: Bug 20119 - Ability to print claims for late orders Applying: Bug 20119 - Add unit tests error: sha1 information is lacking or useless (C4/Letters.pm). error: could not build fake ancestor Patch failed at 0001 Bug 20119 - Add unit tests hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem run "git bz apply --continue". If you would prefer to skip this patch, instead run "git bz apply --skip". To restore the original branch and stop patching run "git bz apply --abort". Patch left in /tmp/Bug-20119---Add-unit-tests-BTwZip.patch |