From d8ac598201d0b0eb92005bede199543e998e8035 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 13 Oct 2021 15:36:43 +0200 Subject: [PATCH] Bug 29220: Minor fixes and improved code readability The current handling of onsite checkouts with OnSiteCheckoutsForce syspref enabled is confusing and hard to understand. It's also fragile with a high risk future changes could result in subtle bugs. Also fix an inconsistency in which errors are considered blocking for forced onsite checkouts. To test: 1) Enable OnSiteCheckouts, disable OnSiteCheckoutsForce 2) Edit a biblio item and for example set Not for loan to a value restricting loans 3) Try to check out the item for some patron 4) A message that item is not for loan should be displayed 5) Select "On-site checkout" and try again 6) The same message should be displayed 7) Try to checkout with some invalid barcode 8) A message that barcode was not found should be displayed 9) Now enable OnSiteCheckoutsForce 10) Try to checkout the item for some patron 11) A message that item is not for loan should be displayed 12) Select "On-site checkout" and try again 13) Checkout should now succeed, no messages should be displayed 14) Try to checkout with some invalid barcode 15) A message that barcode was not found should be displayed 16) All of the above steps should produce the same result with and without this patch Sponsored-by: Gothenburg University Library Signed-off-by: Fridolin Somers --- circ/circulation.pl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index 1471f3d160..cb49995163 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -356,21 +356,21 @@ if (@$barcodes) { } } - if ( $error->{DEBT_GUARANTORS} ) { - $template_params->{DEBT_GUARANTORS} = $error->{DEBT_GUARANTORS}; - $template_params->{IMPOSSIBLE} = 1; - $blocker = 1; - } - - if ( $error->{UNKNOWN_BARCODE} or not $onsite_checkout or not C4::Context->preference("OnSiteCheckoutsForce") ) { - delete $question->{'DEBT'} if ($debt_confirmed); - foreach my $impossible ( keys %$error ) { - $template_params->{$impossible} = $$error{$impossible}; + # Only some errors will block when performing forced onsite checkout, + # for other cases all errors will block + my @blocking_error_codes = ($onsite_checkout and C4::Context->preference("OnSiteCheckoutsForce")) ? + qw( UNKNOWN_BARCODE ) : (keys %$error); + + foreach my $code ( @blocking_error_codes ) { + if ($error->{$code}) { + $template_params->{$code} = $error->{$code}; $template_params->{IMPOSSIBLE} = 1; $blocker = 1; } } + delete $question->{'DEBT'} if ($debt_confirmed); + if( $item and ( !$blocker or $force_allow_issue ) ){ my $confirm_required = 0; unless($issueconfirmed){ -- 2.35.1