Bug 18928: Use get_effective_rule in GetBranchItemRule

Signed-off-by: Agustin Moyano <agustinmoyano@theke.io>
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2019-04-29 11:14:27 -04:00 committed by Martin Renvoize
parent 54791a5c46
commit 86f37b1eb3
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 28 additions and 46 deletions

View File

@ -1722,58 +1722,40 @@ Neither C<$branchcode> nor C<$itemtype> should be '*'.
sub GetBranchItemRule {
my ( $branchcode, $itemtype ) = @_;
# Set search precedences
my @params = (
# Search for rules!
my $holdallowed_rule = Koha::CirculationRules->get_effective_rule(
{
branchcode => $branchcode,
categorycode => undef,
itemtype => $itemtype,
},
branchcode => $branchcode,
itemtype => $itemtype,
rule_name => 'holdallowed',
}
);
my $hold_fulfillment_policy_rule = Koha::CirculationRules->get_effective_rule(
{
branchcode => $branchcode,
categorycode => undef,
itemtype => undef,
},
branchcode => $branchcode,
itemtype => $itemtype,
rule_name => 'hold_fulfillment_policy',
}
);
my $returnbranch_rule = Koha::CirculationRules->get_effective_rule(
{
branchcode => undef,
categorycode => undef,
itemtype => $itemtype,
},
{
branchcode => undef,
categorycode => undef,
itemtype => undef,
},
branchcode => $branchcode,
itemtype => $itemtype,
rule_name => 'returnbranch',
}
);
# 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;
}
}
}
# 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;
}