use t::lib::Mocks;
use C4::Context;
-use Test::More tests => 6;
+use Test::More tests => 7;
use MARC::Record;
use Koha::Patrons;
+use Koha::Holds;
use C4::Biblio;
use C4::Items;
use Koha::Database;
biblionumber => $biblio->biblionumber,
homebranch => $library4->{branchcode},
holdingbranch => $library3->{branchcode},
- itype => $itemtype
+ itype => $itemtype,
+ exclude_from_local_holds_priority => 0,
},
)->store->itemnumber;
-
my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} );
-
-my $patron_category = $builder->build({ source => 'Category' });
+my $patron_category = $builder->build({ source => 'Category', value => {exclude_from_local_holds_priority => 0} });
# Create some borrowers
my @borrowernumbers;
-foreach ( 1 .. $borrowers_count ) {
+foreach ( 0 .. $borrowers_count-1 ) {
my $borrowernumber = Koha::Patron->new({
firstname => 'my firstname',
surname => 'my surname ' . $_,
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
-ok( $reserve->{borrowernumber} eq $borrowernumbers[1], "Received expected results with HomeLibrary/holdingbranch" );
+ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/holdingbranch" );
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
-ok( $reserve->{borrowernumber} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );
+ok( $reserve->{borrowernumber} eq $borrowernumbers[3], "Received expected results with HomeLibrary/homebranch" );
+
+$schema->storage->txn_rollback;
+
+subtest "exclude from local holds" => sub {
+ plan tests => 3;
+
+ $schema->storage->txn_begin;
+
+ t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
+ t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
+ t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
+
+ my $category_ex = $builder->build_object({ class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 1} });
+ my $category_nex = $builder->build_object({ class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
+
+ my $lib1 = $builder->build_object({ class => 'Koha::Libraries' });
+ my $lib2 = $builder->build_object({ class => 'Koha::Libraries' });
+
+ my $item1 = $builder->build_sample_item({exclude_from_local_holds_priority => 0, homebranch => $lib1->branchcode});
+ my $item2 = $builder->build_sample_item({exclude_from_local_holds_priority => 1, homebranch => $lib1->branchcode});
+
+ my $patron_ex_l2 = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib2->branchcode, categorycode => $category_ex->categorycode}});
+ my $patron_ex_l1 = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib1->branchcode, categorycode => $category_ex->categorycode}});
+ my $patron_nex_l2 = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib2->branchcode, categorycode => $category_nex->categorycode}});
+ my $patron_nex_l1 = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib1->branchcode, categorycode => $category_nex->categorycode}});
+
+ AddReserve(
+ {
+ branchcode => $patron_nex_l2->branchcode,
+ borrowernumber => $patron_nex_l2->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 1,
+ }
+ );
+ AddReserve(
+ {
+ branchcode => $patron_ex_l1->branchcode,
+ borrowernumber => $patron_ex_l1->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 2,
+ }
+ );
+ AddReserve(
+ {
+ branchcode => $patron_nex_l1->branchcode,
+ borrowernumber => $patron_nex_l1->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 3,
+ }
+ );
+
+ my ($status, $reserve, $all_reserves);
+ ($status, $reserve, $all_reserves) = CheckReserves($item1->itemnumber);
+ is($reserve->{borrowernumber}, $patron_nex_l1->borrowernumber, "Patron not excluded with local holds priorities is next checkout");
+
+ Koha::Holds->delete;
+
+ AddReserve(
+ {
+ branchcode => $patron_nex_l2->branchcode,
+ borrowernumber => $patron_nex_l2->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 1,
+ }
+ );
+ AddReserve(
+ {
+ branchcode => $patron_ex_l1->branchcode,
+ borrowernumber => $patron_ex_l1->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 2,
+ }
+ );
+
+ ($status, $reserve, $all_reserves) = CheckReserves($item1->itemnumber);
+ is($reserve->{borrowernumber}, $patron_nex_l2->borrowernumber, "Local patron is excluded from priority");
+
+ Koha::Holds->delete;
+
+ AddReserve(
+ {
+ branchcode => $patron_nex_l2->branchcode,
+ borrowernumber => $patron_nex_l2->borrowernumber,
+ biblionumber => $item2->biblionumber,
+ priority => 1,
+ }
+ );
+ AddReserve(
+ {
+ branchcode => $patron_nex_l1->branchcode,
+ borrowernumber => $patron_nex_l1->borrowernumber,
+ biblionumber => $item2->biblionumber,
+ priority => 2,
+ }
+ );
+
+ ($status, $reserve, $all_reserves) = CheckReserves($item2->itemnumber);
+ is($reserve->{borrowernumber}, $patron_nex_l2->borrowernumber, "Patron from other library is next checkout because item is excluded");
+
+ $schema->storage->txn_rollback;
+};
\ No newline at end of file
use Modern::Perl;
-use Test::More tests => 53;
+use Test::More tests => 54;
use Data::Dumper;
use C4::Calendar;
});
@branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} );
+my $category = $builder->build({ source => 'Category', value => {exclude_from_local_holds_priority => 0} } );
+
my $borrower1 = $builder->build({
source => 'Borrower',
value => {
branchcode => $branchcodes[0],
+ categorycode => $category->{categorycode},
},
});
my $borrower2 = $builder->build({
source => 'Borrower',
value => {
branchcode => $branchcodes[1],
+ categorycode => $category->{categorycode},
},
});
my $borrower3 = $builder->build({
source => 'Borrower',
value => {
branchcode => $branchcodes[2],
+ categorycode => $category->{categorycode},
},
});
$dbh->do(qq{
INSERT INTO biblio (
- frameworkcode,
- author,
- title,
+ frameworkcode,
+ author,
+ title,
datecreated
) VALUES (
- 'SER',
- 'Koha test',
- '$TITLE',
+ 'SER',
+ 'Koha test',
+ '$TITLE',
'2011-02-01'
)
});
$dbh->do(qq{
INSERT INTO biblioitems (
- biblionumber,
+ biblionumber,
itemtype
) VALUES (
- $biblionumber,
+ $biblionumber,
'$itemtype'
)
});
$items_insert_sth = $dbh->prepare(qq{
INSERT INTO items (
- biblionumber,
+ biblionumber,
biblioitemnumber,
barcode,
homebranch,
itemlost,
withdrawn,
onloan,
- itype
+ itype,
+ exclude_from_local_holds_priority
) VALUES (
$biblionumber,
$biblioitemnumber,
0,
0,
NULL,
- '$itemtype'
+ '$itemtype',
+ 0
)
});
# Create 3 items from 2 branches ( branches are for borrowers 1 and 2 respectively )
$dbh->do("DELETE FROM reserves");
my $sth = $dbh->prepare(q{
- INSERT INTO reserves (
+ INSERT INTO reserves (
borrowernumber,
biblionumber,
branchcode,
or BAIL_OUT("Cannot find newly created biblioitems record");
$dbh->do("
- INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
- VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
+ INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype, exclude_from_local_holds_priority)
+ VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype', 0)
");
$dbh->do("
- INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
- VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype')
+ INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype, exclude_from_local_holds_priority)
+ VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype', 0)
");
Koha::CirculationRules->set_rules(
or BAIL_OUT("Cannot find newly created biblioitems record");
$dbh->do("
- INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
- VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
+ INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype, exclude_from_local_holds_priority)
+ VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype', 0)
");
$reserve_id = AddReserve(
or BAIL_OUT("Cannot find newly created biblioitems record");
$dbh->do("
- INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
- VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$itemtype')
+ INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype, exclude_from_local_holds_priority)
+ VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$itemtype', 0)
");
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch
or BAIL_OUT("Cannot find newly created biblioitems record");
$dbh->do("
- INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
- VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$right_itemtype')
+ INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype, exclude_from_local_holds_priority)
+ VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$right_itemtype', 0)
");
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
my $local_patron = $builder->build_object(
{
class => "Koha::Patrons",
value => {
- branchcode => $branch->branchcode
+ branchcode => $branch->branchcode,
+ categorycode => $category->categorycode
}
}
);
{
class => "Koha::Patrons",
value => {
- branchcode => $branch2->branchcode
+ branchcode => $branch2->branchcode,
+ categorycode => $category->categorycode
}
}
);
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
my $local_patron = $builder->build_object(
{
class => "Koha::Patrons",
value => {
- branchcode => $branch->branchcode
+ branchcode => $branch->branchcode,
+ categorycode => $category->categorycode
}
}
);
{
class => "Koha::Patrons",
value => {
- branchcode => $branch2->branchcode
+ branchcode => $branch2->branchcode,
+ categorycode => $category->categorycode
}
}
);
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
my $local_patron = $builder->build_object(
{
class => "Koha::Patrons",
value => {
- branchcode => $branch->branchcode
+ branchcode => $branch->branchcode,
+ categorycode => $category->categorycode,
}
}
);
{
class => "Koha::Patrons",
value => {
- branchcode => $branch2->branchcode
+ branchcode => $branch2->branchcode,
+ categorycode => $category->categorycode,
}
}
);
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
my $local_patron = $builder->build_object(
{
class => "Koha::Patrons",
value => {
- branchcode => $branch->branchcode
+ branchcode => $branch->branchcode,
+ categorycode => $category->categorycode,
}
}
);
{
class => "Koha::Patrons",
value => {
- branchcode => $branch2->branchcode
+ branchcode => $branch2->branchcode,
+ categorycode => $category->categorycode,
}
}
);
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
my $item2 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
my $item3 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
my $patron = $builder->build_object(
{
class => "Koha::Patrons",
value => {
- branchcode => $branch->branchcode
+ branchcode => $branch->branchcode,
+ categorycode => $category->categorycode,
}
}
);
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
my $item2 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
{
biblionumber => $biblio->biblionumber,
library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
$dbh->do("DELETE FROM circulation_rules");
my $library = $builder->build_object({ class => 'Koha::Libraries' });
+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
my $patron_1 = $builder->build_object(
{
class => "Koha::Patrons",
value => {
- branchcode => $library->branchcode
+ branchcode => $library->branchcode,
+ categorycode => $category->categorycode
}
}
);
{
class => "Koha::Patrons",
value => {
- branchcode => $library->branchcode
+ branchcode => $library->branchcode,
+ categorycode => $category->categorycode
}
}
);
{
biblionumber => $biblio->biblionumber,
library => $library->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
my $item_2 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
library => $library->branchcode,
+ exclude_from_local_holds_priority => 0,
}
);
is( $schema->resultset('TransportCost')->count, 2, 'UpdateTransportCostMatrix added two records' );
};
+subtest 'Excludes from local holds priority' => sub {
+ plan tests => 5;
+
+ Koha::Holds->delete;
+
+ t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
+ t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
+ t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
+
+ my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} });
+ my $excluded_category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 1} });
+ my $local_patron_excluded = $builder->build_object(
+ {
+ class => "Koha::Patrons",
+ value => {
+ branchcode => $branch->branchcode,
+ categorycode => $excluded_category->categorycode
+ }
+ }
+ );
+
+ my $local_patron_not_excluded = $builder->build_object(
+ {
+ class => "Koha::Patrons",
+ value => {
+ branchcode => $branch->branchcode,
+ categorycode => $category->categorycode
+ }
+ }
+ );
+
+ my $other_patron = $builder->build_object(
+ {
+ class => "Koha::Patrons",
+ value => {
+ branchcode => $branch2->branchcode,
+ categorycode => $category->categorycode
+ }
+ }
+ );
+
+ my $item1 = $builder->build_sample_item(
+ {
+ library => $branch->branchcode,
+ exclude_from_local_holds_priority => 0,
+ }
+ );
+
+ AddReserve(
+ {
+ branchcode => $other_patron->branchcode,
+ borrowernumber => $other_patron->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 1
+ }
+ );
+
+ AddReserve(
+ {
+ branchcode => $local_patron_excluded->branchcode,
+ borrowernumber => $local_patron_excluded->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 2
+ }
+ );
+
+ AddReserve(
+ {
+ branchcode => $local_patron_not_excluded->branchcode,
+ borrowernumber => $local_patron_not_excluded->borrowernumber,
+ biblionumber => $item1->biblionumber,
+ priority => 3
+ }
+ );
+
+ C4::HoldsQueue::CreateQueue();
+
+ my $queue_rs = $schema->resultset('TmpHoldsqueue');
+ my $next = $queue_rs->next;
+ is($next->borrowernumber, $local_patron_not_excluded->borrowernumber, 'Not excluded local patron is queued');
+
+ my $item2 = $builder->build_sample_item(
+ {
+ biblionumber => $item1->biblionumber,
+ library => $branch->branchcode,
+ exclude_from_local_holds_priority => 1,
+ }
+ );
+ C4::HoldsQueue::CreateQueue();
+
+ $queue_rs = $schema->resultset('TmpHoldsqueue');
+ $next = $queue_rs->next;
+ is($next->borrowernumber, $local_patron_not_excluded->borrowernumber, 'Not excluded local patron is queued');
+ $next = $queue_rs->next;
+ is($next->borrowernumber, $other_patron->borrowernumber, 'Other patron is queued');
+
+ $item1->exclude_from_local_holds_priority(1)->store;
+
+ C4::HoldsQueue::CreateQueue();
+
+ $queue_rs = $schema->resultset('TmpHoldsqueue');
+ $next = $queue_rs->next;
+ is($next->borrowernumber, $other_patron->borrowernumber, 'Other patron is queued');
+ $next = $queue_rs->next;
+ is($next->borrowernumber, $local_patron_excluded->borrowernumber, 'Excluded local patron is queued');
+};
# Cleanup
$schema->storage->txn_rollback;