From 86f37b1eb3a3376f475e69d351f0b0983b2b482a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 29 Apr 2019 11:14:27 -0400 Subject: [PATCH] Bug 18928: Use get_effective_rule in GetBranchItemRule Signed-off-by: Agustin Moyano Signed-off-by: Liz Rea Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Circulation.pm | 74 ++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7e3c9899ce..560abc1430 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1722,58 +1722,40 @@ Neither C<$branchcode> nor C<$itemtype> should be '*'. sub GetBranchItemRule { my ( $branchcode, $itemtype ) = @_; - # Set search precedences - my @params = ( - { - branchcode => $branchcode, - categorycode => undef, - itemtype => $itemtype, - }, - { - branchcode => $branchcode, - categorycode => undef, - itemtype => undef, - }, + # Search for rules! + my $holdallowed_rule = Koha::CirculationRules->get_effective_rule( { - branchcode => undef, - categorycode => undef, - itemtype => $itemtype, - }, + branchcode => $branchcode, + itemtype => $itemtype, + rule_name => 'holdallowed', + } + ); + my $hold_fulfillment_policy_rule = Koha::CirculationRules->get_effective_rule( { - branchcode => undef, - categorycode => undef, - itemtype => undef, - }, + branchcode => $branchcode, + itemtype => $itemtype, + rule_name => 'hold_fulfillment_policy', + } ); - - # Initialize default values - my $rules = { - holdallowed => undef, - hold_fulfillment_policy => undef, - returnbranch => undef, - }; - - # Search for rules! - foreach my $rule_name (qw( holdallowed hold_fulfillment_policy returnbranch )) { - foreach my $params (@params) { - my $rule = Koha::CirculationRules->search( - { - rule_name => $rule_name, - %$params, - } - )->next(); - - if ( $rule ) { - $rules->{$rule_name} = $rule->rule_value; - last; - } + my $returnbranch_rule = Koha::CirculationRules->get_effective_rule( + { + branchcode => $branchcode, + itemtype => $itemtype, + rule_name => 'returnbranch', } - } + ); # built-in default circulation rule - $rules->{holdallowed} = 2 unless ( defined $rules->{holdallowed} ); - $rules->{hold_fulfillment_policy} = 'any' unless ( defined $rules->{hold_fulfillment_policy} ); - $rules->{returnbranch} = 'homebranch' unless ( defined $rules->{returnbranch} ); + my $rules; + $rules->{holdallowed} = defined $holdallowed_rule + ? $holdallowed_rule->rule_value + : 2; + $rules->{hold_fulfillment_policy} = defined $hold_fulfillment_policy_rule + ? $hold_fulfillment_policy_rule->rule_value + : 'any'; + $rules->{returnbranch} = defined $returnbranch_rule + ? $returnbranch_rule->rule_value + : 'homebranch'; return $rules; } -- 2.39.5