Bugzilla – Attachment 185807 Details for
Bug 20125
Add a cron script to claim late orders
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20125: Add a script to claim late orders (ordersClaim.pl)
Bug-20125-Add-a-script-to-claim-late-orders-orders.patch (text/plain), 7.31 KB, created by
Arthur Suzuki
on 2025-08-27 09:23:06 UTC
(
hide
)
Description:
Bug 20125: Add a script to claim late orders (ordersClaim.pl)
Filename:
MIME Type:
Creator:
Arthur Suzuki
Created:
2025-08-27 09:23:06 UTC
Size:
7.31 KB
patch
obsolete
>From f64cc9a4f0fd23f6480c0267287a46bec49521f2 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 20125: Add a script to claim late orders (ordersClaim.pl) >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Test plan: > > - Put some orders late from different baskets by changing the closedate > column in aqbasket table, > >Testing delay parameters: > - launch "perl misc/cronjobs/ordersClaim.pl" with the following > parameters: > - delay: Up to the number of days from the basket's closedate, > - claimed-for: no matter for the first claim, > - Check that there is one entry in message_queue *for each basket with > late order(s)* > - Check these late orders in database: > - claims_count column should be set to 1, > - claimed_date should be today > >Testing claimed-for parameter: > - change the claimed_date column in database for all orders (i.e 2 days > back), > - launch "perl misc/cronjobs/ordersClaim.pl" again with the following > parameters: > - delay: Same than for the first test, > - claimed-for: 3 (if set claimed_date 2 days back), > - max-claims: at least 2 > - check that there is no new entry in message_queue > - launch "perl misc/cronjobs/ordersClaim.pl" again by moving only > claimed-for to 1 > - There should be new entry in message_queue > - claims_count column should be set to 2 > - claimed_date should be today > >Testing max-claims parameter: > - change the claimed_date column in database for all orders (i.e 2 days > back), > - launch "perl misc/cronjobs/ordersClaim.pl" again with the following > parameters: > - delay: Same than for the first and second test, > - claimed-for: 1 (if set claimed_date 2 days back), > - max-claims: 1 and 2 (test the two options), > - There should be new entry in message_queue > - launch "perl misc/cronjobs/ordersClaim.pl" again by moving only > max-claims to 3 > - There should be new entry in message_queue > - claims_count column should be set to 3 > - claimed_date should be today > >Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> >--- > misc/cronjobs/ordersClaim.pl | 166 +++++++++++++++++++++++++++++++++++ > 1 file changed, 166 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 00000000000..280f7a3fba1 >--- /dev/null >+++ b/misc/cronjobs/ordersClaim.pl >@@ -0,0 +1,166 @@ >+#!/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 to automatically generate late order claims in the 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 qw( GetPreparedLetter EnqueueLetter ); >+use Koha::Acquisition::Orders; >+ >+=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; >+ >+=back >+ >+=cut >+ >+my $help; >+my $delay; >+my $claimed_for = 0; >+my $max_claims = 1; >+my $letter_code = 'ACQCLAIM'; >+ >+GetOptions( >+ 'help|?' => \$help, >+ 'delay|d:i' => \$delay, >+ 'claimed-for|c:i' => \$claimed_for, >+ 'max-claims|m:i' => \$max_claims, >+ 'letter-code|l:s' => \$letter_code, >+) or pod2usage(1); >+ >+pod2usage(1) if $help; >+ >+my @lateorders = Koha::Acquisition::Orders->filter_by_lates( { delay => $delay } )->as_list; >+ >+# 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 = Koha::Acquisition::Baskets->find($basketno); >+ >+ my $booksellerid = $basket->booksellerid; >+ my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid); >+ >+ 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.*, >+ COUNT(aqorders_claims.claimed_on) AS claims_count, >+ MAX(aqorders_claims.claimed_on) AS last_claim >+ FROM aqorders >+ LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber >+ LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno >+ LEFT JOIN aqorders_claims ON aqorders.ordernumber = aqorders_claims.ordernumber >+ WHERE aqorders.ordernumber IN ($orderids_str) >+ HAVING claims_count <= $max_claims >+ AND (last_claim IS NULL or last_claim <= DATE_SUB(CAST(now() AS date),INTERVAL $claimed_for DAY)) >+ }, { Slice => {} }, @$orderids >+ ); >+ >+ next unless @$orders; >+ >+ my $letter = GetPreparedLetter( >+ module => 'claimacquisition', >+ letter_code => $letter_code, >+ message_transport_type => 'email', >+ tables => { >+ 'aqbooksellers' => $bookseller->unblessed, >+ 'aqcontacts' => $contact, >+ 'aqbasket' => $basket->unblessed >+ }, >+ repeat => $orders, >+ ) or next; >+ >+ my $from_address = C4::Context->preference('KohaAdminEmailAddress'); >+ if ( my $library = Koha::Libraries->find( $basket->branch ) ) { >+ $from_address = $library->branchemail || $from_address; >+ } >+ >+ my $id = C4::Letters::EnqueueLetter( >+ { >+ letter => $letter, >+ from_address => $from_address, >+ to_address => $contact->{email}, >+ message_transport_type => $letter->{message_transport_type} >+ } >+ ); >+ >+ continue unless $id; >+ >+ Koha::Acquisition::Orders->find( $_->{ordernumber} )->claim() for @$orders; >+} >-- >2.39.5
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 20125
:
71139
|
71274
|
74767
|
74837
|
74838
|
74839
|
112977
|
112981
| 185807