SELECT itemtype FROM circulation_rules
WHERE branchcode = ?
AND (categorycode = ? OR categorycode = ?)
- AND itemtype <> '*'
+ AND itemtype IS NOT NULL
AND rule_name = 'maxissueqty'
) ";
} else {
SELECT itemtype FROM circulation_rules
WHERE branchcode = ?
AND (categorycode = ? OR categorycode = ?)
- AND itemtype <> '*'
+ AND itemtype IS NOT NULL
AND rule_name = 'maxissueqty'
) ";
}
},
{
categorycode => $categorycode,
- itemtype => '*',
+ itemtype => undef,
branchcode => $branchcode,
},
{
- categorycode => '*',
+ categorycode => undef,
itemtype => $itemtype,
branchcode => $branchcode,
},
{
- categorycode => '*',
- itemtype => '*',
+ categorycode => undef,
+ itemtype => undef,
branchcode => $branchcode,
},
{
categorycode => $categorycode,
itemtype => $itemtype,
- branchcode => '*',
+ branchcode => undef,
},
{
categorycode => $categorycode,
- itemtype => '*',
- branchcode => '*',
+ itemtype => undef,
+ branchcode => undef,
},
{
- categorycode => '*',
+ categorycode => undef,
itemtype => $itemtype,
- branchcode => '*',
+ branchcode => undef,
},
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
},
);
$holds_per_day = $rights->{holds_per_day};
}
else {
- $ruleitemtype = '*';
+ $ruleitemtype = undef;
}
my $holds = Koha::Holds->search(
C4::Context->preference('item-level_itypes')
? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
: " AND biblioitems.itemtype = ?"
- if ( $ruleitemtype ne "*" );
+ if defined $ruleitemtype;
my $sthcount = $dbh->prepare($querycount);
- if ( $ruleitemtype eq "*" ) {
- $sthcount->execute( $borrowernumber, $branchcode );
+ if ( defined $ruleitemtype ) {
+ $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
}
else {
- $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
+ $sthcount->execute( $borrowernumber, $branchcode );
}
my $reservecount = "0";
=cut
+=head3 rule_kinds
+
+This structure describes the possible rules that may be set, and what scopes they can be set at.
+
+Any attempt to set a rule with a nonsensical scope (for instance, setting the C<patron_maxissueqty> for a branchcode and itemtype), is an error.
+
+=cut
+
+our $RULE_KINDS = {
+ refund => {
+ scope => [ 'branchcode' ],
+ },
+
+ patron_maxissueqty => {
+ scope => [ 'branchcode', 'categorycode' ],
+ },
+ patron_maxonsiteissueqty => {
+ scope => [ 'branchcode', 'categorycode' ],
+ },
+ max_holds => {
+ scope => [ 'branchcode', 'categorycode' ],
+ },
+
+ holdallowed => {
+ scope => [ 'branchcode', 'itemtype' ],
+ },
+ hold_fulfillment_policy => {
+ scope => [ 'branchcode', 'itemtype' ],
+ },
+ returnbranch => {
+ scope => [ 'branchcode', 'itemtype' ],
+ },
+
+ article_requests => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ auto_renew => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ cap_fine_to_replacement_price => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ chargeperiod => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ chargeperiod_charge_at => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ fine => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ finedays => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ firstremind => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ hardduedate => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ hardduedatecompare => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ holds_per_record => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ issuelength => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ lengthunit => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ maxissueqty => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ maxonsiteissueqty => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ maxsuspensiondays => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ no_auto_renewal_after => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ no_auto_renewal_after_hard_limit => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ norenewalbefore => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ onshelfholds => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ opacitemholds => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ overduefinescap => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ renewalperiod => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ renewalsallowed => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ rentaldiscount => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ reservesallowed => {
+ scope => [ 'branchcode', 'categorycode', 'itemtype' ],
+ },
+ # Not included (deprecated?):
+ # * accountsent
+ # * chargename
+ # * reservecharge
+ # * restrictedtype
+};
+
+sub rule_kinds {
+ return $RULE_KINDS;
+}
+
=head3 get_effective_rule
=cut
sub get_effective_rule {
my ( $self, $params ) = @_;
- $params->{categorycode} = '*' if exists($params->{categorycode}) && !defined($params->{categorycode});
- $params->{branchcode} = '*' if exists($params->{branchcode}) && !defined($params->{branchcode});
- $params->{itemtype} = '*' if exists($params->{itemtype}) && !defined($params->{itemtype});
+ $params->{categorycode} //= undef;
+ $params->{branchcode} //= undef;
+ $params->{itemtype} //= undef;
my $rule_name = $params->{rule_name};
my $categorycode = $params->{categorycode};
Koha::Exceptions::MissingParameter->throw(
"Required parameter 'branchcode' missing")
unless exists $params->{$mandatory_parameter};
+
+ my $kind_info = $RULE_KINDS->{ $params->{rule_name} };
+ croak "set_rule given unknown rule '$params->{rule_name}'!"
+ unless defined $kind_info;
+
+ # Enforce scope; a rule should be set for its defined scope, no more, no less.
+ foreach my $scope_level ( qw( branchcode categorycode itemtype ) ) {
+ if ( grep /$scope_level/, @{ $kind_info->{scope} } ) {
+ croak "set_rule needs '$scope_level' to set '$params->{rule_name}'!"
+ unless exists $params->{$scope_level};
+ } else {
+ croak "set_rule cannot set '$params->{rule_name}' for a '$scope_level'!"
+ if exists $params->{$scope_level};
+ }
}
my $branchcode = $params->{branchcode};
sub set_rules {
my ( $self, $params ) = @_;
- my $branchcode = $params->{branchcode};
- my $categorycode = $params->{categorycode};
- my $itemtype = $params->{itemtype};
+ my %set_params;
+ $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
+ $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
+ $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
my $rules = $params->{rules};
my $rule_objects = [];
while ( my ( $rule_name, $rule_value ) = each %$rules ) {
my $rule_object = Koha::CirculationRules->set_rule(
{
- branchcode => $branchcode,
- categorycode => $categorycode,
- itemtype => $itemtype,
+ %set_params,
rule_name => $rule_name,
rule_value => $rule_value,
}
--- /dev/null
+package Koha::REST::V1::CirculationRules;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Mojo::Base 'Mojolicious::Controller';
+
+use Koha::CirculationRules;
+
+use Try::Tiny;
+
+sub get_kinds {
+ my ( $c, $args, $cb ) = @_;
+
+ return $c->$cb( Koha::CirculationRules->rule_kinds, 200 );
+}
+
+1;
Koha::CirculationRules->set_rules(
{
- categorycode => $categorycode,
- branchcode => $branch,
- itemtype => $itemtype,
+ categorycode => $categorycode eq '*' ? undef : $categorycode,
+ branchcode => $branch eq '*' ? undef : $branch,
+ itemtype => $itemtype eq '*' ? undef : $itemtype,
rules => {
restrictedtype => undef,
rentaldiscount => undef,
my $categorycode = $input->param('categorycode');
if ($branch eq "*") {
if ($categorycode eq "*") {
- Koha::CirculationRules->set_rules(
- {
- categorycode => undef,
- branchcode => undef,
- itemtype => undef,
- rules => {
- patron_maxissueqty => undef,
- patron_maxonsiteissueqty => undef,
- holdallowed => undef,
- hold_fulfillment_policy => undef,
- returnbranch => undef,
- max_holds => undef,
- }
- }
- );
- } else {
- Koha::CirculationRules->set_rules(
- {
- categorycode => $categorycode,
- branchcode => undef,
- itemtype => undef,
- rules => {
- max_holds => undef,
- patron_maxissueqty => undef,
- patron_maxonsiteissueqty => undef,
- }
- }
- );
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ categorycode => undef,
+ rules => {
+ max_holds => undef,
+ patron_maxissueqty => undef,
+ patron_maxonsiteissueqty => undef,
+ }
+ }
+ );
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ rules => {
+ holdallowed => undef,
+ hold_fulfillment_policy => undef,
+ returnbranch => undef,
+ }
+ }
+ );
+ } else {
+ Koha::CirculationRules->set_rules(
+ {
+ categorycode => $categorycode,
+ branchcode => undef,
+ rules => {
+ max_holds => undef,
+ patron_maxissueqty => undef,
+ patron_maxonsiteissueqty => undef,
+ }
+ }
+ );
}
} elsif ($categorycode eq "*") {
Koha::CirculationRules->set_rules(
{
+ branchcode => $branch,
categorycode => undef,
+ rules => {
+ patron_maxissueqty => undef,
+ patron_maxonsiteissueqty => undef,
+ }
+ }
+ );
+ Koha::CirculationRules->set_rules(
+ {
branchcode => $branch,
- itemtype => undef,
rules => {
- patron_maxissueqty => undef,
- patron_maxonsiteissueqty => undef,
holdallowed => undef,
hold_fulfillment_policy => undef,
returnbranch => undef,
{
categorycode => $categorycode,
branchcode => $branch,
- itemtype => undef,
rules => {
max_holds => undef,
patron_maxissueqty => undef,
if ($itemtype eq "*") {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
branchcode => undef,
itemtype => undef,
rules => {
- patron_maxissueqty => undef,
- patron_maxonsiteissueqty => undef,
holdallowed => undef,
hold_fulfillment_policy => undef,
returnbranch => undef,
} else {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
branchcode => undef,
itemtype => $itemtype,
rules => {
} elsif ($itemtype eq "*") {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
branchcode => $branch,
itemtype => undef,
rules => {
- maxissueqty => undef,
- maxonsiteissueqty => undef,
holdallowed => undef,
hold_fulfillment_policy => undef,
returnbranch => undef,
} else {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
branchcode => $branch,
itemtype => $itemtype,
rules => {
Koha::CirculationRules->set_rules(
{
- categorycode => $bor,
- itemtype => $itemtype,
- branchcode => $br,
+ categorycode => $bor eq '*' ? undef : $bor,
+ itemtype => $itemtype eq '*' ? undef : $itemtype,
+ branchcode => $br eq '*' ? undef : $br,
rules => $rules,
}
);
if ($branch eq "*") {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
itemtype => undef,
branchcode => undef,
rules => {
- patron_maxissueqty => $patron_maxissueqty,
- patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
- holdallowed => $holdallowed,
- hold_fulfillment_policy => $hold_fulfillment_policy,
- returnbranch => $returnbranch,
+ holdallowed => $holdallowed,
+ hold_fulfillment_policy => $hold_fulfillment_policy,
+ returnbranch => $returnbranch,
}
}
);
- } else {
Koha::CirculationRules->set_rules(
{
categorycode => undef,
+ branchcode => undef,
+ rules => {
+ patron_maxissueqty => $patron_maxissueqty,
+ patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
+ }
+ }
+ );
+ } else {
+ Koha::CirculationRules->set_rules(
+ {
itemtype => undef,
branchcode => $branch,
rules => {
- patron_maxissueqty => $patron_maxissueqty,
- patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
- holdallowed => $holdallowed,
- hold_fulfillment_policy => $hold_fulfillment_policy,
- returnbranch => $returnbranch,
+ holdallowed => $holdallowed,
+ hold_fulfillment_policy => $hold_fulfillment_policy,
+ returnbranch => $returnbranch,
+ }
+ }
+ );
+ Koha::CirculationRules->set_rules(
+ {
+ categorycode => undef,
+ branchcode => $branch,
+ rules => {
+ patron_maxissueqty => $patron_maxissueqty,
+ patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
}
}
);
Koha::CirculationRules->set_rules(
{
categorycode => undef,
- itemtype => undef,
branchcode => undef,
rules => {
max_holds => $max_holds,
} else {
Koha::CirculationRules->set_rules(
{
- branchcode => undef,
categorycode => $categorycode,
- itemtype => undef,
+ branchcode => undef,
rules => {
max_holds => $max_holds,
patron_maxissueqty => $patron_maxissueqty,
Koha::CirculationRules->set_rules(
{
categorycode => undef,
- itemtype => undef,
branchcode => $branch,
rules => {
max_holds => $max_holds,
Koha::CirculationRules->set_rules(
{
categorycode => $categorycode,
- itemtype => undef,
branchcode => $branch,
rules => {
max_holds => $max_holds,
if ($itemtype eq "*") {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
itemtype => undef,
branchcode => undef,
rules => {
} else {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
itemtype => $itemtype,
branchcode => undef,
rules => {
} elsif ($itemtype eq "*") {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
itemtype => undef,
branchcode => $branch,
rules => {
} else {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
itemtype => $itemtype,
branchcode => $branch,
rules => {
# only do something for $refund eq '*' if branch-specific
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
- itemtype => undef,
branchcode => $branch,
rules => {
refund => undef
} else {
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
- itemtype => undef,
- branchcode => $branch,
+ branchcode => undef,
rules => {
refund => $refund
}
}
}
-my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => ($branch eq '*') ? undef:$branch });
-
+my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => ($branch eq '*') ? undef : $branch });
$template->param(
refundLostItemFeeRule => $refundLostItemFeeRule,
defaultRefundRule => Koha::RefundLostItemFeeRules->_default_rule
$template->param(
patron_categories => $patron_categories,
itemtypeloop => $itemtypes,
- humanbranch => ( $branch ne '*' ? $branch : '' ),
+ humanbranch => ( $branch ne '*' ? $branch : undef ),
current_branch => $branch,
);
output_html_with_http_headers $input, $cookie, $template->output;
"basket": {
"$ref": "definitions/basket.json"
},
+ "circ-rule-kind": {
+ "$ref": "definitions/circ-rule-kind.json"
+ },
"city": {
"$ref": "definitions/city.json"
},
--- /dev/null
+{
+ "type": "object",
+ "properties": {
+ "scope": {
+ "description": "levels that this rule kind can be set for",
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": [ "branchcode", "categorycode", "itemtype" ]
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": ["scope"]
+}
"/checkouts/{checkout_id}/renewal": {
"$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewal"
},
+ "/circulation-rules/kinds": {
+ "$ref": "paths/circulation-rules.json#/~1circulation-rules~1kinds"
+ },
"/cities": {
"$ref": "paths/cities.json#/~1cities"
},
--- /dev/null
+{
+ "/circulation-rules/kinds": {
+ "get": {
+ "x-mojo-controller": "Koha::REST::V1::CirculationRules",
+ "operationId": "get_kinds",
+ "tags": ["cities"],
+ "produces": [
+ "application/json"
+ ],
+ "responses": {
+ "200": {
+ "description": "A map of rule kind information",
+ "schema": {
+ "type": "object",
+ "additionalProperties": {
+ "$ref": "../definitions.json#/circ-rule-kind"
+ }
+ }
+ },
+ "403": {
+ "description": "Access forbidden",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ },
+ "500": {
+ "description": "Internal error",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ }
+ }
+ }
+ }
+}
[% USE CirculationRules %]
[% SET footerjs = 1 %]
-[% SET branchcode = humanbranch || '*' %]
+[% SET branchcode = humanbranch || undef %]
[% SET categorycodes = [] %]
[% FOREACH pc IN patron_categories %]
[% categorycodes.push( pc.id ) %]
[% END %]
-[% categorycodes.push('*') %]
+[% categorycodes.push(undef) %]
[% SET itemtypes = [] %]
[% FOREACH i IN itemtypeloop %]
[% itemtypes.push( i.itemtype ) %]
[% END %]
-[% itemtypes.push('*') %]
+[% itemtypes.push(undef) %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha › Administration › Circulation and fine rules</title>
[% SET row_count = row_count + 1 %]
<tr row_countd="row_[% row_count %]">
<td>
- [% IF c == '*' %]
+ [% IF c == undef %]
<em>All</em>
[% ELSE %]
[% Categories.GetName(c) %]
[% END %]
</td>
<td>
- [% IF i == '*' %]
+ [% IF i == undef %]
<em>All</em>
[% ELSE %]
[% ItemTypes.GetDescription(i) %]
[% END %]
</td>
+ <td class="actions">
+ <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
+ <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&itemtype=[% rule.itemtype || '*' %]&categorycode=[% rule.categorycode || '*' %]&branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
+ </td>
<td>
[% IF rule.note %]
<a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
<td>[% rentaldiscount %]</td>
<td class="actions">
<a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
- <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&itemtype=[% rule.itemtype | uri %]&categorycode=[% rule.categorycode | uri %]&branch=[% rule.current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
+ <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&itemtype=[% rule.itemtype || '*' | uri %]&categorycode=[% rule.categorycode || '*' | uri %]&branch=[% rule.current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
</td>
</tr>
[% END %]
<th> </th>
</tr>
[% FOREACH c IN categorycodes %]
+ [% NEXT UNLESS c %]
[% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
[% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
[% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
[% IF ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
<tr>
<td>
- [% IF c == '*'%]
+ [% IF c == undef %]
<em>Default</em>
[% ELSE %]
[% Categories.GetName(c) | html %]
my $rule = Koha::CirculationRules->set_rule(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rule_name => 'article_requests',
rule_value => 'yes',
}
$rule = Koha::CirculationRules->set_rule(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rule_name => 'article_requests',
rule_value => 'bib_only',
}
$rule = Koha::CirculationRules->set_rule(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rule_name => 'article_requests',
rule_value => 'item_only',
}
$rule = Koha::CirculationRules->set_rule(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rule_name => 'article_requests',
rule_value => 'no',
}
use Test::More tests => 46;
use Test::MockModule;
+use Test::Deep qw( cmp_deeply );
use Data::Dumper;
use DateTime;
$dbh->do('DELETE FROM circulation_rules');
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
reservesallowed => 25,
issuelength => 14,
# Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
Koha::CirculationRules->set_rule(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rule_name => 'onshelfholds',
rule_value => '1',
}
# Test premature manual renewal
Koha::CirculationRules->set_rule(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rule_name => 'norenewalbefore',
rule_value => '7',
}
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '7',
no_auto_renewal_after => '9',
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '7',
no_auto_renewal_after => '10',
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '7',
no_auto_renewal_after => '11',
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => '11',
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => undef,
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '7',
no_auto_renewal_after => '15',
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => undef,
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => '11',
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '7',
no_auto_renewal_after => '',
my $five_days_before = dt_from_string->add( days => -5 );
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => '5',
$dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => '15',
my $two_days_ahead = dt_from_string->add( days => 2 );
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => '',
);
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => '10',
no_auto_renewal_after => '15',
# set policy to forbid renewals
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
norenewalbefore => undef,
renewalsallowed => 0,
$dbh->do('DELETE FROM circulation_rules');
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
reservesallowed => 25,
issuelength => 14,
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
onshelfholds => 0,
}
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
onshelfholds => 0,
}
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
onshelfholds => 1,
}
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
onshelfholds => 1,
}
t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
- is( keys(%$error) + keys(%$alerts), 0, 'No error or alert should be raised' . str($error, $question, $alerts) );
- is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' . str($error, $question, $alerts) );
+ cmp_deeply(
+ { error => $error, alerts => $alerts },
+ { error => {}, alerts => {} },
+ 'No error or alert should be raised'
+ );
+ is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' );
t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
- is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1' . str($error, $question, $alerts) );
+ cmp_deeply(
+ { error => $error, question => $question, alerts => $alerts },
+ { error => {}, question => {}, alerts => {} },
+ 'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1'
+ );
# Add a subscription
Koha::Subscription->new({ biblionumber => $biblionumber })->store;
t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
- is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' . str($error, $question, $alerts) );
+ cmp_deeply(
+ { error => $error, question => $question, alerts => $alerts },
+ { error => {}, question => {}, alerts => {} },
+ 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
+ );
t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
- is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' . str($error, $question, $alerts) );
+ cmp_deeply(
+ { error => $error, question => $question, alerts => $alerts },
+ { error => {}, question => {}, alerts => {} },
+ 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
+ );
};
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Koha::CirculationRules->search->delete;
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
issuelength => 1,
firstremind => 1, # 1 day of grace
Koha::CirculationRules->search->delete;
my $rule = Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
issuelength => 6,
lengthunit => 'days',
{
branchcode => $samplebranch1->{branchcode},
categorycode => $samplecat->{categorycode},
- itemtype => undef,
rules => {
patron_maxissueqty => 5,
patron_maxonsiteissueqty => 6,
}
);
+
Koha::CirculationRules->set_rules(
{
branchcode => $samplebranch2->{branchcode},
categorycode => undef,
- itemtype => undef,
rules => {
patron_maxissueqty => 3,
patron_maxonsiteissueqty => 2,
- holdallowed => 1,
- returnbranch => 'holdingbranch',
+ }
+ }
+);
+Koha::CirculationRules->set_rules(
+ {
+ branchcode => $samplebranch2->{branchcode},
+ itemtype => undef,
+ rules => {
+ holdallowed => 1,
+ returnbranch => 'holdingbranch',
}
}
);
{
branchcode => undef,
categorycode => undef,
- itemtype => undef,
rules => {
patron_maxissueqty => 4,
patron_maxonsiteissueqty => 5,
- holdallowed => 3,
- returnbranch => 'homebranch',
+ }
+ }
+);
+Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ rules => {
+ holdallowed => 3,
+ returnbranch => 'homebranch',
}
}
);
Koha::CirculationRules->set_rules(
{
branchcode => $samplebranch1->{branchcode},
- categorycode => undef,
itemtype => $sampleitemtype1->{itemtype},
rules => {
holdallowed => 5,
Koha::CirculationRules->set_rules(
{
branchcode => $samplebranch2->{branchcode},
- categorycode => undef,
itemtype => $sampleitemtype1->{itemtype},
rules => {
holdallowed => 5,
Koha::CirculationRules->set_rules(
{
branchcode => $samplebranch2->{branchcode},
- categorycode => undef,
itemtype => $sampleitemtype2->{itemtype},
rules => {
holdallowed => 5,
Koha::CirculationRules->set_rules(
{
- branchcode => '*',
- categorycode => '*',
- itemtype => '*',
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
rules => {
fine => '1.00',
lengthunit => 'days',
t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
Koha::CirculationRules->set_rules(
{
- branchcode => '*',
- categorycode => '*',
- itemtype => '*',
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
rules => {
fine => '1.00',
lengthunit => 'days',
use Koha::CirculationRules;
use Koha::Library;
-use Test::More tests => 8;
+use t::lib::TestBuilder;
+
+use Test::More tests => 10;
BEGIN {
use_ok('C4::Circulation');
$samplecat->{category_type}
);
+my $builder = t::lib::TestBuilder->new;
+my $sampleitemtype1 = $builder->build({ source => 'Itemtype' })->{itemtype};
+my $sampleitemtype2 = $builder->build({ source => 'Itemtype' })->{itemtype};
+
#Begin Tests
my $default = {
my $sampleissuingrule1 = {
branchcode => $samplebranch1->{branchcode},
categorycode => $samplecat->{categorycode},
- itemtype => 'BOOK',
+ itemtype => $sampleitemtype1,
rules => {
- reservecharge => 0,
- restrictedtype => 0,
- accountsent => 0,
finedays => 0,
lengthunit => 'days',
renewalperiod => 5,
my $sampleissuingrule2 = {
branchcode => $samplebranch2->{branchcode},
categorycode => $samplecat->{categorycode},
- itemtype => 'BOOK',
+ itemtype => $sampleitemtype1,
rules => {
renewalsallowed => 0,
renewalperiod => 2,
chargeperiod_charge_at => 0,
rentaldiscount => 2.00,
overduefinescap => undef,
- accountsent => undef,
- reservecharge => undef,
- restrictedtype => undef,
maxsuspensiondays => 0,
onshelfholds => 1,
opacitemholds => 'Y',
my $sampleissuingrule3 = {
branchcode => $samplebranch1->{branchcode},
categorycode => $samplecat->{categorycode},
- itemtype => 'DVD',
+ itemtype => $sampleitemtype2,
rules => {
renewalsallowed => 0,
renewalperiod => 3,
chargeperiod_charge_at => 0,
rentaldiscount => 3.00,
overduefinescap => undef,
- accountsent => undef,
- reservecharge => undef,
- restrictedtype => undef,
maxsuspensiondays => 0,
onshelfholds => 1,
opacitemholds => 'F',
is_deeply(
C4::Circulation::GetLoanLength(
$samplecat->{categorycode},
- 'BOOK', $samplebranch1->{branchcode}
+ $sampleitemtype1, $samplebranch1->{branchcode}
),
{ issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
"GetLoanLength"
"With only one parameter, GetLoanLength returns hardcoded values"
); #NOTE : is that really what is expected?
is_deeply(
- C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
+ C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1 ),
$default,
"With only two parameters, GetLoanLength returns hardcoded values"
); #NOTE : is that really what is expected?
is_deeply(
- C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK', $samplebranch1->{branchcode} ),
+ C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
{
issuelength => 5,
renewalperiod => 5,
#Test GetHardDueDate
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
- 'BOOK', $samplebranch1->{branchcode} );
+ $sampleitemtype1, $samplebranch1->{branchcode} );
is_deeply(
\@hardduedate,
[
Koha::CirculationRules->search->delete;
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
firstremind => 0,
finedays => 2,
# Test with maxsuspensiondays = 10 days
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
maxsuspensiondays => 10,
}
Koha::CirculationRules->search->delete;
Koha::CirculationRules->set_rule(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rule_name => 'issuelength',
rule_value => 1,
}
t::lib::Mocks::mock_preference( 'finesMode', 'production' );
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
chargeperiod => 1,
fine => 1,
Koha::CirculationRules->set_rules(
{
branchcode => $branch->{branchcode},
- categorycode => '*',
- itemtype => '*',
+ categorycode => undef,
+ itemtype => undef,
rules => {
maxissueqty => 2,
maxonsiteissueqty => 1,
- branchcode => $branch->{branchcode},
- categorycode => '*',
- itemtype => '*',
lengthunit => 'days',
issuelength => 5,
hardduedate => undef,
Koha::CirculationRules->set_rules(
{
branchcode => $branch->{branchcode},
- categorycode => '*',
- itemtype => '*',
+ categorycode => undef,
+ itemtype => undef,
rules => {
maxissueqty => 2,
maxonsiteissueqty => 1,
{
branchcode => $branch->{branchcode},
categorycode => $category->{categorycode},
- itemtype => '*',
+ itemtype => undef,
rules => {
maxissueqty => 0,
maxonsiteissueqty => 0,
{
branchcode => $branch->{branchcode},
categorycode => $category->{categorycode},
- itemtype => '*',
+ itemtype => undef,
rules => {
maxissueqty => 1,
maxonsiteissueqty => 1,
{
branchcode => $branch->{branchcode},
categorycode => $category->{categorycode},
- itemtype => '*',
+ itemtype => undef,
rules => {
maxissueqty => 1,
maxonsiteissueqty => 1,
{
branchcode => $branch->{branchcode},
categorycode => $category->{categorycode},
- itemtype => '*',
+ itemtype => undef,
rules => {
maxissueqty => 1,
maxonsiteissueqty => 1,
# Add a default rule: renewal is allowed
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
renewalsallowed => 3,
}
Koha::CirculationRules->set_rules(
{
- branchcode => '*',
- categorycode => '*',
+ branchcode => undef,
+ categorycode => undef,
itemtype => $item->itype,
rules => {
issuelength => '14',
lengthunit => 'days',
reservesallowed => '99',
+ holds_per_record => '99',
}
}
);
my $issuingrule = Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
fine => 1,
finedays => 0,
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
# Test charging fine at the *beginning* of each charge period
-my $issuingrule = Koha::CirculationRules->set_rules(
+$issuingrule = Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
chargeperiod_charge_at => 1,
}
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
reservesallowed => 25,
holds_per_record => 99,
);
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
+ categorycode => undef,
+ branchcode => undef,
itemtype => 'CANNOT',
rules => {
reservesallowed => 0,
$dbh->do('DELETE FROM circulation_rules');
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
reservesallowed => 25,
holds_per_record => 99,
{
branchcode => $branch_1,
itemtype => 'CANNOT',
- categorycode => undef,
rules => {
holdallowed => 0,
returnbranch => 'homebranch',
{
branchcode => $branch_1,
itemtype => 'CAN',
- categorycode => undef,
rules => {
holdallowed => 1,
returnbranch => 'homebranch',
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
+ categorycode => undef,
+ branchcode => undef,
itemtype => 'ONLY1',
rules => {
reservesallowed => 1,
$biblio->biblionumber );
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => 'TEST',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => $testitemtype,
rules => {
reservesallowed => 99,
holds_per_record => 99,
{
categorycode => $category->{categorycode},
branchcode => undef,
- itemtype => undef,
rule_name => 'max_holds',
rule_value => 3,
}
{
branchcode => $branch_1,
categorycode => $category->{categorycode},
- itemtype => undef,
rule_name => 'max_holds',
rule_value => 5,
}
$dbh->do("DELETE FROM circulation_rules");
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
+ categorycode => undef,
itemtype => $itemtype,
- branchcode => '*',
+ branchcode => undef,
rules => {
issuelength => 7,
lengthunit => 8,
$dbh->do("DELETE FROM circulation_rules");
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
branchcode => undef,
itemtype => undef,
rules => {
$dbh->do("DELETE FROM circulation_rules");
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
branchcode => undef,
itemtype => undef,
rules => {
$dbh->do("DELETE FROM circulation_rules");
Koha::CirculationRules->set_rules(
{
- categorycode => undef,
branchcode => undef,
itemtype => undef,
rules => {
Koha::CirculationRules->set_rules(
{
itemtype => undef,
- categorycode => undef,
branchcode => undef,
rules => {
holdallowed => 2,
rule_name => 'holdallowed',
rule_value => 1,
branchcode => undef,
- categorycode => undef,
itemtype => undef,
}
);
rule_name => 'holdallowed',
rule_value => 2,
branchcode => undef,
- categorycode => undef,
itemtype => undef,
}
);
rule_name => 'holdallowed',
rule_value => 2,
branchcode => undef,
- categorycode => undef,
itemtype => undef,
}
);
{
branchcode => $library_A,
itemtype => $itemtype,
- categorycode => undef,
rules => {
holdallowed => 2,
returnbranch => 'homebranch',
{
branchcode => undef,
itemtype => undef,
- categorycode => undef,
rules => {
holdallowed => 2,
hold_fulfillment_policy => 'homebranch',
{
branchcode => undef,
itemtype => undef,
- categorycode => undef,
rules => {
holdallowed => 2,
hold_fulfillment_policy => 'holdingbranch',
{
branchcode => undef,
itemtype => undef,
- categorycode => undef,
rules => {
holdallowed => 2,
hold_fulfillment_policy => 'any',
{
branchcode => undef,
itemtype => undef,
- categorycode => undef,
rules => {
holdallowed => 2,
hold_fulfillment_policy => 'any',
use Modern::Perl;
-use Test::More tests => 4;
+use Test::More tests => 3;
+use Test::Deep qw( cmp_methods );
+use Test::Exception;
use Benchmark;
subtest 'get_effective_issuing_rule' => sub {
plan tests => 3;
- my $patron = $builder->build({ source => 'Borrower' });
- my $item = $builder->build({ source => 'Item' });
-
- my $categorycode = $patron->{'categorycode'};
- my $itemtype = $item->{'itype'};
- my $branchcode = $item->{'homebranch'};
+ my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
+ my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'};
+ my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'};
subtest 'Call with undefined values' => sub {
- plan tests => 4;
+ plan tests => 5;
my $rule;
Koha::CirculationRules->delete;
is($rule, undef, 'When I attempt to get effective issuing rule by'
.' providing undefined values, then undef is returned.');
ok(Koha::CirculationRule->new({
- branchcode => '*',
- categorycode => '*',
- itemtype => '*',
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
rule_name => 'fine',
- })->store, 'Given I added an issuing rule branchcode => *,'
- .' categorycode => *, itemtype => *,');
+ })->store, 'Given I added an issuing rule branchcode => undef,'
+ .' categorycode => undef, itemtype => undef,');
$rule = Koha::CirculationRules->get_effective_rule({
- branchcode => '*',
- categorycode => '*',
- itemtype => '*',
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
rule_name => 'fine',
});
- ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective'
+ _is_row_match(
+ $rule,
+ {
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef
+ },
+ 'When I attempt to get effective'
.' issuing rule by providing undefined values, then the above one is'
- .' returned.');
+ .' returned.'
+ );
};
subtest 'Get effective issuing rule in correct order' => sub {
- plan tests => 18;
+ plan tests => 26;
my $rule;
Koha::CirculationRules->delete;
.' is returned.');
ok(Koha::CirculationRule->new({
- branchcode => '*',
- categorycode => '*',
- itemtype => '*',
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
rule_name => 'fine',
- })->store, 'Given I added an issuing rule branchcode => *, categorycode => *, itemtype => *,');
+ })->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,');
$rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
ok(Koha::CirculationRule->new({
- branchcode => '*',
- categorycode => '*',
+ branchcode => undef,
+ categorycode => undef,
itemtype => $itemtype,
rule_name => 'fine',
- })->store, "Given I added an issuing rule branchcode => *, categorycode => *, itemtype => $itemtype,");
+ })->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,");
$rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, '*', '*', $itemtype), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => $itemtype
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
ok(Koha::CirculationRule->new({
- branchcode => '*',
+ branchcode => undef,
categorycode => $categorycode,
- itemtype => '*',
+ itemtype => undef,
rule_name => 'fine',
- })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => *,");
+ })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,");
$rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, '*', $categorycode, '*'), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => undef,
+ categorycode => $categorycode,
+ itemtype => undef
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
ok(Koha::CirculationRule->new({
- branchcode => '*',
+ branchcode => undef,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
- })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => $itemtype,");
+ })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,");
$rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, '*', $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => undef,
+ categorycode => $categorycode,
+ itemtype => $itemtype
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
ok(Koha::CirculationRule->new({
branchcode => $branchcode,
- categorycode => '*',
- itemtype => '*',
+ categorycode => undef,
+ itemtype => undef,
rule_name => 'fine',
- })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => '*',");
+ })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,");
$rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, $branchcode, '*', '*'), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => $branchcode,
+ categorycode => undef,
+ itemtype => undef
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
ok(Koha::CirculationRule->new({
branchcode => $branchcode,
- categorycode => '*',
+ categorycode => undef,
itemtype => $itemtype,
rule_name => 'fine',
- })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => $itemtype,");
+ })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,");
$rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, $branchcode, '*', $itemtype), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => $branchcode,
+ categorycode => undef,
+ itemtype => $itemtype
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
ok(Koha::CirculationRule->new({
branchcode => $branchcode,
categorycode => $categorycode,
- itemtype => '*',
+ itemtype => undef,
rule_name => 'fine',
- })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => '*',");
+ })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,");
$rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, $branchcode, $categorycode, '*'), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ itemtype => undef
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
ok(Koha::CirculationRule->new({
branchcode => $branchcode,
itemtype => $itemtype,
rule_name => 'fine',
});
- ok(_row_match($rule, $branchcode, $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
- .' then the above one is returned.');
+ _is_row_match(
+ $rule,
+ {
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ itemtype => $itemtype
+ },
+ 'When I attempt to get effective issuing rule,'
+ .' then the above one is returned.'
+ );
};
subtest 'Performance' => sub {
};
};
-subtest 'get_opacitemholds_policy' => sub {
- plan tests => 4;
- my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
- my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
- my $library = $builder->build_object({ class => 'Koha::Libraries' });
- my $patron = $builder->build_object({ class => 'Koha::Patrons' });
- my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
- my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { itemtype => $itemtype->itemtype, biblionumber => $biblio->biblionumber } } );
- my $item = $builder->build_object(
- { class => 'Koha::Items',
- value => {
- homebranch => $library->branchcode,
- holdingbranch => $library->branchcode,
- notforloan => 0,
- itemlost => 0,
- withdrawn => 0,
- biblionumber => $biblio->biblionumber,
- biblioitemnumber => $biblioitem->biblioitemnumber,
- itype => $itype->itemtype,
- }
- }
- );
-
- Koha::IssuingRules->delete;
- Koha::IssuingRule->new({categorycode => '*', itemtype => '*', branchcode => '*', opacitemholds => "N"})->store;
- Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype, branchcode => '*', opacitemholds => "Y"})->store;
- Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "N"})->store;
- t::lib::Mocks::mock_preference('item-level_itypes', 1);
- my $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
- is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itype');
- t::lib::Mocks::mock_preference('item-level_itypes', 0);
- $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
- is ( $opacitemholds, 'N', 'Patrons cannot place a hold on this itemtype');
-
- Koha::IssuingRules->delete;
- Koha::IssuingRule->new({categorycode => '*', itemtype => '*', branchcode => '*', opacitemholds => "N"})->store;
- Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype, branchcode => '*', opacitemholds => "N"})->store;
- Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "Y"})->store;
- t::lib::Mocks::mock_preference('item-level_itypes', 1);
- $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
- is ( $opacitemholds, 'N', 'Patrons cannot place a hold on this itype');
- t::lib::Mocks::mock_preference('item-level_itypes', 0);
- $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
- is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itemtype');
-
- $patron->delete;
-};
-
-subtest 'get_onshelfholds_policy' => sub {
+subtest 'set_rule' => sub {
plan tests => 3;
- t::lib::Mocks::mock_preference('item-level_itypes', 1);
- Koha::IssuingRules->delete;
+ my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'};
+ my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
+ my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'};
- my $patron = $builder->build_object({ class => 'Koha::Patrons' });
- my $item = $builder->build_object({ class => 'Koha::Items' });
+ subtest 'Correct call' => sub {
+ plan tests => 4;
- is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), undef, 'Should return undef when no rules can be found' );
- Koha::IssuingRule->new({ categorycode => $patron->categorycode, itemtype => $item->itype, branchcode => '*', onshelfholds => "0" })->store;
- is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 0, 'Should be zero' );
- Koha::IssuingRule->new({ categorycode => $patron->categorycode, itemtype => $item->itype, branchcode => $item->holdingbranch, onshelfholds => "2" })->store;
- is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 2, 'Should be two now' );
+ Koha::CirculationRules->delete;
+
+ lives_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ rule_name => 'refund',
+ rule_value => '',
+ } );
+ }, 'setting refund with branch' );
+
+ lives_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ rule_name => 'patron_maxissueqty',
+ rule_value => '',
+ } );
+ }, 'setting patron_maxissueqty with branch/category succeeds' );
+
+ lives_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ itemtype => $itemtype,
+ rule_name => 'holdallowed',
+ rule_value => '',
+ } );
+ }, 'setting holdallowed with branch/itemtype succeeds' );
+
+ lives_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ rule_name => 'fine',
+ rule_value => '',
+ } );
+ }, 'setting fine with branch/category/itemtype succeeds' );
+ };
+
+ subtest 'Call with missing params' => sub {
+ plan tests => 4;
+
+ Koha::CirculationRules->delete;
+
+ throws_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ rule_name => 'refund',
+ rule_value => '',
+ } );
+ }, qr/branchcode/, 'setting refund without branch fails' );
+
+ throws_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ rule_name => 'patron_maxissueqty',
+ rule_value => '',
+ } );
+ }, qr/categorycode/, 'setting patron_maxissueqty without categorycode fails' );
+
+ throws_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ rule_name => 'holdallowed',
+ rule_value => '',
+ } );
+ }, qr/itemtype/, 'setting holdallowed without itemtype fails' );
+
+ throws_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ rule_name => 'fine',
+ rule_value => '',
+ } );
+ }, qr/itemtype/, 'setting fine without itemtype fails' );
+ };
+
+ subtest 'Call with extra params' => sub {
+ plan tests => 3;
+
+ Koha::CirculationRules->delete;
+
+ throws_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ rule_name => 'refund',
+ rule_value => '',
+ } );
+ }, qr/categorycode/, 'setting refund with categorycode fails' );
+
+ throws_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ rule_name => 'patron_maxissueqty',
+ rule_value => '',
+ } );
+ }, qr/itemtype/, 'setting patron_maxissueqty with itemtype fails' );
+
+ throws_ok( sub {
+ Koha::CirculationRules->set_rule( {
+ branchcode => $branchcode,
+ rule_name => 'holdallowed',
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ rule_value => '',
+ } );
+ }, qr/categorycode/, 'setting holdallowed with categorycode fails' );
+ };
};
subtest 'delete' => sub {
};
-sub _row_match {
- my ($rule, $branchcode, $categorycode, $itemtype) = @_;
+sub _is_row_match {
+ my ( $rule, $expected, $message ) = @_;
- return $rule->branchcode eq $branchcode && $rule->categorycode eq $categorycode
- && $rule->itemtype eq $itemtype;
+ ok( $rule, $message ) ?
+ cmp_methods( $rule, [ %$expected ], $message ) :
+ fail( $message );
}
$schema->storage->txn_rollback;
}
}
);
+ my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $generated_other_rule = $builder->build(
{
source => 'CirculationRule',
value => {
+ branchcode => $branchcode,
categorycode => undef,
itemtype => undef,
rule_name => 'refund',
}
}
);
+ my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $generated_other_rule = $builder->build(
{
source => 'CirculationRule',
value => {
+ branchcode => $branchcode,
categorycode => undef,
itemtype => undef,
rule_name => 'refund',
}
}
);
+ my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $specific_rule_false = $builder->build(
{
source => 'CirculationRule',
value => {
+ branchcode => $branchcode,
categorycode => undef,
itemtype => undef,
rule_name => 'refund',
}
}
);
+ my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
my $specific_rule_true = $builder->build(
{
source => 'CirculationRule',
value => {
+ branchcode => $branchcode2,
categorycode => undef,
itemtype => undef,
rule_name => 'refund',
}
}
);
+ my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $specific_rule_false = $builder->build(
{
source => 'CirculationRule',
value => {
+ branchcode => $branchcode,
categorycode => undef,
itemtype => undef,
rule_name => 'refund',
}
}
);
+ my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
my $specific_rule_true = $builder->build(
{
source => 'CirculationRule',
value => {
+ branchcode => $branchcode2,
categorycode => undef,
itemtype => undef,
rule_name => 'refund',
}
);
# Make sure we have an unused branchcode
+ my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
my $specific_rule_dummy = $builder->build(
{
source => 'CirculationRule',
value => {
+ branchcode => $branchcode3,
categorycode => undef,
itemtype => undef,
rule_name => 'refund',
$dbh->do('DELETE FROM circulation_rules');
Koha::CirculationRules->set_rules(
{
- branchcode => '*',
- categorycode => '*',
- itemtype => '*',
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
rules => {
reservesallowed => 25,
holds_per_record => 1,
Koha::CirculationRules->set_rules(
{
branchcode => $branch_1,
- categorycode => undef,
itemtype => undef,
rules => {
holdallowed => 1,
Koha::CirculationRules->set_rules(
{
branchcode => $branch_2,
- categorycode => undef,
itemtype => undef,
rules => {
holdallowed => 2,
# Test GetMaxPatronHoldsForRecord and GetHoldRule
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
reservesallowed => 1,
holds_per_record => 1,
$itemtype1->{itemtype},
$library->{branchcode}
);
-is( $rule->{categorycode}, '*', 'Got rule with universal categorycode' );
-is( $rule->{itemtype}, '*', 'Got rule with universal itemtype' );
-is( $rule->{branchcode}, '*', 'Got rule with universal branchcode' );
+is( $rule->{categorycode}, undef, 'Got rule with universal categorycode' );
+is( $rule->{itemtype}, undef, 'Got rule with universal itemtype' );
+is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' );
is( $rule->{reservesallowed}, 1, 'Got reservesallowed of 1' );
is( $rule->{holds_per_record}, 1, 'Got holds_per_record of 1' );
Koha::CirculationRules->set_rules(
{
categorycode => $category->{categorycode},
- itemtype => '*',
- branchcode => '*',
+ itemtype => undef,
+ branchcode => undef,
rules => {
reservesallowed => 2,
holds_per_record => 2,
$library->{branchcode}
);
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' );
-is( $rule->{itemtype}, '*', 'Got rule with universal itemtype' );
-is( $rule->{branchcode}, '*', 'Got rule with universal branchcode' );
+is( $rule->{itemtype}, undef, 'Got rule with universal itemtype' );
+is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' );
is( $rule->{reservesallowed}, 2, 'Got reservesallowed of 2' );
is( $rule->{holds_per_record}, 2, 'Got holds_per_record of 2' );
{
categorycode => $category->{categorycode},
itemtype => $itemtype1->{itemtype},
- branchcode => '*',
+ branchcode => undef,
rules => {
reservesallowed => 3,
holds_per_record => 3,
);
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' );
is( $rule->{itemtype}, $itemtype1->{itemtype}, 'Got rule with universal itemtype' );
-is( $rule->{branchcode}, '*', 'Got rule with universal branchcode' );
+is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' );
is( $rule->{reservesallowed}, 3, 'Got reservesallowed of 3' );
is( $rule->{holds_per_record}, 3, 'Got holds_per_record of 3' );
{
categorycode => $category->{categorycode},
itemtype => $itemtype2->{itemtype},
- branchcode => '*',
+ branchcode => undef,
rules => {
reservesallowed => 4,
holds_per_record => 4,
);
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' );
is( $rule->{itemtype}, $itemtype2->{itemtype}, 'Got rule with universal itemtype' );
-is( $rule->{branchcode}, '*', 'Got rule with universal branchcode' );
+is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' );
is( $rule->{reservesallowed}, 4, 'Got reservesallowed of 4' );
is( $rule->{holds_per_record}, 4, 'Got holds_per_record of 4' );
# Test multi-hold via AddReserve
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- itemtype => '*',
- branchcode => '*',
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
rules => {
reservesallowed => 2,
holds_per_record => 2,
$builder = t::lib::TestBuilder->new();
+ my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
my $issuing_rule = $builder->build_object(
{ class => 'Koha::CirculationRules',
value => {
+ branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype
}
Koha::CirculationRules->search()->delete();
Koha::CirculationRules->set_rules(
{
- categorycode => '*',
- branchcode => '*',
- itemtype => '*',
+ categorycode => undef,
+ branchcode => undef,
+ itemtype => undef,
rules => {
reservesallowed => 1,
holds_per_record => 99