From 66c9381a273add7649572965924d40a1e290e786 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Tue, 24 Apr 2018 14:30:22 +0000 Subject: [PATCH] Bug 20125: QA followup - fix a QA script warning - rename script description - add letter-code parameter to ordersClaim script - use, in order, library email or admin email as from address --- misc/cronjobs/ordersClaim.pl | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/misc/cronjobs/ordersClaim.pl b/misc/cronjobs/ordersClaim.pl index 3ce5643..776dbf3 100755 --- a/misc/cronjobs/ordersClaim.pl +++ b/misc/cronjobs/ordersClaim.pl @@ -19,7 +19,7 @@ =head1 NAME -ordersClaim.pl - cron script that put late orders in message queue grouped by basket. +ordersClaim.pl - cron script to automatically generate late order claims in the message queue grouped by basket. =head1 SYNOPSIS @@ -71,18 +71,20 @@ Minimum number of days since the last claim. Default is 0. Number of claims beyond which we stop sending others. Default is 1; -=cut +=back 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; @@ -96,11 +98,9 @@ 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 $basket = Koha::Acquisition::Baskets->find( $basketno ); - my $booksellerid = $basket->{booksellerid}; + my $booksellerid = $basket->booksellerid; my $bookseller = $schema->resultset('Aqbookseller')->find( { id => $booksellerid }, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); @@ -130,20 +130,24 @@ while (my ($basketno, $orderids) = each %$baskets_orders) { my $letter = GetPreparedLetter( module => 'claimacquisition', - letter_code => 'ACQCLAIM', + letter_code => $letter_code, message_transport_type => 'email', tables => { 'aqbooksellers' => $bookseller, 'aqcontacts' => $contact, - 'aqbasket' => $basket + 'aqbasket' => $basket->unblessed }, repeat => $orders, ) or next; - my $admin_address = C4::Context->preference('KohaAdminEmailAddress'); + 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 => $admin_address, + from_address => $from_address, to_address => $contact->{email}, message_transport_type => $letter->{message_transport_type} }); -- 2.7.4