return { status => 'cannotReserveFromOtherBranches' };
}
- my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
- my $itembranchcode = $branch_control eq 'holdingbranch' ? $item->holdingbranch : $item->homebranch;
- my $item_library = Koha::Libraries->find( {branchcode => $itembranchcode} );
+ my $item_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
if ( $branchitemrule->{holdallowed} == 3) {
- if($borrower->{branchcode} ne $itembranchcode && !$item_library->validate_hold_sibling( {branchcode => $borrower->{branchcode}} )) {
+ if($borrower->{branchcode} ne $item->homebranch && !$item_library->validate_hold_sibling( {branchcode => $borrower->{branchcode}} )) {
return { status => 'branchNotInHoldGroup' };
}
}
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
next if ($branchitemrule->{'holdallowed'} == 0);
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
- my $library = Koha::Libraries->find({branchcode=>$branch});
+ my $library = Koha::Libraries->find({branchcode=>$item->homebranch});
next if (($branchitemrule->{'holdallowed'} == 3) && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) ));
my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
next if ( ($hold_fulfillment_policy eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{branchcode}})) );
foreach my $i (@items) {
my $reserves_control_branch = GetReservesControlBranch( $i->unblessed(), $patron->unblessed );
my $branchitemrule = C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
- my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
- my $itembranchcode = $branch_control eq 'holdingbranch' ? $item->holdingbranch : $item->homebranch;
- my $item_library = Koha::Libraries->find( {branchcode => $itembranchcode} );
+ my $item_library = Koha::Libraries->find( {branchcode => $i->homebranch} );
$any_available = 1
&& !C4::Context->preference('AllowHoldsOnDamagedItems') )
|| Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
|| $branchitemrule->{holdallowed} == 1 && $patron->branchcode ne $i->homebranch
- || $branchitemrule->{holdallowed} == 3 && !$item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} );
+ || $branchitemrule->{holdallowed} == 3 && !$item_library->validate_hold_sibling( {branchcode => $patron->branchcode} );
}
return $any_available ? 0 : 1;
my $patron = $params->{patron};
my @pickup_locations;
- foreach my $item_of_bib ($self->items) {
+ foreach my $item_of_bib ($self->items->as_list) {
push @pickup_locations, $item_of_bib->pickup_locations( {patron => $patron} );
}
my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
my $library = $branch_control eq 'holdingbranch' ? $self->holding_branch : $self->home_branch;
- #warn $branch_control.' '.$branchitemrule->{holdallowed}.' '.$library->branchcode.' '.$patron->branchcode;
-
my @libs;
if(defined $patron) {
return @libs if $branchitemrule->{holdallowed} == 3 && !$library->validate_hold_sibling( {branchcode => $patron->branchcode} );
$dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_local_hold_group tinyint(1) NOT NULL DEFAULT 0 AFTER ft_search_groups_staff" );
}
- $dbh->do("ALTER TABLE default_branch_circ_rules MODIFY hold_fulfillment_policy ENUM('any', 'holdgroup', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any'");
- $dbh->do("ALTER TABLE default_circ_rules MODIFY hold_fulfillment_policy ENUM('any', 'holdgroup', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any'");
- $dbh->do("ALTER TABLE default_branch_item_rules MODIFY hold_fulfillment_policy ENUM('any', 'holdgroup', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any'");
- $dbh->do("ALTER TABLE branch_item_rules MODIFY hold_fulfillment_policy ENUM('any', 'holdgroup', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any'");
-
# Always end with this (adjust the bug info)
SetVersion( $DBversion );
- print "Upgrade to $DBversion done (Bug 22284 - Add ft_local_hold_group column to library_groups and alter hold_fulfillment_policy in rules tables)\n";
+ print "Upgrade to $DBversion done (Bug 22284 - Add ft_local_hold_group column to library_groups)\n";
}
From any library
</option>
- [% IF holdallowed == 3 %]
+ [% IF holdallowed == 3 %]
<option value="3" selected="selected">
[% ELSE %]
<option value="3">
</option>
[% END %]
- [% IF hold_fulfillment_policy == 'holdgroup' %]
+ [% IF hold_fulfillment_policy == 'holdgroup' %]
<option value="holdgroup" selected="selected">
item's hold group
</option>
<td>
[% IF holdallowed == 2 %]
<span>From any library</span>
- [% ELSIF holdallowed == 3 %]
+ [% ELSIF holdallowed == 3 %]
<span>From local hold group</span>
[% ELSIF holdallowed == 1 %]
<span>From home library</span>
use C4::Context;
-use Test::More tests => 60;
+use Test::More tests => 61;
use MARC::Record;
use C4::Biblio;
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
-$dbh->do('DELETE FROM issuingrules');
-$dbh->do(
- q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
- VALUES (?, ?, ?, ?, ?)},
- {},
- '*', '*', '*', 25, 99
-);
+# Cleanup circulation rules
+$dbh->do('DELETE FROM circulation_rules');
+# $dbh->do(
+# q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
+# VALUES (?, ?, ?, ?, ?)},
+# {},
+# '*', '*', '*', 25, 99
+# );
$dbh->do(
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
VALUES (?, ?, ?, ?, ?)},
Koha::Holds->search->delete;
$dbh->do('DELETE FROM issues');
+ $dbh->do('DELETE FROM issuingrules');
+ $dbh->do('DELETE FROM circulation_rules');
Koha::Items->search->delete;
Koha::Biblios->search->delete;
{},
'*', '*', '*', 25
);
- $dbh->do('DELETE FROM branch_item_rules');
- $dbh->do('DELETE FROM default_branch_circ_rules');
- $dbh->do('DELETE FROM default_branch_item_rules');
- $dbh->do('DELETE FROM default_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
Koha::Items->search->delete;
Koha::Biblios->search->delete;
);
# Insert default circ rule of holds allowed only from local hold group for all libraries
- $dbh->do(
- q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?)},
- {},
- 3, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 2: Patron 1 can place hold
);
# Cleanup default_cirt_rules
- $dbh->do('DELETE FROM default_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
# Insert default circ rule to "any" for library 2
- $dbh->do(
- q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?,?)},
- {},
- $library2->branchcode, 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 4: Patron 3 can place hold
);
# Update default circ rule to "hold group" for library 2
- $dbh->do(
- q{UPDATE default_branch_circ_rules set holdallowed = ?
- WHERE branchcode = ?},
- {},
- 3, $library2->branchcode
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 5: Patron 3 cannot place hold
);
# Cleanup default_branch_cirt_rules
- $dbh->do('DELETE FROM default_branch_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
# Insert default item rule to "any" for itemtype 2
- $dbh->do(
- q{INSERT INTO default_branch_item_rules (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?,?)},
- {},
- $itemtype2->itemtype, 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 6: Patron 3 can place hold
);
# Update default item rule to "hold group" for itemtype 2
- $dbh->do(
- q{UPDATE default_branch_item_rules set holdallowed = ?
- WHERE itemtype = ?},
- {},
- 3, $itemtype2->itemtype
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 7: Patron 3 cannot place hold
);
# Cleanup default_branch_item_rules
- $dbh->do('DELETE FROM default_branch_item_rules');
+ $dbh->do('DELETE FROM circulation_rules');
# Insert branch item rule to "any" for itemtype 2 and library 2
- $dbh->do(
- q{INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?,?,?)},
- {},
- $library2->branchcode, $itemtype2->itemtype, 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 8: Patron 3 can place hold
);
# Update branch item rule to "hold group" for itemtype 2 and library 2
- $dbh->do(
- q{UPDATE branch_item_rules set holdallowed = ?
- WHERE branchcode = ? and itemtype = ?},
- {},
- 3, $library2->branchcode, $itemtype2->itemtype
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 9: Patron 3 cannot place hold
{},
'*', '*', '*', 25
);
- $dbh->do('DELETE FROM branch_item_rules');
- $dbh->do('DELETE FROM default_branch_circ_rules');
- $dbh->do('DELETE FROM default_branch_item_rules');
- $dbh->do('DELETE FROM default_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
Koha::Items->search->delete;
Koha::Biblios->search->delete;
);
# Insert default circ rule of holds allowed only from local hold group for all libraries
- $dbh->do(
- q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?)},
- {},
- 2, 'holdgroup', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
# Test 2: Patron 1 can place hold
);
# Cleanup default_cirt_rules
- $dbh->do('DELETE FROM default_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
# Insert default circ rule to "any" for library 2
- $dbh->do(
- q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?,?)},
- {},
- $library2->branchcode, 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 4: Patron 3 can place hold
);
# Update default circ rule to "hold group" for library 2
- $dbh->do(
- q{UPDATE default_branch_circ_rules set hold_fulfillment_policy = ?
- WHERE branchcode = ?},
- {},
- 'holdgroup', $library2->branchcode
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
# Test 5: Patron 3 cannot place hold
);
# Cleanup default_branch_cirt_rules
- $dbh->do('DELETE FROM default_branch_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
# Insert default item rule to "any" for itemtype 2
- $dbh->do(
- q{INSERT INTO default_branch_item_rules (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?,?)},
- {},
- $itemtype2->itemtype, 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 6: Patron 3 can place hold
);
# Update default item rule to "hold group" for itemtype 2
- $dbh->do(
- q{UPDATE default_branch_item_rules set hold_fulfillment_policy = ?
- WHERE itemtype = ?},
- {},
- 'holdgroup', $itemtype2->itemtype
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
# Test 7: Patron 3 cannot place hold
);
# Cleanup default_branch_item_rules
- $dbh->do('DELETE FROM default_branch_item_rules');
+ $dbh->do('DELETE FROM circulation_rules');
# Insert branch item rule to "any" for itemtype 2 and library 2
- $dbh->do(
- q{INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?,?,?)},
- {},
- $library2->branchcode, $itemtype2->itemtype, 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
# Test 8: Patron 3 can place hold
);
# Update branch item rule to "hold group" for itemtype 2 and library 2
- $dbh->do(
- q{UPDATE branch_item_rules set hold_fulfillment_policy = ?
- WHERE branchcode = ? and itemtype = ?},
- {},
- 'holdgroup', $library2->branchcode, $itemtype2->itemtype
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => $library2->branchcode,
+ itemtype => $itemtype2->itemtype,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
# Test 9: Patron 3 cannot place hold
{},
'*', '*', '*', 25
);
- $dbh->do('DELETE FROM branch_item_rules');
- $dbh->do('DELETE FROM default_branch_circ_rules');
- $dbh->do('DELETE FROM default_branch_item_rules');
- $dbh->do('DELETE FROM default_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
#Case 1: holdallowed any, hold_fulfillment_policy any
- $dbh->do(
- q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?)},
- {},
- 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations');
#Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
#Case 3: holdallowed holdgroup, hold_fulfillment_policy any
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5, 'Returns all libraries that are pickup_locations, when item\'s hombebranch is in patron\' holdgroup');
#Case 4: holdallowed any, hold_fulfillment_policy holdgroup
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 2, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 3 && scalar(@pl_2_4) == 3 && scalar(@pl_1_4) == 3 && scalar(@pl_2_1) == 3, 'Returns libraries in item\'s holdgroup, and that are pickup_locations');
#Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
#Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch is included patron\'s holdgroup, and that are pickup_locations');
#Case 7: holdallowed any, hold_fulfillment_policy homebranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 2, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns homebranch of items in biblio, that are pickup_locations');
#Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
#Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0, 'No pickup locations returned');
#Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 2, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns holdingbranch of items in biblio, that are pickup_locations');
#Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
#Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
#Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
#Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
#Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned');
#Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
{},
'*', '*', '*', 25
);
- $dbh->do('DELETE FROM branch_item_rules');
- $dbh->do('DELETE FROM default_branch_circ_rules');
- $dbh->do('DELETE FROM default_branch_item_rules');
- $dbh->do('DELETE FROM default_circ_rules');
+ $dbh->do('DELETE FROM circulation_rules');
my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
#Case 1: holdallowed any, hold_fulfillment_policy any
- $dbh->do(
- q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
- VALUES (?,?,?)},
- {},
- 2, 'any', 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_1) == scalar(@pl_1_4) && scalar(@pl_1_1) == scalar(@pl_3_1) && scalar(@pl_1_1) == scalar(@pl_3_4), 'All combinations of patron/item renders the same number of locations');
#Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
#Case 3: holdallowed holdgroup, hold_fulfillment_policy any
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
#Case 4: holdallowed any, hold_fulfillment_policy holdgroup
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 2, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1, 'Pickup locations for item 3 renders all libraries in items\'s holdgroup that are pickup_locations');
#Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
#Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
#Case 7: holdallowed any, hold_fulfillment_policy homebranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 2, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
#Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
#Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
#Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 2, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 2,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
#Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
#Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 3, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 3,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
#Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'any'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'any',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
#Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdgroup'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdgroup',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
#Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'homebranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'homebranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
ok(scalar(@pl_3_4) == 0 && scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any combination of patron/item renders no locations');
#Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
- $dbh->do(
- q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
- {},
- 1, 'holdingbranch'
+ Koha::CirculationRules->set_rules(
+ {
+ branchcode => undef,
+ itemtype => undef,
+ categorycode => undef,
+ rules => {
+ holdallowed => 1,
+ hold_fulfillment_policy => 'holdingbranch',
+ returnbranch => 'any'
+ }
+ }
);
@pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
+# Cleanup default_branch_item_rules
+my $dbh = C4::Context->dbh;
+$dbh->do('DELETE FROM circulation_rules');
+
my $builder = t::lib::TestBuilder->new;
my $nb_of_libraries = Koha::Libraries->search->count;
my $new_library_1 = Koha::Library->new({