Bugzilla – Attachment 72831 Details for
Bug 8137
Checkout limit for all libraries
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8137 - Add Default checkout limit by patron category with priority.
Bug-8137---Add-Default-checkout-limit-by-patron-ca.patch (text/plain), 11.56 KB, created by
Alex Arnaud
on 2018-03-14 09:19:06 UTC
(
hide
)
Description:
Bug 8137 - Add Default checkout limit by patron category with priority.
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2018-03-14 09:19:06 UTC
Size:
11.56 KB
patch
obsolete
>From 98a576d58d4b1618533083e718e51c4c631df61c Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Wed, 28 Jun 2017 13:50:20 +0000 >Subject: [PATCH] Bug 8137 - Add Default checkout limit by patron category with > priority. > >This patch add the ability to make a 'Default checkout limit by patron category' >rule has priority. When a rule has priority, it overrides all others >for the same categorycode. For "normal" rule, the behavior is the same >than before (like a default rule if no one is specified at branch level). >Rule with priority can only be created on the circulation and fine rules >page for *all libraries*. The goal is to allow librarian to limit the >total number of checkouts by patron category for all libraries. > >test plan: > > - Create a rule with 4 checkouts allowed in default checkout limit > table > for a patron category and make it has priority, > - create more permissive rules for all other branches (at least 5 > checkouts allowed), > - Checkout items of different branches for a patron with the same > category, > - Patron should be limited to 4 checkouts > >https://bugs.koha-community.org/show_bug.cgi?id=8137 > >Rebased: 2018-03-14, by: Alex Arnaud <alex.arnaud@biblibre.com> >--- > C4/Circulation.pm | 28 +++++++++++++++------- > admin/smart-rules.pl | 16 ++++++++----- > .../Bug_8137-add-column-has_priority.sql | 5 ++++ > .../prog/en/modules/admin/smart-rules.tt | 15 ++++++++++++ > t/db_dependent/Circulation/Branch.t | 26 +++++++++++++++++++- > 5 files changed, 74 insertions(+), 16 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index d583e53..38f4d93 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -417,7 +417,7 @@ sub TooMany { > AND (categorycode = ? OR categorycode = ?) > AND itemtype <> '*' > ) "; >- } else { >+ } else { > $count_query .= " JOIN biblioitems USING (biblionumber) > WHERE biblioitems.itemtype NOT IN ( > SELECT itemtype FROM issuingrules >@@ -502,14 +502,17 @@ sub TooMany { > |; > push @bind_params, $borrower->{borrowernumber}; > >- if (C4::Context->preference('CircControl') eq 'PickupLibrary') { >- $branch_count_query .= " AND issues.branchcode = ? "; >- push @bind_params, $branch; >- } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { >- ; # if branch is the patron's home branch, then count all loans by patron >- } else { >- $branch_count_query .= " AND items.homebranch = ? "; >- push @bind_params, $branch; >+ # Only for specific or default branches. >+ unless ($branch_borrower_circ_rule->{has_priority}) { >+ if (C4::Context->preference('CircControl') eq 'PickupLibrary') { >+ $branch_count_query .= " AND issues.branchcode = ? "; >+ push @bind_params, $branch; >+ } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { >+ ; # if branch is the patron's home branch, then count all loans by patron >+ } else { >+ $branch_count_query .= " AND items.homebranch = ? "; >+ push @bind_params, $branch; >+ } > } > my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params ); > my $max_checkouts_allowed = $branch_borrower_circ_rule->{maxissueqty}; >@@ -1597,6 +1600,13 @@ sub GetBranchBorrowerCircRule { > my $rules; > my $dbh = C4::Context->dbh(); > $rules = $dbh->selectrow_hashref( q| >+ SELECT maxissueqty, maxonsiteissueqty, has_priority >+ FROM default_borrower_circ_rules >+ WHERE categorycode = ? AND has_priority = 1 >+ |, {}, $categorycode ) ; >+ return $rules if $rules; >+ >+ $rules = $dbh->selectrow_hashref( q| > SELECT maxissueqty, maxonsiteissueqty > FROM branch_borrower_circ_rules > WHERE branchcode = ? >diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl >index 718b682..9eb0a26 100755 >--- a/admin/smart-rules.pl >+++ b/admin/smart-rules.pl >@@ -254,10 +254,12 @@ elsif ($op eq "add-branch-cat") { > my $categorycode = $input->param('categorycode'); > my $maxissueqty = $input->param('maxissueqty'); > my $maxonsiteissueqty = $input->param('maxonsiteissueqty'); >+ my $has_priority = $input->param('has_priority'); > $maxissueqty =~ s/\s//g; > $maxissueqty = undef if $maxissueqty !~ /^\d+/; > $maxonsiteissueqty =~ s/\s//g; > $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/; >+ $has_priority = $has_priority ? 1 : 0; > > if ($branch eq "*") { > if ($categorycode eq "*") { >@@ -284,24 +286,26 @@ elsif ($op eq "add-branch-cat") { > } else { > my $sth_search = $dbh->prepare("SELECT count(*) AS total > FROM default_borrower_circ_rules >- WHERE categorycode = ?"); >+ WHERE categorycode = ? >+ AND has_priority = ?"); > my $sth_insert = $dbh->prepare(q| > INSERT INTO default_borrower_circ_rules >- (categorycode, maxissueqty, maxonsiteissueqty) >- VALUES (?, ?, ?) >+ (categorycode, maxissueqty, maxonsiteissueqty, has_priority) >+ VALUES (?, ?, ?, ?) > |); > my $sth_update = $dbh->prepare(q| > UPDATE default_borrower_circ_rules > SET maxissueqty = ?, > maxonsiteissueqty = ? > WHERE categorycode = ? >+ AND has_priority = ? > |); >- $sth_search->execute($categorycode); >+ $sth_search->execute($categorycode, $has_priority); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode); >+ $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode, $has_priority) or die $sth_update->errstr;; > } else { >- $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty); >+ $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty, $has_priority); > } > } > } elsif ($categorycode eq "*") { >diff --git a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql b/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql >new file mode 100644 >index 0000000..fc7c42f >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql >@@ -0,0 +1,5 @@ >+ALTER TABLE default_borrower_circ_rules ADD has_priority INT(1) DEFAULT 0; >+ALTER TABLE default_borrower_circ_rules DROP foreign key borrower_borrower_circ_rules_ibfk_1; >+ALTER TABLE default_borrower_circ_rules DROP primary key; >+ALTER TABLE default_borrower_circ_rules ADD primary key(categorycode, has_priority); >+ALTER TABLE default_borrower_circ_rules ADD CONSTRAINT borrower_borrower_circ_rules_ibfk_1 FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE; >\ No newline at end of file >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 e1a5839..4c47b64 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 >@@ -456,6 +456,10 @@ > <p>If the total amount loanable for a given patron category is left blank, > no limit applies, except possibly for a limit you define for a specific item type. > </p> >+ <p> >+ <b>Has priority: </b>If checked, the rule will override those for all branches. Else >+ it behaves like a default one: used if no rule existe for the coresponding branch. >+ </p> > <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl"> > <input type="hidden" name="op" value="add-branch-cat" /> > <input type="hidden" name="branch" value="[% current_branch %]"/> >@@ -464,6 +468,7 @@ > <th>Patron category</th> > <th>Total current checkouts allowed</th> > <th>Total current on-site checkouts allowed</th> >+ [% UNLESS humanbranch %]<th>Has priority</th>[% END %] > <th> </th> > </tr> > [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %] >@@ -490,6 +495,11 @@ > [% branch_cat_rule_loo.maxonsiteissueqty %] > [% END %] > </td> >+ [% UNLESS humanbranch %] >+ <td> >+ <input type="checkbox" [% IF branch_cat_rule_loo.has_priority %]checked[% END %] disabled/> >+ </td> >+ [% END %] > > <td class="actions"> > <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&categorycode=[% branch_cat_rule_loo.categorycode %]&branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a> >@@ -506,6 +516,11 @@ > </td> > <td><input name="maxissueqty" size="3" /></td> > <td><input name="maxonsiteissueqty" size="3" /></td> >+ [% UNLESS humanbranch %] >+ <td> >+ <input type="checkbox" name="has_priority"/> >+ </td> >+ [% END %] > <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td> > </tr> > </table> >diff --git a/t/db_dependent/Circulation/Branch.t b/t/db_dependent/Circulation/Branch.t >index 1be07d9..764deab 100644 >--- a/t/db_dependent/Circulation/Branch.t >+++ b/t/db_dependent/Circulation/Branch.t >@@ -23,7 +23,7 @@ use C4::Circulation; > use C4::Items; > use C4::Context; > >-use Test::More tests => 14; >+use Test::More tests => 15; > use t::lib::Mocks; > use t::lib::TestBuilder; > >@@ -196,7 +196,15 @@ $sth->execute( > 5, 'noreturn' > ); > >+$query = q| >+ INSERT INTO default_borrower_circ_rules >+ (categorycode, maxissueqty, maxonsiteissueqty, has_priority) >+ VALUES( ?, ?, ?, ? ) >+|; >+$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 0); >+ > #Test GetBranchBorrowerCircRule >+# > is_deeply( > GetBranchBorrowerCircRule(), > { maxissueqty => 4, maxonsiteissueqty => 5 }, >@@ -221,6 +229,22 @@ is_deeply( > "GetBranchBorrower with wrong parameters returns the maxissueqty and maxonsiteissueqty of default_circ_rules" > ); > >+$query = q| >+ INSERT INTO default_borrower_circ_rules >+ (categorycode, maxissueqty, maxonsiteissueqty, has_priority) >+ VALUES( ?, ?, ?, ? ) >+|; >+$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 1); >+ >+is_deeply( >+ GetBranchBorrowerCircRule( >+ $samplebranch1->{branchcode}, >+ $samplecat->{categorycode} >+ ), >+ { maxissueqty => 3, maxonsiteissueqty => 3, has_priority => 1 }, >+ "GetBranchBorrower returns the rule having priority" >+); >+ > #Test GetBranchItemRule > my @lazy_any = ( 'hold_fulfillment_policy' => 'any' ); > is_deeply( >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8137
:
9705
|
9706
|
11079
|
64703
|
64704
|
64791
|
64891
|
72831
|
72832
|
107207
|
107208
|
107209
|
107459
|
111368
|
111369
|
111370
|
112640
|
113797
|
113882
|
114531
|
114532
|
114533
|
114534
|
116676
|
116677
|
116678
|
116679
|
116680
|
145476
|
145477
|
145478
|
145479
|
145480
|
152040
|
152041
|
152042
|
152043
|
152044
|
152045
|
156316
|
156317
|
156318
|
156319
|
156320
|
156321
|
156322
|
159712
|
162367
|
167208
|
167923
|
168119
|
169084
|
169696
|
169700
|
169727
|
169927
|
169928
|
170411
|
173605
|
173608
|
175837
|
175838
|
177464