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

Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

https://bugs.koha-community.org/show_bug.cgi?id=31559
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2022-08-25 11:26:33 +00:00 committed by Tomas Cohen Arazi
parent b0cf6c087b
commit 24e7703aef
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 64 additions and 44 deletions

View File

@ -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'){

View File

@ -287,20 +287,43 @@
<input type="text" size="10" id="datereceived" name="datereceived" value="[% datereceived | html %]" class="flatpickr" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
</li>
<li><label for="bookfund">Fund: </label><select id="bookfund" name="bookfund">
<option value="">Keep current ([% budget_period_description | html %] - [% order.fund.budget_name | html %])</option>
[% FOREACH period IN budget_loop %]
<optgroup label="[% period.description | html %]">
[% FOREACH fund IN period.funds %]
[% IF ( fund.b_sel ) %]
<option value="[% fund.b_id | html %]" selected="selected">[% fund.b_txt | html %]</option>
[% ELSE %]
<option value="[% fund.b_id | html %]">[% fund.b_txt | html %]</option>
[% END %]
<li>
<label class="required" for="bookfund">Fund: </label>
[% active_count = 0 %]
[% IF !ordernumber %]
[% FOREACH budget_loo IN budget_loop %]
[% active_count= active_count + budget_loo.b_active %]
[% END %]
</optgroup>
[% END %]
</select></li>
<select class="select2" id="bookfund" name="bookfund">
[% 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 %]
<option value="[% budget_loo.b_id | html %]" selected="selected" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]"
>
[% ELSIF active_count==1 && budget_loo.b_active %]
<option value="[% budget_loo.b_id | html %]" selected="selected" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]"
>
[% ELSE %]
[% bdgclass=budget_loo.b_active? "": "b_inactive" | html %]
<option value="[% budget_loo.b_id | html %]" class="[% bdgclass | html %]" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]"
>
[% END %]
[% level_indent | html %][% budget_loo.b_txt | html %][% IF !budget_loo.b_active %] (inactive)[% END %]
</option>
[% END %]
</select>
<span class="required">Required</span>
<label for="showallbudgets" style="float:none;">&nbsp;Show inactive:</label>
<input type="checkbox" id="showallbudgets" />
</li>
<li><label>&nbsp;</label><span>(Current: [% budget_period_description | html %] - [% bookfund | html %])</span></li>
<li>
<label for="creator">Ordered by: </label>
@ -434,6 +457,7 @@
[% INCLUDE 'calendar.inc' %]
[% Asset.js("js/additem.js") | $raw %]
[% Asset.js("js/cataloging.js") | $raw %]
[% INCLUDE 'select2.inc' %]
<script>
function Check(form) {
[% IF (AcqCreateItem == 'receiving') %]
@ -528,6 +552,20 @@
[% END %]
$(document).ready(function() {
//keep a copy of all budgets before removing the inactives
disabledBudgetsCopy = $('#bookfund').html();
$('#bookfund .b_inactive').remove();
$('#showallbudgets').click(function() {
if ($(this).is(":checked")) {
$('#bookfund').html(disabledBudgetsCopy); //Puts back all the funds
}
else {
$('#bookfund .b_inactive').remove();
}
});
[% IF (AcqCreateItem == 'receiving') %]
cloneItemBlock(0, '[% Koha.Preference('UniqueItemFields') | html %]');
[% ELSIF (AcqCreateItem == 'ordering') && not order.subscriptionid %]