From d1342ae9b0cf24ac6816ba87270170a52667624f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 25 Aug 2022 11:26:33 +0000 Subject: [PATCH] Bug 31459: Use the same dropdown as when adding orders to a basket Current order receive code loops over each budget period and gets the hierarchy, this is slow when systems have many budgets. Additionally, the list includes inactive items by default We can switch to a single call, and add consistency by adopting the same dropdown as used when placing an order To test: 1 - Add some budgets with funds - ensure you have at least one inactive budget and fund 2 - Place an order, observe the fund selection menu 3 - Close basket, receive order, observe the fund menu 4 - Apply patch 5 - Cancel receipt 6 - Receive again 7 - Observe fund menu, confirm it matches the order placing menu 8 - Confirm inactive are not displayed by default, but are when button is checked --- acqui/orderreceive.pl | 46 +++++--------- .../prog/en/modules/acqui/orderreceive.tt | 62 +++++++++++++++---- 2 files changed, 64 insertions(+), 44 deletions(-) diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index c690dca55f..43b9c109f7 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -170,39 +170,21 @@ if ( $suggestion ) { } my $patron = Koha::Patrons->find( $loggedinuser )->unblessed; -my @budget_loop; -my $periods = GetBudgetPeriods( ); -foreach my $period (@$periods) { - if ($period->{'budget_period_id'} == $budget->{'budget_period_id'}) { - $template->{'VARS'}->{'budget_period_description'} = $period->{'budget_period_description'}; - } - next if $period->{'budget_period_locked'} || !$period->{'budget_period_description'}; - my $budget_hierarchy = GetBudgetHierarchy( $period->{'budget_period_id'}, undef, undef, 1 ); - my @funds; - foreach my $r ( @{$budget_hierarchy} ) { - next unless ( CanUserUseBudget( $patron, $r, $userflags ) ); - if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { - next; - } - push @funds, - { - b_id => $r->{budget_id}, - b_txt => $r->{budget_name}, - b_sel => ( $r->{budget_id} == $order->budget_id ) ? 1 : 0, - }; - } - - @funds = sort { uc( $a->{b_txt} ) cmp uc( $b->{b_txt} ) } @funds; - - push @budget_loop, - { - 'id' => $period->{'budget_period_id'}, - 'description' => $period->{'budget_period_description'}, - 'funds' => \@funds - }; +my $budget_loop = []; +my $budgets = GetBudgetHierarchy( undef, undef, undef, 1 ); +foreach my $r (@{$budgets}) { + next unless (CanUserUseBudget($patron, $r, $userflags)); + push @{$budget_loop}, { + b_id => $r->{budget_id}, + b_txt => $r->{budget_name}, + b_sort1_authcat => $r->{'sort1_authcat'}, + b_sort2_authcat => $r->{'sort2_authcat'}, + b_active => $r->{budget_period_active}, + b_sel => ( $r->{budget_id} == $order->budget_id ) ? 1 : 0, + b_level => $r->{budget_level}, + }; } - -$template->{'VARS'}->{'budget_loop'} = \@budget_loop; +$template->{'VARS'}->{'budget_loop'} = $budget_loop; my $op = $input->param('op'); if ($op and $op eq 'edit'){ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index 80a1d9da65..2f8011c46c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -280,20 +280,43 @@
[% INCLUDE 'date-format.inc' %]
-
  • + [% FOREACH budget_loo IN budget_loop %] + [% level_indent_cnt = 0 %] + [% level_indent = "" %] + [% WHILE level_indent_cnt < budget_loo.b_level %] + [% level_indent = level_indent _ " -- " %] + [% level_indent_cnt = level_indent_cnt +1 %] + [% END %] + + [% IF ( budget_loo.b_sel ) %] + [% active_count = 0 #select no other fund %] + [% END %] -
  • + + Required + + +
  • (Current: [% budget_period_description | html %] - [% bookfund | html %])
  • @@ -427,6 +450,7 @@ [% INCLUDE 'calendar.inc' %] [% Asset.js("js/additem.js") | $raw %] [% Asset.js("js/cataloging.js") | $raw %] + [% INCLUDE 'select2.inc' %]