From 20d3352bb51a52ee91a18a4d5e84293d2a097d65 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 10 Jul 2017 11:00:44 -0400 Subject: [PATCH] Bug 18925: Move maxissueqty and maxonsiteissueqty to circulation_rules This patch set moves maxissueqty and maxonsiteissueqty to the circulation_rules table. Test Plan: 1) Apply this patch 2) Run updatedatabase 3) prove t/db_dependent/Circulation.t 4) prove t/db_dependent/Circulation/Branch.t 5) prove t/db_dependent/Circulation/GetHardDueDate.t 6) prove t/db_dependent/Circulation/Returns.t 7) prove t/db_dependent/Circulation/SwitchOnSiteCheckouts.t 8) prove t/db_dependent/Circulation/TooMany.t 9) prove t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t 10) prove t/db_dependent/Reserves.t 11) Note no changes in circulation behavior related to check out limis both on and off site --- C4/Circulation.pm | 125 ++++++----- Koha/CirculationRules.pm | 12 +- admin/smart-rules.pl | 249 +++++++-------------- installer/data/mysql/atomicupdate/bug_18925.perl | 75 +++++++ installer/data/mysql/kohastructure.sql | 37 --- .../prog/en/modules/admin/smart-rules.tt | 76 ++++--- t/db_dependent/Circulation.t | 26 ++- t/db_dependent/Circulation/Branch.t | 60 +++-- t/db_dependent/Circulation/GetHardDueDate.t | 20 +- t/db_dependent/Circulation/Returns.t | 1 - t/db_dependent/Circulation/SwitchOnSiteCheckouts.t | 38 ++-- t/db_dependent/Circulation/TooMany.t | 105 +++++---- .../Holds/DisallowHoldIfItemsAvailable.t | 1 - t/db_dependent/Reserves.t | 14 +- 14 files changed, 440 insertions(+), 399 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18925.perl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index dce77eaaf7..e8f8d5b75a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -387,10 +387,20 @@ sub TooMany { # given branch, patron category, and item type, determine # applicable issuing rule - my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( - { categorycode => $cat_borrower, + my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( + { + categorycode => $cat_borrower, + itemtype => $type, + branchcode => $branch, + rule_name => 'maxissueqty', + } + ); + my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( + { + categorycode => $cat_borrower, itemtype => $type, - branchcode => $branch + branchcode => $branch, + rule_name => 'maxonsiteissueqty', } ); @@ -398,7 +408,7 @@ sub TooMany { # if a rule is found and has a loan limit set, count # how many loans the patron already has that meet that # rule - if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) { + if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) { my @bind_params; my $count_query = q| SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts @@ -406,7 +416,7 @@ sub TooMany { JOIN items USING (itemnumber) |; - my $rule_itemtype = $issuing_rule->itemtype; + my $rule_itemtype = $maxissueqty_rule->itemtype; if ($rule_itemtype eq "*") { # matching rule has the default item type, so count only # those existing loans that don't fall under a more @@ -427,8 +437,8 @@ sub TooMany { AND itemtype <> '*' ) "; } - push @bind_params, $issuing_rule->branchcode; - push @bind_params, $issuing_rule->categorycode; + push @bind_params, $maxissueqty_rule->branchcode; + push @bind_params, $maxissueqty_rule->categorycode; push @bind_params, $cat_borrower; } else { # rule has specific item type, so count loans of that @@ -444,7 +454,7 @@ sub TooMany { $count_query .= " AND borrowernumber = ? "; push @bind_params, $borrower->{'borrowernumber'}; - my $rule_branch = $issuing_rule->branchcode; + my $rule_branch = $maxissueqty_rule->branchcode; if ($rule_branch ne "*") { if (C4::Context->preference('CircControl') eq 'PickupLibrary') { $count_query .= " AND issues.branchcode = ? "; @@ -459,8 +469,8 @@ sub TooMany { my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params ); - my $max_checkouts_allowed = $issuing_rule->maxissueqty; - my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty; + my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0; + my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0; if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { @@ -545,7 +555,7 @@ sub TooMany { } } - if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { + if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; } @@ -1573,14 +1583,11 @@ maxonsiteissueqty - maximum of on-site checkouts that a patron of the given category can have at the given branch. If the value is undef, no limit. -This will first check for a specific branch and -category match from branch_borrower_circ_rules. - -If no rule is found, it will then check default_branch_circ_rules -(same branch, default category). If no rule is found, -it will then check default_borrower_circ_rules (default -branch, same category), then failing that, default_circ_rules -(default branch, default category). +This will check for different branch/category combinations in the following order: +branch and category +branch only +category only +default branch and category If no rule has been found in the database, it will default to the buillt in rule: @@ -1597,44 +1604,54 @@ wildcards. sub GetBranchBorrowerCircRule { my ( $branchcode, $categorycode ) = @_; - my $rules; - my $dbh = C4::Context->dbh(); - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM branch_borrower_circ_rules - WHERE branchcode = ? - AND categorycode = ? - |, {}, $branchcode, $categorycode ) ; - return $rules if $rules; - - # try same branch, default borrower category - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM default_branch_circ_rules - WHERE branchcode = ? - |, {}, $branchcode ) ; - return $rules if $rules; - - # try default branch, same borrower category - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM default_borrower_circ_rules - WHERE categorycode = ? - |, {}, $categorycode ) ; - return $rules if $rules; - - # try default branch, default borrower category - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM default_circ_rules - |, {} ); - return $rules if $rules; + # Set search prededences + my @params = ( + { + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => undef, + }, + { + branchcode => $branchcode, + categorycode => undef, + itemtype => undef, + }, + { + branchcode => undef, + categorycode => $categorycode, + itemtype => undef, + }, + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + }, + ); - # built-in default circulation rule - return { - maxissueqty => undef, + # Initialize default values + my $rules = { + maxissueqty => undef, maxonsiteissueqty => undef, }; + + # Search for rules! + foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) { + foreach my $params (@params) { + my $rule = Koha::CirculationRules->search( + { + rule_name => $rule_name, + %$params, + } + )->next(); + + if ( $rule ) { + $rules->{$rule_name} = $rule->rule_value; + last; + } + } + } + + return $rules; } =head2 GetBranchItemRule diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index c800673fcf..82becb1e92 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -145,17 +145,21 @@ sub set_rules { my $itemtype = $params->{itemtype}; my $rules = $params->{rules}; - foreach my $rule (@$rules) { - Koha::CirculationRules->set_rule( + my $rule_objects = []; + while ( my ( $rule_name, $rule_value ) = each %$rules ) { + my $rule_object = Koha::CirculationRules->set_rule( { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, - rule_name => $rule->{rule_name}, - rule_value => $rule->{rule_value}, + rule_name => $rule_name, + rule_value => $rule_value, } ); + push( @$rule_objects, $rule_object ); } + + return $rule_objects; } =head3 type diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index bdeee64e01..f363ab1cfe 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -83,28 +83,22 @@ elsif ($op eq 'delete-branch-cat') { if ($categorycode eq "*") { my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); $sth_delete->execute(); - } else { - my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules - WHERE categorycode = ?"); - $sth_delete->execute($categorycode); } } elsif ($categorycode eq "*") { my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules WHERE branchcode = ?"); $sth_delete->execute($branch); - } else { - my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules - WHERE branchcode = ? - AND categorycode = ?"); - $sth_delete->execute($branch, $categorycode); } - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { - branchcode => $branch, - categorycode => $categorycode, + categorycode => $categorycode eq '*' ? undef : $categorycode, + branchcode => $branch eq '*' ? undef : $branch, itemtype => undef, - rule_name => 'max_holds', - rule_value => undef, + rules => { + max_holds => undef, + maxissueqty => undef, + maxonsiteissueqty => undef, + } } ); } @@ -187,8 +181,6 @@ elsif ($op eq 'add') { firstremind => $firstremind, chargeperiod => $chargeperiod, chargeperiod_charge_at => $chargeperiod_charge_at, - maxissueqty => $maxissueqty, - maxonsiteissueqty => $maxonsiteissueqty, renewalsallowed => $renewalsallowed, renewalperiod => $renewalperiod, norenewalbefore => $norenewalbefore, @@ -216,6 +208,18 @@ elsif ($op eq 'add') { Koha::IssuingRule->new()->set($params)->store(); } + Koha::CirculationRules->set_rules( + { + categorycode => $bor, + itemtype => $itemtype, + branchcode => $br, + rules => { + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); + } elsif ($op eq "set-branch-defaults") { my $categorycode = $input->param('categorycode'); @@ -238,35 +242,59 @@ elsif ($op eq "set-branch-defaults") { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_circ_rules"); my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules - (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) - VALUES (?, ?, ?, ?, ?)"); + (holdallowed, hold_fulfillment_policy, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_circ_rules - SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); + SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); + $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); } else { - $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); + $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); } + + Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => undef, + rules => { + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_branch_circ_rules WHERE branchcode = ?"); my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules - (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) - VALUES (?, ?, ?, ?, ?, ?)"); + (branchcode, holdallowed, hold_fulfillment_policy, returnbranch) + VALUES (?, ?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules - SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? + SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? WHERE branchcode = ?"); $sth_search->execute($branch); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); + $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); } else { - $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); + $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch); } + + Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => $branch, + rules => { + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); } Koha::CirculationRules->set_rule( { @@ -292,126 +320,56 @@ elsif ($op eq "add-branch-cat") { if ($branch eq "*") { if ($categorycode eq "*") { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM default_circ_rules"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO default_circ_rules - (maxissueqty, maxonsiteissueqty, max_holds) - VALUES (?, ?, ?) - |); - my $sth_update = $dbh->prepare(q| - UPDATE default_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ?, - max_holds = ? - |); - - $sth_search->execute(); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute( $maxissueqty, $maxonsiteissueqty ); - } else { - $sth_insert->execute( $maxissueqty, $maxonsiteissueqty ); - } - - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { - branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'max_holds', - rule_value => $max_holds, + branchcode => undef, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } } ); } else { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM default_borrower_circ_rules - WHERE categorycode = ?"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO default_borrower_circ_rules - (categorycode, maxissueqty, maxonsiteissueqty) - VALUES ( ?, ?, ?) - |); - my $sth_update = $dbh->prepare(q| - UPDATE default_borrower_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ?, - WHERE categorycode = ? - |); - $sth_search->execute($categorycode); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode ); - } else { - $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty ); - } - - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { branchcode => undef, categorycode => $categorycode, itemtype => undef, - rule_name => 'max_holds', - rule_value => $max_holds, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } } ); } } elsif ($categorycode eq "*") { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM default_branch_circ_rules - WHERE branchcode = ?"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO default_branch_circ_rules - (branchcode, maxissueqty, maxonsiteissueqty) - VALUES (?, ?, ?) - |); - my $sth_update = $dbh->prepare(q| - UPDATE default_branch_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ? - WHERE branchcode = ? - |); - $sth_search->execute($branch); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch); - } else { - $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty); - } - } else { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM branch_borrower_circ_rules - WHERE branchcode = ? - AND categorycode = ?"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO branch_borrower_circ_rules - (branchcode, categorycode, maxissueqty, maxonsiteissueqty, max_holds) - VALUES (?, ?, ?, ?, ?) - |); - my $sth_update = $dbh->prepare(q| - UPDATE branch_borrower_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ? - max_holds = ? - WHERE branchcode = ? - AND categorycode = ? - |); - - $sth_search->execute($branch, $categorycode); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $max_holds, $branch, $categorycode); - } else { - $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds); - } - - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { + categorycode => undef, + itemtype => undef, branchcode => $branch, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); + } else { + Koha::CirculationRules->set_rules( + { categorycode => $categorycode, itemtype => undef, - rule_name => 'max_holds', - rule_value => $max_holds, + branchcode => $branch, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } } ); } @@ -579,40 +537,6 @@ while (my $row = $sth2->fetchrow_hashref) { my @sorted_row_loop = sort by_category_and_itemtype @row_loop; -my $sth_branch_cat; -if ($branch eq "*") { - $sth_branch_cat = $dbh->prepare(" - SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode - FROM default_borrower_circ_rules - JOIN categories USING (categorycode) - - "); - $sth_branch_cat->execute(); -} else { - $sth_branch_cat = $dbh->prepare(" - SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode - FROM branch_borrower_circ_rules - JOIN categories USING (categorycode) - WHERE branch_borrower_circ_rules.branchcode = ? - "); - $sth_branch_cat->execute($branch); -} - -my @branch_cat_rules = (); -while (my $row = $sth_branch_cat->fetchrow_hashref) { - push @branch_cat_rules, $row; -} -my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules; - -# note undef maxissueqty so that template can deal with them -foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { - $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty}); - $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty}); - $entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds}); -} - -@sorted_row_loop = sort by_category_and_itemtype @row_loop; - my $sth_branch_item; if ($branch eq "*") { $sth_branch_item = $dbh->prepare(" @@ -653,7 +577,6 @@ foreach my $entry (@sorted_branch_item_rules) { $template->param(show_branch_cat_rule_form => 1); $template->param(branch_item_rule_loop => \@sorted_branch_item_rules); -$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules); my $sth_defaults; if ($branch eq "*") { diff --git a/installer/data/mysql/atomicupdate/bug_18925.perl b/installer/data/mysql/atomicupdate/bug_18925.perl new file mode 100644 index 0000000000..b80dd29d65 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_18925.perl @@ -0,0 +1,75 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, NULL, 'maxissueqty', maxissueqty + FROM branch_borrower_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM branch_borrower_circ_rules + "); + $dbh->do("DROP TABLE branch_borrower_circ_rules"); + } + + if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, NULL, NULL, 'maxissueqty', maxissueqty + FROM default_borrower_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM default_borrower_circ_rules + "); + $dbh->do("DROP TABLE default_borrower_circ_rules"); + } + + if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, NULL, NULL, 'maxissueqty', maxissueqty + FROM default_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM default_circ_rules + "); + $dbh->do("ALTER TABLE default_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); + } + + if ( column_exists( 'default_branch_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, branchcode, NULL, 'maxissueqty', maxissueqty + FROM default_branch_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM default_branch_circ_rules + "); + $dbh->do("ALTER TABLE default_branch_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); + } + + if ( column_exists( 'issuingrules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, itemtype, 'maxissueqty', maxissueqty + FROM issuingrules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, itemtype, 'maxonsiteissueqty', maxonsiteissueqty + FROM issuingrules + "); + $dbh->do("ALTER TABLE issuingrules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18925 - Move maxissueqty and maxonsiteissueqty to circulation_rules)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index c4d47d2dfb..5c53f92745 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -341,45 +341,12 @@ CREATE TABLE collections_tracking ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- --- Table structure for table `branch_borrower_circ_rules` --- - -DROP TABLE IF EXISTS `branch_borrower_circ_rules`; -CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category" - `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode) - `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode) - `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch - `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch - PRIMARY KEY (`categorycode`, `branchcode`), - CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) - ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) - ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - --- --- Table structure for table `default_borrower_circ_rules` --- - -DROP TABLE IF EXISTS `default_borrower_circ_rules`; -CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy" - `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul - `maxissueqty` int(4) default NULL, - `maxonsiteissueqty` int(4) default NULL, - PRIMARY KEY (`categorycode`), - CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) - ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - --- -- Table structure for table `default_branch_circ_rules` -- DROP TABLE IF EXISTS `default_branch_circ_rules`; CREATE TABLE `default_branch_circ_rules` ( `branchcode` VARCHAR(10) NOT NULL, - `maxissueqty` int(4) default NULL, - `maxonsiteissueqty` int(4) default NULL, `holdallowed` tinyint(1) default NULL, hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode `returnbranch` varchar(15) default NULL, @@ -395,8 +362,6 @@ CREATE TABLE `default_branch_circ_rules` ( DROP TABLE IF EXISTS `default_circ_rules`; CREATE TABLE `default_circ_rules` ( `singleton` enum('singleton') NOT NULL default 'singleton', - `maxissueqty` int(4) default NULL, - `maxonsiteissueqty` int(4) default NULL, `holdallowed` int(1) default NULL, hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode `returnbranch` varchar(15) default NULL, @@ -844,8 +809,6 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period `accountsent` int(11) default NULL, -- not used? always NULL `chargename` varchar(100) default NULL, -- not used? always NULL - `maxissueqty` int(4) default NULL, -- total number of checkouts allowed - `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours) `hardduedate` date default NULL, -- hard due date diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 32febcc6c1..1512590e28 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -1,8 +1,17 @@ [% USE raw %] [% USE Asset %] [% USE Branches %] +[% USE Categories %] [% USE CirculationRules %] [% SET footerjs = 1 %] + +[% SET branchcode = humanbranch %] + +[% SET categorycodes = ['*'] %] +[% FOREACH pc IN patron_categories %] + [% categorycodes.push( pc.id ) %] +[% END %] + [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Circulation and fine rules [% INCLUDE 'doc-head-close.inc' %] @@ -117,18 +126,22 @@ Delete - [% IF ( rule.unlimited_maxissueqty ) %] - Unlimited - [% ELSE %] - [% rule.maxissueqty | html %] - [% END %] - - [% IF rule.unlimited_maxonsiteissueqty %] + + [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %] + [% IF rule_value %] + [% rule_value | html %] + [% ELSE %] Unlimited + [% END %] + + + [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %] + [% IF rule_value %] + [% rule_value | html %] [% ELSE %] - [% rule.maxonsiteissueqty | html %] + Unlimited [% END %] - + [% rule.issuelength | html %] [% rule.lengthunit | html %] @@ -377,8 +390,14 @@ Defaults[% UNLESS ( default_rules ) %] (not set)[% END %] - - + + [% SET maxissueqty = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %] + + + + [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %] + + [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %] @@ -494,28 +513,32 @@ Total holds allowed   - [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %] - [% UNLESS ( loop.odd ) %] - - [% ELSE %] + [% FOREACH c IN categorycodes %] + [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %] + [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %] + [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %] + + [% IF maxissueqty || maxissueqty || max_holds %] - [% END %] - [% IF ( branch_cat_rule_loo.default_humancategorycode ) %] + + [% IF c == '*'%] Default [% ELSE %] - [% branch_cat_rule_loo.humancategorycode | html %] + [% Categories.GetName(c) | html %] [% END %] - [% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %] - Unlimited + + [% IF maxissueqty %] + [% maxissueqty | html %] [% ELSE %] - [% branch_cat_rule_loo.maxissueqty | html %] + Unlimited [% END %] - [% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %] - Unlimited + + [% IF maxonsiteissueqty %] + [% maxonsiteissueqty | html %] [% ELSE %] - [% branch_cat_rule_loo.maxonsiteissueqty | html %] + Unlimited [% END %] @@ -523,14 +546,15 @@ [% IF rule_value.defined && rule_value != '' %] [% rule_value | html %] [% ELSE %] - Unlimited + Unlimited [% END %] - Delete + Delete + [% END %] [% END %] diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 09d4d0adb6..68581c5bb9 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -37,6 +37,7 @@ use Koha::Database; use Koha::IssuingRules; use Koha::Checkouts; use Koha::Patrons; +use Koha::CirculationRules; use Koha::Subscriptions; use Koha::Account::Lines; use Koha::Account::Offsets; @@ -186,14 +187,15 @@ is( # Set a simple circ policy $dbh->do('DELETE FROM issuingrules'); +Koha::CirculationRules->search()->delete(); $dbh->do( q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, - maxissueqty, issuelength, lengthunit, + issuelength, lengthunit, renewalsallowed, renewalperiod, norenewalbefore, auto_renew, fine, chargeperiod) VALUES (?, ?, ?, ?, - ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ? @@ -201,7 +203,7 @@ $dbh->do( }, {}, '*', '*', '*', 25, - 20, 14, 'days', + 14, 'days', 1, 7, undef, 0, .10, 1 @@ -1039,18 +1041,29 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $dbh->do('DELETE FROM issues'); $dbh->do('DELETE FROM items'); $dbh->do('DELETE FROM issuingrules'); + Koha::CirculationRules->search()->delete(); $dbh->do( q{ - INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod, - norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) + INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod, + norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) }, {}, '*', '*', '*', 25, - 20, 14, 'days', + 14, 'days', 1, 7, undef, 0, .10, 1 ); + Koha::CirculationRules->set_rules( + { + categorycode => '*', + itemtype => '*', + branchcode => '*', + rules => { + maxissueqty => 20 + } + } + ); my ( $biblionumber, $biblioitemnumber ) = add_biblio(); my $barcode1 = '1234'; @@ -1657,7 +1670,6 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { categorycode => '*', itemtype => '*', branchcode => '*', - maxissueqty => 99, issuelength => 1, firstremind => 1, # 1 day of grace finedays => 2, # 2 days of fine per day of overdue diff --git a/t/db_dependent/Circulation/Branch.t b/t/db_dependent/Circulation/Branch.t index 10bc52e280..22e491dda2 100644 --- a/t/db_dependent/Circulation/Branch.t +++ b/t/db_dependent/Circulation/Branch.t @@ -21,6 +21,7 @@ use C4::Circulation; use C4::Items; use C4::Biblio; use C4::Context; +use Koha::CirculationRules; use Koha::Patrons; @@ -53,7 +54,6 @@ $dbh->do(q|DELETE FROM categories|); $dbh->do(q|DELETE FROM accountlines|); $dbh->do(q|DELETE FROM itemtypes|); $dbh->do(q|DELETE FROM branch_item_rules|); -$dbh->do(q|DELETE FROM branch_borrower_circ_rules|); $dbh->do(q|DELETE FROM default_branch_circ_rules|); $dbh->do(q|DELETE FROM default_circ_rules|); $dbh->do(q|DELETE FROM default_branch_item_rules|); @@ -152,31 +152,53 @@ is_deeply( "Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined" ); -my $query = q| - INSERT INTO branch_borrower_circ_rules - (branchcode, categorycode, maxissueqty, maxonsiteissueqty) - VALUES( ?, ?, ?, ? ) -|; - -$dbh->do( - $query, {}, - $samplebranch1->{branchcode}, - $samplecat->{categorycode}, 5, 6 +Koha::CirculationRules->set_rules( + { + branchcode => $samplebranch1->{branchcode}, + categorycode => $samplecat->{categorycode}, + itemtype => undef, + rules => { + maxissueqty => 5, + maxonsiteissueqty => 6, + } + } ); -$query = q| +my $query = q| INSERT INTO default_branch_circ_rules - (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch) - VALUES( ?, ?, ?, ?, ? ) + (branchcode, holdallowed, returnbranch) + VALUES( ?, ?, ? ) |; -$dbh->do( $query, {}, $samplebranch2->{branchcode}, - 3, 2, 1, 'holdingbranch' ); +$dbh->do( $query, {}, $samplebranch2->{branchcode}, 1, 'holdingbranch' ); +Koha::CirculationRules->set_rules( + { + branchcode => $samplebranch2->{branchcode}, + categorycode => undef, + itemtype => undef, + rules => { + maxissueqty => 3, + maxonsiteissueqty => 2, + } + } +); + $query = q| INSERT INTO default_circ_rules - (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch) - VALUES( ?, ?, ?, ?, ? ) + (singleton, holdallowed, returnbranch) + VALUES( ?, ?, ? ) |; -$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' ); +$dbh->do( $query, {}, 'singleton', 3, 'homebranch' ); +Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + maxissueqty => 4, + maxonsiteissueqty => 5, + } + } +); $query = "INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)"; diff --git a/t/db_dependent/Circulation/GetHardDueDate.t b/t/db_dependent/Circulation/GetHardDueDate.t index b39c32c3c9..ad8d77786e 100644 --- a/t/db_dependent/Circulation/GetHardDueDate.t +++ b/t/db_dependent/Circulation/GetHardDueDate.t @@ -117,8 +117,6 @@ my $sampleissuingrule1 = { chargename => undef, restrictedtype => 0, accountsent => 0, - maxissueqty => 5, - maxonsiteissueqty => 4, finedays => 0, lengthunit => 'days', renewalperiod => 5, @@ -152,9 +150,7 @@ my $sampleissuingrule2 = { branchcode => $samplebranch2->{branchcode}, categorycode => $samplecat->{categorycode}, itemtype => 'BOOK', - maxissueqty => 2, - maxonsiteissueqty => 1, - renewalsallowed => 0, + renewalsallowed => 'Null', renewalperiod => 2, norenewalbefore => 7, auto_renew => 0, @@ -185,9 +181,7 @@ my $sampleissuingrule3 = { branchcode => $samplebranch1->{branchcode}, categorycode => $samplecat->{categorycode}, itemtype => 'DVD', - maxissueqty => 3, - maxonsiteissueqty => 2, - renewalsallowed => 0, + renewalsallowed => 'Null', renewalperiod => 3, norenewalbefore => 8, auto_renew => 0, @@ -219,8 +213,6 @@ $query = 'INSERT INTO issuingrules ( branchcode, categorycode, itemtype, - maxissueqty, - maxonsiteissueqty, renewalsallowed, renewalperiod, norenewalbefore, @@ -246,14 +238,12 @@ $query = 'INSERT INTO issuingrules ( opacitemholds, cap_fine_to_replacement_price, article_requests - ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; + ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; my $sth = $dbh->prepare($query); $sth->execute( $sampleissuingrule1->{branchcode}, $sampleissuingrule1->{categorycode}, $sampleissuingrule1->{itemtype}, - $sampleissuingrule1->{maxissueqty}, - $sampleissuingrule1->{maxonsiteissueqty}, $sampleissuingrule1->{renewalsallowed}, $sampleissuingrule1->{renewalperiod}, $sampleissuingrule1->{norenewalbefore}, @@ -284,8 +274,6 @@ $sth->execute( $sampleissuingrule2->{branchcode}, $sampleissuingrule2->{categorycode}, $sampleissuingrule2->{itemtype}, - $sampleissuingrule2->{maxissueqty}, - $sampleissuingrule2->{maxonsiteissueqty}, $sampleissuingrule2->{renewalsallowed}, $sampleissuingrule2->{renewalperiod}, $sampleissuingrule2->{norenewalbefore}, @@ -316,8 +304,6 @@ $sth->execute( $sampleissuingrule3->{branchcode}, $sampleissuingrule3->{categorycode}, $sampleissuingrule3->{itemtype}, - $sampleissuingrule3->{maxissueqty}, - $sampleissuingrule3->{maxonsiteissueqty}, $sampleissuingrule3->{renewalsallowed}, $sampleissuingrule3->{renewalperiod}, $sampleissuingrule3->{norenewalbefore}, diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t index bd21347694..92a321c3bd 100644 --- a/t/db_dependent/Circulation/Returns.t +++ b/t/db_dependent/Circulation/Returns.t @@ -54,7 +54,6 @@ my $rule = Koha::IssuingRule->new( categorycode => '*', itemtype => '*', branchcode => '*', - maxissueqty => 99, issuelength => 1, } ); diff --git a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t b/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t index 506423d676..f6a4852d48 100644 --- a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t +++ b/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t @@ -27,6 +27,7 @@ use C4::Context; use Koha::DateUtils qw( dt_from_string ); use Koha::Database; use Koha::Checkouts; +use Koha::CirculationRules; use t::lib::TestBuilder; use t::lib::Mocks; @@ -38,7 +39,6 @@ our $dbh = C4::Context->dbh; $dbh->do(q|DELETE FROM branch_item_rules|); $dbh->do(q|DELETE FROM issues|); -$dbh->do(q|DELETE FROM branch_borrower_circ_rules|); $dbh->do(q|DELETE FROM default_branch_circ_rules|); $dbh->do(q|DELETE FROM default_circ_rules|); $dbh->do(q|DELETE FROM default_branch_item_rules|); @@ -91,12 +91,22 @@ my $issuingrule = $builder->build({ branchcode => $branch->{branchcode}, categorycode => '*', itemtype => '*', - maxissueqty => 2, - maxonsiteissueqty => 1, lengthunit => 'days', issuelength => 5, }, }); +Koha::CirculationRules->search()->delete(); +Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => '*', + itemtype => '*', + rules => { + maxissueqty => 2, + maxonsiteissueqty => 1, + } + } +); C4::Context->_new_userenv ('DUMMY_SESSION_ID'); C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0); @@ -154,16 +164,18 @@ my $yet_another_item = $builder->build({ ( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} ); is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' ); -$dbh->do(q|DELETE FROM issuingrules|); -my $borrower_circ_rule = $builder->build({ - source => 'DefaultCircRule', - value => { - branchcode => $branch->{branchcode}, - categorycode => '*', - maxissueqty => 2, - maxonsiteissueqty => 1, - }, -}); +Koha::CirculationRules->search()->delete(); +Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => '*', + itemtype => '*', + rules => { + maxissueqty => 2, + maxonsiteissueqty => 1, + } + } +); ( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} ); is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' ); is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' ); diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t index a7f19db8f1..c47577e32d 100644 --- a/t/db_dependent/Circulation/TooMany.t +++ b/t/db_dependent/Circulation/TooMany.t @@ -26,6 +26,7 @@ use C4::Context; use Koha::DateUtils qw( dt_from_string ); use Koha::Database; +use Koha::CirculationRules; use t::lib::TestBuilder; use t::lib::Mocks; @@ -43,11 +44,11 @@ $dbh->do(q|DELETE FROM categories|); $dbh->do(q|DELETE FROM accountlines|); $dbh->do(q|DELETE FROM itemtypes|); $dbh->do(q|DELETE FROM branch_item_rules|); -$dbh->do(q|DELETE FROM branch_borrower_circ_rules|); $dbh->do(q|DELETE FROM default_branch_circ_rules|); $dbh->do(q|DELETE FROM default_circ_rules|); $dbh->do(q|DELETE FROM default_branch_item_rules|); $dbh->do(q|DELETE FROM issuingrules|); +Koha::CirculationRules->search()->delete(); my $builder = t::lib::TestBuilder->new(); t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level @@ -106,16 +107,17 @@ subtest 'no rules exist' => sub { subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { plan tests => 4; - my $issuingrule = $builder->build({ - source => 'Issuingrule', - value => { - branchcode => $branch->{branchcode}, - categorycode => $category->{categorycode}, - itemtype => '*', - maxissueqty => 0, - maxonsiteissueqty => 0, + Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => $category->{categorycode}, + itemtype => '*', + rules => { + maxissueqty => 0, + maxonsiteissueqty => 0, + } }, - }); + ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is_deeply( C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ), @@ -214,16 +216,17 @@ subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { plan tests => 4; - my $issuingrule = $builder->build({ - source => 'Issuingrule', - value => { - branchcode => $branch->{branchcode}, - categorycode => $category->{categorycode}, - itemtype => '*', - maxissueqty => 1, - maxonsiteissueqty => 1, - }, - }); + Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => $category->{categorycode}, + itemtype => '*', + rules => { + maxissueqty => 1, + maxonsiteissueqty => 1, + } + } + ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is( C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ), @@ -253,16 +256,17 @@ subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { plan tests => 5; - my $issuingrule = $builder->build({ - source => 'Issuingrule', - value => { - branchcode => $branch->{branchcode}, - categorycode => $category->{categorycode}, - itemtype => '*', - maxissueqty => 1, - maxonsiteissueqty => 1, - }, - }); + Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => $category->{categorycode}, + itemtype => '*', + rules => { + maxissueqty => 1, + maxonsiteissueqty => 1, + } + } + ); my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() ); like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); @@ -308,16 +312,17 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { plan tests => 5; - my $issuingrule = $builder->build({ - source => 'Issuingrule', - value => { - branchcode => $branch->{branchcode}, - categorycode => $category->{categorycode}, - itemtype => '*', - maxissueqty => 1, - maxonsiteissueqty => 1, - }, - }); + Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => $category->{categorycode}, + itemtype => '*', + rules => { + maxissueqty => 1, + maxonsiteissueqty => 1, + } + } + ); my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } ); like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); @@ -366,15 +371,17 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm plan tests => 10; - my $issuingrule = $builder->build({ - source => 'BranchBorrowerCircRule', - value => { - branchcode => $branch->{branchcode}, - categorycode => $category->{categorycode}, - maxissueqty => 1, - maxonsiteissueqty => 1, - }, - }); + Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => $category->{categorycode}, + itemtype => undef, + rules => { + maxissueqty => 1, + maxonsiteissueqty => 1, + } + } + ); my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef ); like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); diff --git a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t index a5237d9aa3..83d4ac9b1f 100755 --- a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t +++ b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t @@ -98,7 +98,6 @@ my $rule = Koha::IssuingRule->new( categorycode => '*', itemtype => '*', branchcode => '*', - maxissueqty => 99, issuelength => 7, lengthunit => 8, reservesallowed => 99, diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 9fe293df34..51915a6f8b 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -201,8 +201,6 @@ $requesters{$branch_3} = Koha::Patron->new({ $dbh->do('DELETE FROM issuingrules'); $dbh->do('DELETE FROM branch_item_rules'); -$dbh->do('DELETE FROM branch_borrower_circ_rules'); -$dbh->do('DELETE FROM default_borrower_circ_rules'); $dbh->do('DELETE FROM default_branch_item_rules'); $dbh->do('DELETE FROM default_branch_circ_rules'); $dbh->do('DELETE FROM default_circ_rules'); @@ -215,18 +213,18 @@ $dbh->do( # CPL allows only its own patrons to request its items $dbh->do( - q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) - VALUES (?, ?, ?, ?)}, + q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch) + VALUES (?, ?, ?)}, {}, - $branch_1, 10, 1, 'homebranch', + $branch_1, 1, 'homebranch', ); # ... while FPL allows anybody to request its items $dbh->do( - q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) - VALUES (?, ?, ?, ?)}, + q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch) + VALUES (?, ?, ?)}, {}, - $branch_2, 10, 2, 'homebranch', + $branch_2, 2, 'homebranch', ); # helper biblio for the bug 10272 regression test -- 2.11.0