From 5da8926b790be3141a192a31e9919c12ccd0b3d0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 3 Aug 2020 18:25:10 +0200 Subject: [PATCH] Bug 26132: TooMany refactoring The different calls to _check_max_qty can be improved to highlight what is really changing between each of them. --- C4/Circulation.pm | 56 +++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ee7f5a7ccd..7fc90e72b3 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -508,51 +508,31 @@ sub TooMany { my ( $checkout_count_type, $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params ); - my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef; - + my $checkout_rules = { + checkout_count => $checkout_count, + onsite_checkout_count => $onsite_checkout_count, + onsite_checkout => $onsite_checkout, + max_checkouts_allowed => $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef, + max_onsite_checkouts_allowed => $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef, + switch_onsite_checkout => $switch_onsite_checkout, + }; # If parent rules exists if ( defined($parent_maxissueqty_rule) and defined($parent_maxissueqty_rule->rule_value) ){ - my $max_checkouts_allowed = $parent_maxissueqty_rule->rule_value; - - my $qty_over = _check_max_qty({ - checkout_count => $checkout_count, - onsite_checkout_count => $onsite_checkout_count, - onsite_checkout => $onsite_checkout, - max_checkouts_allowed => $max_checkouts_allowed, - max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, - switch_onsite_checkout => $switch_onsite_checkout - }); + $checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty_rule ? $parent_maxissueqty_rule->rule_value : undef; + my $qty_over = _check_max_qty($checkout_rules); return $qty_over if defined $qty_over; - - # If the parent rule is less than or equal to the child, we only need check the parent - if( $maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value && defined($maxissueqty_rule->itemtype) ) { - my $max_checkouts_allowed = $maxissueqty_rule->rule_value; - my $qty_over = _check_max_qty({ - checkout_count => $checkout_count_type, - onsite_checkout_count => $onsite_checkout_count, - onsite_checkout => $onsite_checkout, - max_checkouts_allowed => $max_checkouts_allowed, - max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, - switch_onsite_checkout => $switch_onsite_checkout - }); - return $qty_over if defined $qty_over; - } - + # If the parent rule is less than or equal to the child, we only need check the parent + if( $maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value && defined($maxissueqty_rule->itemtype) ) { + $checkout_rules->{checkout_count} = $checkout_count_type; + $checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef; + my $qty_over = _check_max_qty($checkout_rules); + return $qty_over if defined $qty_over; + } } else { - my $max_checkouts_allowed = $maxissueqty_rule->rule_value; - my $qty_over = _check_max_qty({ - checkout_count => $checkout_count, - onsite_checkout_count => $onsite_checkout_count, - onsite_checkout => $onsite_checkout, - max_checkouts_allowed => $max_checkouts_allowed, - max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, - switch_onsite_checkout => $switch_onsite_checkout - }); + my $qty_over = _check_max_qty($checkout_rules); return $qty_over if defined $qty_over; } - - } # Now count total loans against the limit for the branch -- 2.20.1