From 11b8c6f2ec1a49e89e23cdd372ffad3730afc05b Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 19 Feb 2024 13:24:47 +0000 Subject: [PATCH] Bug 27893: Optionally skip biblio with open orders in batch delete Content-Type: text/plain; charset=utf-8 If the user unchecks the skip checkbox (on by default), we must make sure that order cancellation is done in background job. Test plan: Pick two biblios. One has linked open orders, the other not. Go to batch delete records. Select 'Enter list of numbers'. Enter both biblio numbers and check that only one is used on the follow-up form. Run the deletion without the skip open orders and verify that linked order line is cancelled. Signed-off-by: Marcel de Rooy --- Koha/BackgroundJob/BatchDeleteBiblio.pm | 8 ++++++++ .../prog/en/modules/tools/batch_delete_records.tt | 6 ++++++ tools/batch_delete_records.pl | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Koha/BackgroundJob/BatchDeleteBiblio.pm b/Koha/BackgroundJob/BatchDeleteBiblio.pm index 0709fd259a..2054a726fe 100644 --- a/Koha/BackgroundJob/BatchDeleteBiblio.pm +++ b/Koha/BackgroundJob/BatchDeleteBiblio.pm @@ -7,6 +7,7 @@ use C4::Biblio; use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; use Koha::SearchEngine; use Koha::SearchEngine::Indexer; +use Koha::Acquisition::Orders; use base 'Koha::BackgroundJob'; @@ -123,6 +124,13 @@ sub process { } } + # Cancel acq order lines + my @result = Koha::Acquisition::Orders->search( { biblionumber => $biblionumber } )->cancel; + my $warns = @{ $result[1] }; + if ( $result[0] && $warns ) { # warnings about order lines not removed + warn sprintf( "%d order lines were deleted, but %d lines gave a warning\n", $result[0], $warns ); + } + # Finally, delete the biblio my $error = eval { C4::Biblio::DelBiblio( $biblionumber, { skip_record_index => 1, skip_holds_queue => 1 } ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt index d9930db1da..4c7ca5a5f3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt @@ -89,6 +89,10 @@
  1. +
  2. + + +
@@ -260,8 +264,10 @@ $("input[type='radio']").click(function() { if ($(this).attr('id') == 'authority_type') { $("a[href='#shelves_tab_panel']").parent().hide(); + $("li.skip_open_orders").hide(); } else if ($(this).attr('id') == 'biblio_type') { $("a[href='#shelves_tab_panel']").parent().show(); + $("li.skip_open_orders").show(); } }); diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index 9164235bc8..ea4a5a9ba4 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -29,6 +29,7 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); use C4::Biblio; use C4::AuthoritiesMarc; +use Koha::Acquisition::Orders; use Koha::Virtualshelves; use Koha::Authorities; @@ -37,9 +38,10 @@ use Koha::Items; use Koha::BackgroundJob::BatchDeleteBiblio; use Koha::BackgroundJob::BatchDeleteAuthority; -my $input = CGI->new; -my $op = $input->param('op') // q|form|; -my $recordtype = $input->param('recordtype') // 'biblio'; +my $input = CGI->new; +my $op = $input->param('op') // q|form|; +my $recordtype = $input->param('recordtype') // 'biblio'; +my $skip_open_orders = $input->param('skip_open_orders') // 0; my ($template, $loggedinuser, $cookie) = get_template_and_user({ template_name => 'tools/batch_delete_records.tt', @@ -106,6 +108,13 @@ if ( $op eq 'form' ) { $biblio->{holds_count} = $biblio_object->holds->count; $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id ); $biblio->{subscriptions_count} = $biblio_object->subscriptions->count; + + # Respect skip_open_orders + next + if $skip_open_orders + && Koha::Acquisition::Orders->search( + { biblionumber => $record_id, orderstatus => [ 'new', 'ordered', 'partial' ] } )->count; + push @records, $biblio; } else { # Retrieve authority information -- 2.30.2