Bugzilla – Attachment 7033 Details for
Bug 7144
Floating collection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Revised Patch
0001-Enhancement-7144-Floating-Collections-per-branch-ite.patch (text/plain), 22.31 KB, created by
Ian Walls
on 2012-01-03 20:12:07 UTC
(
hide
)
Description:
Revised Patch
Filename:
MIME Type:
Creator:
Ian Walls
Created:
2012-01-03 20:12:07 UTC
Size:
22.31 KB
patch
obsolete
>From 49e91b06558dd4fe6cc39966ef86372b322b52ed Mon Sep 17 00:00:00 2001 >From: Ian Walls <ian.walls@bywatersolutions.com> >Date: Mon, 12 Dec 2011 12:15:35 -0500 >Subject: [PATCH] Enhancement 7144: Floating Collections (per branch/itemtype) > >Adds support for Floating Collections (i.e. items that don't automatically return >home when checked in at another branch) on a per branchcode/itemtype basis. > >This patch adds a new column (returnbranch) to the default_circ_rules, default_branch_item_rules, >default_branch_circ_rules and branch_item_rules tables, after the 'holdsallowed' column. While >this is coded as a varchar(15), the only currently supported values are 'homebranch', 'holdingbranch', >'noreturn' and NULL. > >On upgrade, the value of HomeOrHoldingBranchReturn is used to populate the global default (which is >stored in default_circ_rules.returnbranch). > >To access this value, use C4::Circulation::GetBranchItemRule. This subroutine is altered to supply >an additional key, "returnbranch", containing this value (or 'homebranch' as a default). No existing >usage of GetBranchItemRule should need to be modified. > >The use of HomeOrHoldingBranchReturn is removed in AddReturn to instead use this subroutine. This will >determine, on a more granular level, where the item should be transferred, after all is said and done. If >'noreturn' is specified, then the material will remain at the branch doing the checking in. >--- > C4/Circulation.pm | 34 +++++++---- > admin/smart-rules.pl | 63 ++++++++++--------- > ...dd-returnbranch-to-branch-item-issuing-rules.pl | 20 ++++++ > installer/data/mysql/kohastructure.sql | 4 + > .../prog/en/modules/admin/smart-rules.tt | 44 ++++++++++++++ > 5 files changed, 122 insertions(+), 43 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_7144-add-returnbranch-to-branch-item-issuing-rules.pl > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 9a6f4f2..cabc824 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -1344,13 +1344,17 @@ sub GetBranchBorrowerCircRule { > Retrieves circulation rule attributes that apply to the given > branch and item type, regardless of patron category. > >-The return value is a hashref containing the following key: >+The return value is a hashref containing the following keys: > > holdallowed => Hold policy for this branch and itemtype. Possible values: > 0: No holds allowed. > 1: Holds allowed only by patrons that have the same homebranch as the item. > 2: Holds allowed from any patron. > >+returnbranch => branch to which to return item. Possible values: >+ noreturn: do not return, let item remain where checked in (floating collections) >+ homebranch: return to item's home branch >+ > This searches branchitemrules in the following order: > > * Same branchcode and itemtype >@@ -1358,7 +1362,7 @@ This searches branchitemrules in the following order: > * branchcode '*', same itemtype > * branchcode and itemtype '*' > >-Neither C<$branchcode> nor C<$categorycode> should be '*'. >+Neither C<$branchcode> nor C<$itemtype> should be '*'. > > =cut > >@@ -1368,33 +1372,36 @@ sub GetBranchItemRule { > my $result = {}; > > my @attempts = ( >- ['SELECT holdallowed >+ ['SELECT holdallowed, returnbranch > FROM branch_item_rules > WHERE branchcode = ? > AND itemtype = ?', $branchcode, $itemtype], >- ['SELECT holdallowed >+ ['SELECT holdallowed, returnbranch > FROM default_branch_circ_rules > WHERE branchcode = ?', $branchcode], >- ['SELECT holdallowed >+ ['SELECT holdallowed, returnbranch > FROM default_branch_item_rules > WHERE itemtype = ?', $itemtype], >- ['SELECT holdallowed >+ ['SELECT holdallowed, returnbranch > FROM default_circ_rules'], > ); > > foreach my $attempt (@attempts) { > my ($query, @bind_params) = @{$attempt}; >+ my $search_result = $dbh->selectrow_hashref ( $query , {}, @bind_params ); > > # Since branch/category and branch/itemtype use the same per-branch > # defaults tables, we have to check that the key we want is set, not > # just that a row was returned >- return $result if ( defined( $result->{'holdallowed'} = $dbh->selectrow_array( $query, {}, @bind_params ) ) ); >+ $result->{'holdallowed'} = $search_result->{'holdallowed'} unless ( defined $result->{'holdallowed'} ); >+ $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} ); > } > > # built-in default circulation rule >- return { >- holdallowed => 2, >- }; >+ $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} ); >+ $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} ); >+ >+ return $result; > } > > =head2 AddReturn >@@ -1511,9 +1518,10 @@ sub AddReturn { > my $item = GetItem($itemnumber) or die "GetItem($itemnumber) failed"; > # full item data, but no borrowernumber or checkout info (no issue) > # we know GetItem should work because GetItemnumberFromBarcode worked >- my $hbr = C4::Context->preference("HomeOrHoldingBranchReturn") || "homebranch"; >- $hbr = $item->{$hbr} || ''; >- # item must be from items table -- issues table has branchcode and issuingbranch, not homebranch nor holdingbranch >+ my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch"; >+ # get the proper branch to which to return the item >+ $hbr = $item->{$hbr} || $branch ; >+ # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch) > > my $borrowernumber = $borrower->{'borrowernumber'} || undef; # we don't know if we had a borrower or not > >diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl >index f290934..dcfcfc5 100755 >--- a/admin/smart-rules.pl >+++ b/admin/smart-rules.pl >@@ -135,6 +135,7 @@ elsif ($op eq "set-branch-defaults") { > my $categorycode = $input->param('categorycode'); > my $maxissueqty = $input->param('maxissueqty'); > my $holdallowed = $input->param('holdallowed'); >+ my $returnbranch = $input->param('returnbranch'); > $maxissueqty =~ s/\s//g; > $maxissueqty = undef if $maxissueqty !~ /^\d+/; > $holdallowed =~ s/\s//g; >@@ -144,34 +145,34 @@ 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, holdallowed) >- VALUES (?, ?)"); >+ (maxissueqty, holdallowed, returnbranch) >+ VALUES (?, ?, ?)"); > my $sth_update = $dbh->prepare("UPDATE default_circ_rules >- SET maxissueqty = ?, holdallowed = ?"); >+ SET maxissueqty = ?, holdallowed = ?, returnbranch = ?"); > > $sth_search->execute(); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($maxissueqty, $holdallowed); >+ $sth_update->execute($maxissueqty, $holdallowed, $returnbranch); > } else { >- $sth_insert->execute($maxissueqty, $holdallowed); >+ $sth_insert->execute($maxissueqty, $holdallowed, $returnbranch); > } > } 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, holdallowed) >- VALUES (?, ?, ?)"); >+ (branchcode, maxissueqty, holdallowed, returnbranch) >+ VALUES (?, ?, ?, ?)"); > my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules >- SET maxissueqty = ?, holdallowed = ? >+ SET maxissueqty = ?, holdallowed = ?, returnbranch = ? > WHERE branchcode = ?"); > $sth_search->execute($branch); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($maxissueqty, $holdallowed, $branch); >+ $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch); > } else { >- $sth_insert->execute($branch, $maxissueqty, $holdallowed); >+ $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch); > } > } > } >@@ -258,6 +259,7 @@ elsif ($op eq "add-branch-cat") { > elsif ($op eq "add-branch-item") { > my $itemtype = $input->param('itemtype'); > my $holdallowed = $input->param('holdallowed'); >+ my $returnbranch = $input->param('returnbranch'); > $holdallowed =~ s/\s//g; > $holdallowed = undef if $holdallowed !~ /^\d+/; > >@@ -266,34 +268,34 @@ elsif ($op eq "add-branch-item") { > my $sth_search = $dbh->prepare("SELECT count(*) AS total > FROM default_circ_rules"); > my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules >- (holdallowed) >- VALUES (?)"); >+ (holdallowed, returnbranch) >+ VALUES (?, ?)"); > my $sth_update = $dbh->prepare("UPDATE default_circ_rules >- SET holdallowed = ?"); >+ SET holdallowed = ?, returnbranch = ?"); > > $sth_search->execute(); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($holdallowed); >+ $sth_update->execute($holdallowed, $returnbranch); > } else { >- $sth_insert->execute($holdallowed); >+ $sth_insert->execute($holdallowed, $returnbranch); > } > } else { > my $sth_search = $dbh->prepare("SELECT count(*) AS total > FROM default_branch_item_rules > WHERE itemtype = ?"); > my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules >- (itemtype, holdallowed) >- VALUES (?, ?)"); >+ (itemtype, holdallowed, returnbranch) >+ VALUES (?, ?, ?)"); > my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules >- SET holdallowed = ? >+ SET holdallowed = ?, returnbranch = ? > WHERE itemtype = ?"); > $sth_search->execute($itemtype); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($holdallowed, $itemtype); >+ $sth_update->execute($holdallowed, $returnbranch, $itemtype); > } else { >- $sth_insert->execute($itemtype, $holdallowed); >+ $sth_insert->execute($itemtype, $holdallowed, $returnbranch); > } > } > } elsif ($itemtype eq "*") { >@@ -301,17 +303,17 @@ elsif ($op eq "add-branch-item") { > FROM default_branch_circ_rules > WHERE branchcode = ?"); > my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules >- (branchcode, holdallowed) >- VALUES (?, ?)"); >+ (branchcode, holdallowed, returnbranch) >+ VALUES (?, ?, ?)"); > my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules >- SET holdallowed = ? >+ SET holdallowed = ?, returnbranch = ? > WHERE branchcode = ?"); > $sth_search->execute($branch); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($holdallowed, $branch); >+ $sth_update->execute($holdallowed, $returnbranch, $branch); > } else { >- $sth_insert->execute($branch, $holdallowed); >+ $sth_insert->execute($branch, $holdallowed, $returnbranch); > } > } else { > my $sth_search = $dbh->prepare("SELECT count(*) AS total >@@ -319,19 +321,19 @@ elsif ($op eq "add-branch-item") { > WHERE branchcode = ? > AND itemtype = ?"); > my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules >- (branchcode, itemtype, holdallowed) >- VALUES (?, ?, ?)"); >+ (branchcode, itemtype, holdallowed, returnbranch) >+ VALUES (?, ?, ?, ?)"); > my $sth_update = $dbh->prepare("UPDATE branch_item_rules >- SET holdallowed = ? >+ SET holdallowed = ?, returnbranch = ? > WHERE branchcode = ? > AND itemtype = ?"); > > $sth_search->execute($branch, $itemtype); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($holdallowed, $branch, $itemtype); >+ $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype); > } else { >- $sth_insert->execute($branch, $itemtype, $holdallowed); >+ $sth_insert->execute($branch, $itemtype, $holdallowed, $returnbranch); > } > } > } >@@ -484,6 +486,7 @@ if ($defaults) { > $template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1); > $template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2); > $template->param(default_maxissueqty => $defaults->{maxissueqty}); >+ $template->param(default_returnbranch => $defaults->{returnbranch}); > } > > $template->param(default_rules => ($defaults ? 1 : 0)); >diff --git a/installer/data/mysql/atomicupdate/bug_7144-add-returnbranch-to-branch-item-issuing-rules.pl b/installer/data/mysql/atomicupdate/bug_7144-add-returnbranch-to-branch-item-issuing-rules.pl >new file mode 100644 >index 0000000..dc184e6 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_7144-add-returnbranch-to-branch-item-issuing-rules.pl >@@ -0,0 +1,20 @@ >+#! /usr/bin/perl >+use strict; >+use warnings; >+use C4::Context; >+my $dbh=C4::Context->dbh; >+ >+$dbh->do("ALTER TABLE default_circ_rules ADD >+ COLUMN `returnbranch` varchar(15) default NULL AFTER `holdallowed`"); >+$dbh->do("ALTER TABLE branch_item_rules ADD >+ COLUMN `returnbranch` varchar(15) default NULL AFTER `holdallowed`"); >+$dbh->do("ALTER TABLE default_branch_circ_rules ADD >+ COLUMN `returnbranch` varchar(15) default NULL AFTER `holdallowed`"); >+$dbh->do("ALTER TABLE default_branch_item_rules ADD >+ COLUMN `returnbranch` varchar(15) default NULL AFTER `holdallowed`"); >+ >+# set the default rule to the current value of HomeOrHoldingBranchReturn (default to 'homebranch' if need be) >+my $homeorholdingbranchreturn = C4::Context->prefernce('HomeOrHoldingBranchReturn') || 'homebranch'; >+$dbh->do("UPDATE default_circ_rules SET returnbranch = '$homeorholdingbranchreturn'"); >+ >+print "Upgrade done (Adding 'returnbranch' to branch/item issuing rules tables)\n"; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 5287d9f..5dd343c 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -317,6 +317,7 @@ CREATE TABLE `branch_item_rules` ( > `branchcode` varchar(10) NOT NULL, > `itemtype` varchar(10) NOT NULL, > `holdallowed` tinyint(1) default NULL, >+ `returnbranch` varchar(15) default NULL, > PRIMARY KEY (`itemtype`,`branchcode`), > KEY `branch_item_rules_ibfk_2` (`branchcode`), > CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) >@@ -497,6 +498,7 @@ CREATE TABLE `default_branch_circ_rules` ( > `branchcode` VARCHAR(10) NOT NULL, > `maxissueqty` int(4) default NULL, > `holdallowed` tinyint(1) default NULL, >+ `returnbranch` varchar(15) default NULL, > PRIMARY KEY (`branchcode`), > CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) > ON DELETE CASCADE ON UPDATE CASCADE >@@ -509,6 +511,7 @@ DROP TABLE IF EXISTS `default_branch_item_rules`; > CREATE TABLE `default_branch_item_rules` ( > `itemtype` varchar(10) NOT NULL, > `holdallowed` tinyint(1) default NULL, >+ `returnbranch` varchar(15) default NULL, > PRIMARY KEY (`itemtype`), > CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) > ON DELETE CASCADE ON UPDATE CASCADE >@@ -523,6 +526,7 @@ CREATE TABLE `default_circ_rules` ( > `singleton` enum('singleton') NOT NULL default 'singleton', > `maxissueqty` int(4) default NULL, > `holdallowed` int(1) default NULL, >+ `returnbranch` varchar(15) default NULL, > PRIMARY KEY (`singleton`) > ) ENGINE=InnoDB DEFAULT CHARSET=utf8; > >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 d2f314f..1e3c1e0 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 >@@ -192,6 +192,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > <th> </th> > <th>Total Current Checkouts Allowed</th> > <th>Hold Policy</th> >+ <th>Return Policy</th> > <th> </th> > <th> </th> > </tr> >@@ -223,6 +224,31 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > </option> > </select> > </td> >+ <td> >+ <select name="returnbranch"> >+ [% IF ( default_returnbranch == 'homebranch' ) %] >+ <option value="homebranch" selected="selected"> >+ [% ELSE %] >+ <option value="homebranch"> >+ [% END %] >+ Item Returns Home >+ </option> >+ [% IF ( default_returnbranch == 'holdingbranch' ) %] >+ <option value="holdingbranch" selected="selected"> >+ [% ELSE %] >+ <option value="holdingbranch"> >+ [% END %] >+ Item Returns to Issuing Branch >+ </option> >+ [% IF ( default_returnbranch == 'noreturn' ) %] >+ <option value="noreturn" selected="selected"> >+ [% ELSE %] >+ <option value="noreturn"> >+ [% END %] >+ Item Floats >+ </option> >+ </select> >+ </td> > <td><input type="submit" value="Save" class="submit" /></td> > <td> > <a class="button" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&categorycode=*&branch=[% current_branch %]">Unset</a> >@@ -316,6 +342,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > <tr> > <th>Item Type</th> > <th>Hold Policy</th> >+ <th>Return Policy</th> > <th> </th> > </tr> > [% FOREACH branch_item_rule_loo IN branch_item_rule_loop %] >@@ -338,6 +365,16 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > No Holds Allowed > [% END %] > </td> >+ <td>[% IF ( branch_item_rule_loo.returnbranch == 'homebranch' ) %] >+ Item Returns Home >+ [% ELSIF ( branch_item_rule_loo.returnbranch == 'holdingbranch' ) %] >+ Item Returns to Issuing Branch >+ [% ELSIF ( branch_item_rule_loo.returnbranch == 'noreturn' ) %] >+ Item Floats >+ [% ELSE %] >+ Error - unknown option >+ [% END %] >+ </td> > <td> > <a class="button" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-item&itemtype=[% branch_item_rule_loo.itemtype %]&branch=[% current_branch %]">Delete</a> > </td> >@@ -358,6 +395,13 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > <option value="0">No Holds Allowed</option> > </select> > </td> >+ <td> >+ <select name="returnbranch"> >+ <option value="homebranch">Item Returns Home</option> >+ <option value="holdingbranch">Item Returns to Issuing Branch</option> >+ <option value="noreturn">Item Floats</option> >+ </select> >+ </td> > <td><input type="submit" value="Add" class="submit" /></td> > </tr> > </table> >-- >1.7.4.1 >
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 7144
:
6177
|
6482
|
6891
|
7033
|
7533
|
7899
|
8056