From 9e32605dc2bdbd57045f6713650b044e1fdbc351 Mon Sep 17 00:00:00 2001 From: Raphael Straub Date: Tue, 1 Apr 2025 13:39:01 +0000 Subject: [PATCH] Bug 39405: (follow-up) Add the parameter borrowernumber to the overwrite_calc_fine plugin hook This patch adds the borrowernumber as a parameter to the overwrite_calc_fine plugin hook. E.g., the borrower is needed for calculating graduated fines. Sponsored-by: Karlsruhe Institute of Technology (KIT) Signed-off-by: Martin Renvoize --- C4/Overdues.pm | 11 ++++++----- t/db_dependent/Koha/Plugins/Overdues.t | 8 +++++++- t/lib/plugins/Koha/Plugin/Test.pm | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 71509e034bd..24176210a48 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -227,11 +227,12 @@ sub CalcFine { my @fines = grep { defined $_ } Koha::Plugins->call( 'overwrite_calc_fine', { - itemnumber => $item->{itemnumber}, - categorycode => $bortype, - branchcode => $branchcode, - due_date => $due_dt, - end_date => $end_date, + itemnumber => $item->{itemnumber}, + borrowernumber => $item->{borrowernumber}, + categorycode => $bortype, + branchcode => $branchcode, + due_date => $due_dt, + end_date => $end_date, } ); diff --git a/t/db_dependent/Koha/Plugins/Overdues.t b/t/db_dependent/Koha/Plugins/Overdues.t index edde9f9d126..d044817c176 100755 --- a/t/db_dependent/Koha/Plugins/Overdues.t +++ b/t/db_dependent/Koha/Plugins/Overdues.t @@ -54,6 +54,7 @@ subtest 'overwrite_calc_fine hook tests' => sub { my $library = $builder->build_object( { class => 'Koha::Libraries', } ); my $category = $builder->build_object( { class => 'Koha::Patron::Categories', } ); my $item = $builder->build_sample_item; + my $patron = $builder->build_object( { class => 'Koha::Patrons', } ); Koha::Plugins->new->InstallPlugins(); my $test_plugin = Koha::Plugin::Test->new->disable(); @@ -129,13 +130,18 @@ subtest 'overwrite_calc_fine hook tests' => sub { $empty_value_plugin->disable(); $bad_value_plugin->disable(); + my $borrowernumber = $patron->borrowernumber; + my $overdue = $item->unblessed; + $overdue->{borrowernumber} = $borrowernumber; + my $itemnumber = $item->itemnumber; my $branchcode = $library->branchcode; my $categorycode = $category->categorycode; - warnings_like { CalcFine( $item->unblessed, $category->categorycode, $library->branchcode, $due_date, $end_date ); } + warnings_like { CalcFine( $overdue, $category->categorycode, $library->branchcode, $due_date, $end_date ); } [ qr/itemnumber:$itemnumber/, + qr/borrowernumber:$borrowernumber/, qr/branchcode:$branchcode/, qr/categorycode:$categorycode/, qr/due_date_type:DateTime/, diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm index b3539b1ac67..4b5dccbb4d5 100644 --- a/t/lib/plugins/Koha/Plugin/Test.pm +++ b/t/lib/plugins/Koha/Plugin/Test.pm @@ -452,6 +452,7 @@ sub overwrite_calc_fine { my ( $self, $params ) = @_; warn "itemnumber:" . $params->{itemnumber}; + warn "borrowernumber:" . $params->{borrowernumber}; warn "branchcode:" . $params->{branchcode}; warn "categorycode:" . $params->{categorycode}; warn "due_date_type:" . ref( $params->{due_date} ); -- 2.49.0