From cacab828812f849cc567b63e365b502f79823f2c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 23 Sep 2021 13:41:21 +0100 Subject: [PATCH] Bug 28854: Respect WhenLostChargeReplacementFee --- C4/Accounts.pm | 7 ++++++- circ/returns.pl | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index ad0d34f184..84ebbcd225 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -70,7 +70,8 @@ FIXME : if no replacement price, borrower just doesn't get charged? sub chargelostitem { my $dbh = C4::Context->dbh(); my ($borrowernumber, $itemnumber, $amount, $description) = @_; - my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() }); + my $item = Koha::Items->find($itemnumber); + my $itype = Koha::ItemTypes->find({ itemtype => $item->effective_itemtype() }); my $replacementprice = $amount; my $defaultreplacecost = $itype->defaultreplacecost; my $processfee = $itype->processfee; @@ -80,6 +81,10 @@ sub chargelostitem { $replacementprice = $defaultreplacecost; } my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber }); + if ( !$checkout && $item->in_bundle ) { + my $host = $item->bundle_host; + $checkout = $host->checkout; + } my $issue_id = $checkout ? $checkout->issue_id : undef; my $account = Koha::Account->new({ patron_id => $borrowernumber }); diff --git a/circ/returns.pl b/circ/returns.pl index 1774568fcb..83bc880732 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -386,6 +386,20 @@ if ($barcode) { $bundle_item->_result->update_or_create_related( 'items_lost_issue', { issue_id => $checkout->issue_id } ); push @missing_items, $bundle_item; + # NOTE: We cannot use C4::LostItem here because the item itself doesn't have a checkout + # and thus would not get charged.. it's checked out as part of the bundle. + if ( C4::Context->preference('WhenLostChargeReplacementFee') ) { + C4::Accounts::chargelostitem( + $checkout->borrowernumber, + $bundle_item->itemnumber, + $bundle_item->replacementprice, + sprintf( "%s %s %s", + $bundle_item->biblio->title || q{}, + $bundle_item->barcode || q{}, + $bundle_item->itemcallnumber || q{}, + ), + ); + } } $template->param( unexpected_items => \@unexpected_items, -- 2.20.1