From 432e32e36839b1b82bd45687a39c5307ffd21cf9 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 26 Sep 2024 12:59:36 +0000 Subject: [PATCH] Bug 33292: Add logic to handle refunding a lost fee This patch allows the return claims endpoint to handle the refunding of a lost fee for the item if the checkbox is checked Signed-off-by: Lucas Gass Signed-off-by: Katrin Fischer --- Koha/Checkout.pm | 5 +++++ Koha/Item.pm | 6 +++++- Koha/REST/V1/ReturnClaims.pm | 2 ++ api/v1/swagger/paths/return_claims.yaml | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index bbb2d59d86..1e3f227306 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -242,6 +242,7 @@ sub claim_returned { my ( $self, $params ) = @_; my $charge_lost_fee = $params->{charge_lost_fee}; + my $refund_lost_fee = $params->{refund_lost_fee}; try { $self->_result->result_source->schema->txn_do( @@ -273,6 +274,10 @@ sub claim_returned { C4::Circulation::MarkIssueReturned( $self->borrowernumber, $self->itemnumber, undef, $self->patron->privacy ); } + if ($refund_lost_fee) { + $self->item->store( { refund_lost_fee => $refund_lost_fee } ); + } + return $claim; } ); diff --git a/Koha/Item.pm b/Koha/Item.pm index 647e2c4184..286a0a7d95 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -146,6 +146,11 @@ sub store { $action = 'modify'; + # refund lost fee if a return claim has been made on an item previously marked as lost + if ( $params->{refund_lost_fee} ) { + $self->_set_found_trigger( $self->get_from_storage ); + } + my %updated_columns = $self->_result->get_dirty_columns; return $self->SUPER::store unless %updated_columns; @@ -1453,7 +1458,6 @@ Internal function, not exported, called only by Koha::Item->store. sub _set_found_trigger { my ( $self, $pre_mod_item ) = @_; - # Reverse any lost item charges if necessary. my $no_refund_after_days = C4::Context->preference('NoRefundOnLostReturnedItemsAge'); diff --git a/Koha/REST/V1/ReturnClaims.pm b/Koha/REST/V1/ReturnClaims.pm index 45d2bceb43..6cd47d56af 100644 --- a/Koha/REST/V1/ReturnClaims.pm +++ b/Koha/REST/V1/ReturnClaims.pm @@ -45,6 +45,7 @@ sub claim_returned { return try { my $itemnumber = $body->{item_id}; my $charge_lost_fee = $body->{charge_lost_fee} ? 1 : 0; + my $refund_lost_fee = $body->{refund_lost_fee} ? 1 : 0; my $created_by = $body->{created_by}; my $notes = $body->{notes}; @@ -59,6 +60,7 @@ sub claim_returned { my $claim = $checkout->claim_returned( { charge_lost_fee => $charge_lost_fee, + refund_lost_fee => $refund_lost_fee, created_by => $created_by, notes => $notes, } diff --git a/api/v1/swagger/paths/return_claims.yaml b/api/v1/swagger/paths/return_claims.yaml index a83d2c43f3..345ebe670e 100644 --- a/api/v1/swagger/paths/return_claims.yaml +++ b/api/v1/swagger/paths/return_claims.yaml @@ -27,6 +27,10 @@ description: Charge a lost fee if true and Koha is set to allow a choice. Ignored otherwise. type: boolean + refund_lost_fee: + description: Refund a lost fee if true and a lost fee has previously been charged for the item. + Ignored otherwise. + type: boolean additionalProperties: false produces: - application/json -- 2.39.5