Bugzilla – Attachment 95286 Details for
Bug 23971
Add logging for basket related actions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23971: Add Acq action logging
Bug-23971-Add-Acq-action-logging.patch (text/plain), 11.35 KB, created by
Andrew Isherwood
on 2019-11-12 09:10:29 UTC
(
hide
)
Description:
Bug 23971: Add Acq action logging
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2019-11-12 09:10:29 UTC
Size:
11.35 KB
patch
obsolete
>From 7d0a9d370e18f25668ddb158a8bb6de820d23834 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Tue, 12 Nov 2019 08:45:51 +0000 >Subject: [PATCH] Bug 23971: Add Acq action logging > >This patch adds logging for the following Acq actions: > >- Basket creation >- Basket editing >- Basket approval (via EDI) >- Basket closure >--- > C4/Acquisition.pm | 96 +++++++++++++++++++++- > Koha/EDI.pm | 4 +- > acqui/basket.pl | 15 ++-- > acqui/basketgroup.pl | 3 +- > acqui/basketheader.pl | 3 +- > .../intranet-tmpl/prog/en/modules/tools/viewlog.tt | 4 +- > 6 files changed, 113 insertions(+), 12 deletions(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 75429e7e22..617a65d361 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -19,6 +19,7 @@ package C4::Acquisition; > > > use Modern::Perl; >+use JSON qw(to_json); > use Carp; > use C4::Context; > use C4::Debug; >@@ -26,6 +27,7 @@ use C4::Suggestions; > use C4::Biblio; > use C4::Contract; > use C4::Debug; >+use C4::Log qw(logaction); > use C4::Templates qw(gettemplate); > use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Acquisition::Baskets; >@@ -203,6 +205,23 @@ sub NewBasket { > $basketbooksellernote ||= q{}; > ModBasketHeader( $basket, $basketname, $basketnote, $basketbooksellernote, > $basketcontractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items ); >+ >+ # Log the basket creation >+ # We need the creation timestamp, so need to get the newly created basket >+ my $new_basket = GetBasket($basket); >+ my $bookseller = Koha::Acquisition::Booksellers->find( >+ $new_basket->{booksellerid} >+ ); >+ my $patron = Koha::Patrons->find( $authorisedby ); >+ my $infos = { >+ basketno => $basket, >+ basketname => $new_basket->{basketname}, >+ creationdate => $new_basket->{creationdate}, >+ vendorname => $bookseller->name, >+ created_by => $patron->firstname . ' ' . $patron->surname >+ }; >+ logaction('ACQUISITIONS', 'ADD', $basket, to_json($infos)); >+ > return $basket; > } > >@@ -217,7 +236,7 @@ close a basket (becomes unmodifiable, except for receives) > =cut > > sub CloseBasket { >- my ($basketno) = @_; >+ my ($basketno, $user, $edi_approval) = @_; > my $dbh = C4::Context->dbh; > $dbh->do('UPDATE aqbasket SET closedate=now() WHERE basketno=?', {}, $basketno ); > >@@ -225,6 +244,34 @@ sub CloseBasket { > q{UPDATE aqorders SET orderstatus = 'ordered' WHERE basketno = ? AND orderstatus NOT IN ( 'complete', 'cancelled')}, > {}, $basketno > ); >+ >+ # Log the closure >+ my $basket = GetBasket($basketno); >+ my $bookseller = Koha::Acquisition::Booksellers->find( >+ $basket->{booksellerid} >+ ); >+ my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year); >+ $mon = sprintf '%02d', $mon + 1; >+ $day = sprintf '%02d', $day; >+ $year += 1900; >+ my $action = $edi_approval ? 'APPROVE_BASKET' : 'CLOSE_BASKET'; >+ my $infos = { >+ basketno => $basketno, >+ basketname => $basket->{basketname}, >+ closeddate => "$year-$mon-$day", >+ vendorname => $bookseller->name, >+ }; >+ if ($user) { >+ my $patron = Koha::Patrons->find( $user ); >+ $infos->{closed_by} = $patron->firstname . ' ' . $patron->surname >+ } >+ logaction( >+ 'ACQUISITIONS', >+ $action, >+ $basketno, >+ to_json($infos) >+ ); >+ > return; > } > >@@ -548,6 +595,32 @@ sub ModBasket { > my $sth = $dbh->prepare($query); > $sth->execute(@params); > >+ # Log the basket update >+ my $edited_basket = GetBasket($basketinfo->{'basketno'}); >+ my $bookseller = Koha::Acquisition::Booksellers->find( >+ $edited_basket->{booksellerid} >+ ); >+ my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year); >+ $mon = sprintf '%02d', $mon + 1; >+ $day = sprintf '%02d', $day; >+ $year += 1900; >+ my $infos = { >+ basketno => $basketinfo->{'basketno'}, >+ basketname => $edited_basket->{basketname}, >+ updatedate => "$year-$mon-$day", >+ vendorname => $bookseller->name, >+ }; >+ if ($basketinfo->{borrowernumber}) { >+ my $patron = Koha::Patrons->find( $basketinfo->{borrowernumber} ); >+ $infos->{edited_by} = $patron->firstname . ' ' . $patron->surname; >+ } >+ logaction( >+ 'ACQUISITIONS', >+ 'MODIFY', >+ $basketinfo->{'basketno'}, >+ to_json($infos) >+ ); >+ > return; > } > >@@ -587,7 +660,7 @@ case the AcqCreateItem syspref takes precedence). > =cut > > sub ModBasketHeader { >- my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items) = @_; >+ my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items, $borrowernumber) = @_; > > $is_standing ||= 0; > my $query = qq{ >@@ -605,6 +678,25 @@ sub ModBasketHeader { > my $sth2 = $dbh->prepare($query2); > $sth2->execute($contractnumber,$basketno); > } >+ >+ # Log the basket update >+ my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid); >+ my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year); >+ $mon = sprintf '%02d', $mon + 1; >+ $day = sprintf '%02d', $day; >+ $year += 1900; >+ my $infos = { >+ basketno => $basketno, >+ basketname => $basketname, >+ updatedate => "$year-$mon-$day", >+ vendorname => $bookseller->name, >+ }; >+ if ($borrowernumber) { >+ my $patron = Koha::Patrons->find( $borrowernumber ); >+ $infos->{edited_by} = $patron->firstname . ' ' . $patron->surname; >+ } >+ logaction('ACQUISITIONS', 'MODIFY', $basketno, to_json($infos)); >+ > return; > } > >diff --git a/Koha/EDI.pm b/Koha/EDI.pm >index 0ab4658689..32abcec893 100644 >--- a/Koha/EDI.pm >+++ b/Koha/EDI.pm >@@ -574,7 +574,9 @@ sub process_quote { > basketno => $b, > } > ); >- CloseBasket($b); >+ # Close the basket, passing a flag indicating that this action >+ # originated from an approval >+ CloseBasket($b, undef, 1); > } > } > >diff --git a/acqui/basket.pl b/acqui/basket.pl >index e9bf7cd440..7932a18fd1 100755 >--- a/acqui/basket.pl >+++ b/acqui/basket.pl >@@ -195,7 +195,7 @@ if ( $op eq 'delete_confirm' ) { > if ($confirm) { > my $basketno = $query->param('basketno'); > my $booksellerid = $query->param('booksellerid'); >- $basketno =~ /^\d+$/ and CloseBasket($basketno); >+ $basketno =~ /^\d+$/ and CloseBasket($basketno, $loggedinuser); > # if requested, create basket group, close it and attach the basket > if ($query->param('createbasketgroup')) { > my $branchcode; >@@ -210,7 +210,8 @@ if ( $op eq 'delete_confirm' ) { > closed => 1, > }); > ModBasket( { basketno => $basketno, >- basketgroupid => $basketgroupid } ); >+ basketgroupid => $basketgroupid, >+ borrowernumber => $loggedinuser } ); > print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid='.$booksellerid.'&closed=1'); > } else { > print $query->redirect('/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' . $booksellerid); >@@ -243,7 +244,8 @@ elsif ( $op eq 'ediorder' ) { > $branch = undef if(defined $branch and $branch eq ''); > ModBasket({ > basketno => $basket->{basketno}, >- branch => $branch >+ branch => $branch, >+ borrowernumber => $loggedinuser > }); > print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); > exit; >@@ -536,7 +538,7 @@ sub edi_close_and_order { > if ( create_edi_order($edi_params) ) { > #$template->param( edifile => 1 ); > } >- CloseBasket($basketno); >+ CloseBasket($basketno, $loggedinuser); > > # if requested, create basket group, close it and attach the basket > if ( $query->param('createbasketgroup') ) { >@@ -558,8 +560,9 @@ sub edi_close_and_order { > ); > ModBasket( > { >- basketno => $basketno, >- basketgroupid => $basketgroupid >+ basketno => $basketno, >+ basketgroupid => $basketgroupid, >+ borrowernumber => $loggedinuser > } > ); > print $query->redirect( >diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl >index cc3f9fcc48..cc54d2269d 100755 >--- a/acqui/basketgroup.pl >+++ b/acqui/basketgroup.pl >@@ -308,7 +308,8 @@ if ( $op eq "add" ) { > my $basketno=$input->param('basketno'); > my $basketgroupid=$input->param('basketgroupid'); > ModBasket( { basketno => $basketno, >- basketgroupid => $basketgroupid } ); >+ basketgroupid => $basketgroupid, >+ borrowernumber => $loggedinuser } ); > print $input->redirect("basket.pl?basketno=" . $basketno); > } elsif ( $op eq 'closeandprint') { > # >diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl >index 0eb479ff20..ee4cf647b8 100755 >--- a/acqui/basketheader.pl >+++ b/acqui/basketheader.pl >@@ -154,7 +154,8 @@ if ( $op eq 'add_form' ) { > scalar $input->param('deliveryplace'), > scalar $input->param('billingplace'), > scalar $input->param('is_standing') ? 1 : undef, >- scalar $input->param('create_items') >+ scalar $input->param('create_items'), >+ $loggedinuser > ); > } else { #New basket > $basketno = NewBasket( >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt >index 64afbe27ae..7deb046ffd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt >@@ -57,6 +57,8 @@ > [% CASE 'ADDCIRCMESSAGE' %]Add circulation message > [% CASE 'DELCIRCMESSAGE' %]Delete circulation message > [% CASE 'STATUS_CHANGE' %]Change ILL request status >+[% CASE 'CLOSE_BASKET' %]Close an acquisitions basket >+[% CASE 'APPROVE_BASKET' %]Approve an acquisitions basket > [% CASE 'Run' %]Run > [% CASE %][% action | html %] > [% END %] >@@ -124,7 +126,7 @@ > <option value="">All</option> > [% END %] > >- [% FOREACH actx IN [ 'ADD' 'DELETE' 'MODIFY' 'ISSUE' 'RETURN' 'RENEW' 'CREATE' 'CANCEL' 'SUSPEND' 'RESUME' 'ADDCIRCMESSAGE' 'DELCIRCMESSAGE' 'STATUS_CHANGE' 'CHANGE PASS' 'Run' ] %] >+ [% FOREACH actx IN [ 'ADD' 'DELETE' 'MODIFY' 'ISSUE' 'RETURN' 'RENEW' 'CREATE' 'CANCEL' 'SUSPEND' 'RESUME' 'ADDCIRCMESSAGE' 'DELCIRCMESSAGE' 'STATUS_CHANGE' 'CHANGE PASS' 'Run', 'CLOSE_BASKET', 'APPROVE_BASKET' ] %] > [% IF actions.grep(actx).size %] > <option value="[% actx | html %]" selected="selected">[% PROCESS translate_log_action action=actx %]</option> > [% ELSE %] >-- >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 23971
:
95285
|
95286
|
95885
|
95888
|
96063
|
96064
|
100239
|
100240
|
100241
|
103911
|
103912
|
103913
|
103945
|
108962
|
111300
|
111301
|
111302
|
111303
|
111304
|
111955
|
111956
|
111957
|
111958
|
111959
|
111960
|
112277
|
112278
|
112279
|
112280
|
112281
|
112282
|
112283
|
112284
|
112285
|
112286
|
112287
|
112288
|
112289
|
112290
|
112291
|
112298
|
112299
|
112300
|
112301
|
112302
|
112303
|
112304
|
112305
|
112306
|
112307
|
113384
|
113385
|
113386
|
113387
|
113388
|
113389
|
113390
|
113391
|
113392
|
113393
|
114857
|
114858
|
114859
|
114860
|
114861
|
114862
|
114863
|
114864
|
114865
|
114866
|
114867
|
114905
|
114906
|
114907
|
114908
|
114909
|
114910
|
114911
|
114912
|
114913
|
114914
|
114915
|
114916
|
115976
|
115977
|
115978
|
115979
|
115980
|
115981
|
115982
|
115983
|
115984
|
115985
|
115986
|
119401
|
119402
|
119403
|
119404
|
119405
|
119406
|
119407
|
119408
|
119409
|
119410
|
119411
|
119412
|
119944
|
119946
|
120048