Bugzilla – Attachment 139026 Details for
Bug 9525
Add option to define float groups and rules for float
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9525: Add option to define float groups and rules for float
Bug-9525-Add-option-to-define-float-groups-and-rul.patch (text/plain), 18.07 KB, created by
ByWater Sandboxes
on 2022-08-11 15:57:20 UTC
(
hide
)
Description:
Bug 9525: Add option to define float groups and rules for float
Filename:
MIME Type:
Creator:
ByWater Sandboxes
Created:
2022-08-11 15:57:20 UTC
Size:
18.07 KB
patch
obsolete
>From e3f577c0413e7d23745ac3d7f8d6056a6c532286 Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@koha-suomi.fi> >Date: Wed, 8 Sep 2021 08:58:14 +0300 >Subject: [PATCH] Bug 9525: Add option to define float groups and rules for > float > >Bug 22284 introduced ability to create hold groups. >We should have ability to create float groups in >same manner. This patch adds checkbox "Is local >float group" to group creation feature and new return >policy "Item floats by librarygroup". > >To test: >1. Add new float group and some libraries to it. >2. From circulation and fine rules, set default >return policy as "Item floats by library group". >3. Check out an item for a patron. >4. Set library as one that belongs in the same >float group. >5. Check in the item. >=> Observe that notice for transfer doesn't pop up. >6. Check out again. >7. This time set library as one that doen's >belong in the same float group. >8. Check in. >=> Observe that notice for transfer pops up. > >Experiment this feature by changing return policy >per library, item type etc. > >Also prove t/db_dependent/Koha/Libraries.t > >Sponsored-by: Koha-Suomi Oy > >Signed-off-by: Lisette Scheer <lisettePalouse+Koha@gmail.com> >--- > C4/Circulation.pm | 14 ++++++- > Koha/Library.pm | 42 +++++++++++++++++++ > admin/library_groups.pl | 4 ++ > circ/returns.pl | 6 ++- > .../prog/en/modules/admin/library_groups.tt | 27 ++++++++++-- > .../prog/en/modules/admin/smart-rules.tt | 10 +++++ > t/db_dependent/Koha/Libraries.t | 32 ++++++++++++++ > 7 files changed, 128 insertions(+), 7 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 9cb56f79d3..a5e7de25e0 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -1937,6 +1937,7 @@ 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 > holdingbranch: return to issuer branch >+ returnbylibrarygroup: if item is returned to float group library, let it float > > This searches branchitemrules in the following order: > >@@ -2096,8 +2097,19 @@ sub AddReturn { > > # full item data, but no borrowernumber or checkout info (no issue) > my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch"; >+ # check if returnbranch and homebranch belong to the same float group >+ my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch }); > # get the proper branch to which to return the item >- my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch; >+ my $returnbranch; >+ if($hbr eq 'noreturn'){ >+ $returnbranch = $branch; >+ }elsif($hbr eq 'returnbylibrarygroup'){ >+ # if library isn't in same the float group, transfer item to homebranch >+ $hbr = 'homebranch'; >+ $returnbranch = $validate_float ? $branch : $item->$hbr; >+ }else{ >+ $returnbranch = $item->$hbr; >+ } > # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch) > my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef; > >diff --git a/Koha/Library.pm b/Koha/Library.pm >index 48e125529b..fbd33532d0 100644 >--- a/Koha/Library.pm >+++ b/Koha/Library.pm >@@ -313,6 +313,48 @@ sub to_api_mapping { > }; > } > >+=head3 get_float_group_libraries >+ >+Return all libraries belonging to the same float group >+ >+=cut >+ >+sub get_float_libraries { >+ my ( $self ) = @_; >+ >+ my $library_groups = $self->library_groups; >+ my @float_libraries; >+ >+ while ( my $library_group = $library_groups->next ) { >+ my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id}); >+ if($root->ft_local_float_group) { >+ push @float_libraries, $root->all_libraries; >+ } >+ } >+ >+ my %seen; >+ @float_libraries = >+ grep { !$seen{ $_->id }++ } @float_libraries; >+ >+ return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } }); >+} >+ >+=head3 validate_float_sibling >+ >+Return if given library is a valid float group member >+ >+=cut >+ >+sub validate_float_sibling { >+ my ( $self, $params ) = @_; >+ >+ return 1 if $params->{branchcode} eq $self->id; >+ >+ my $branchcode = $params->{branchcode}; >+ return $self->get_float_libraries->search( { branchcode => $branchcode } ) >+ ->count > 0; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/admin/library_groups.pl b/admin/library_groups.pl >index 5284a881f4..b0ab345b01 100755 >--- a/admin/library_groups.pl >+++ b/admin/library_groups.pl >@@ -50,6 +50,7 @@ if ( $action eq 'add' ) { > my $ft_search_groups_opac = $cgi->param('ft_search_groups_opac') || 0; > my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0; > my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0; >+ my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0; > > if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) { > $template->param( error_duplicate_title => $title ); >@@ -65,6 +66,7 @@ if ( $action eq 'add' ) { > ft_search_groups_opac => $ft_search_groups_opac, > ft_search_groups_staff => $ft_search_groups_staff, > ft_local_hold_group => $ft_local_hold_group, >+ ft_local_float_group => $ft_local_float_group, > branchcode => $branchcode, > } > )->store(); >@@ -85,6 +87,7 @@ elsif ( $action eq 'edit' ) { > my $ft_search_groups_opac = $cgi->param('ft_search_groups_opac') || 0; > my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0; > my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0; >+ my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0; > > if ($id) { > my $group = Koha::Library::Groups->find($id); >@@ -97,6 +100,7 @@ elsif ( $action eq 'edit' ) { > ft_search_groups_opac => $ft_search_groups_opac, > ft_search_groups_staff => $ft_search_groups_staff, > ft_local_hold_group => $ft_local_hold_group, >+ ft_local_float_group => $ft_local_float_group, > } > )->store(); > >diff --git a/circ/returns.pl b/circ/returns.pl >index ac3260a5e9..c75ea5725d 100755 >--- a/circ/returns.pl >+++ b/circ/returns.pl >@@ -301,8 +301,10 @@ if ($barcode) { > > # make sure return branch respects home branch circulation rules, default to homebranch > my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch"; >- $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch >- >+ my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $userenv_branch }); >+ # get the proper branch to which to return the item >+ # if library isn't in same the float group, transfer item to homelibrary >+ $returnbranch = $hbr eq 'noreturn' ? $userenv_branch : $hbr eq 'returnbylibrarygroup' ? $validate_float ? $userenv_branch : $item->homebranch : $item->$hbr; > my $materials = $item->materials; > my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials }); > $materials = $descriptions->{lib} // $materials; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt >index 9686e1b9c4..87f41112f4 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt >@@ -147,6 +147,12 @@ > Is local hold group > </label> > </p> >+ <p> >+ <label> >+ <input type="checkbox" name="ft_local_float_group" id="add-group-modal-ft_local_float_group" value="1" /> >+ Is local float group >+ </label> >+ </p> > </div> > </div> > </div> >@@ -211,6 +217,12 @@ > Is local hold group > </label> > </p> >+ <p> >+ <label> >+ <input type="checkbox" id="edit-group-modal-ft_local_float_group" name="ft_local_float_group" value="1" /> >+ Is local float group >+ </label> >+ </p> > </div> > </div> > </div> >@@ -291,7 +303,8 @@ > var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac'); > var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff'); > var ft_local_hold_group = $(this).data('groupFt_local_hold_group'); >- edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group ); >+ var ft_local_float_group = $(this).data('groupFt_local_float_group'); >+ edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_local_float_group ); > }); > > $('.delete-group').on('click', function(e) { >@@ -327,6 +340,7 @@ > $('#add-group-modal-ft_search_groups_opac').prop('checked', false); > $('#add-group-modal-ft_search_groups_staff').prop('checked', false); > $('#add-group-modal-ft_local_hold_group').prop('checked', false); >+ $('#add-group-modal-ft_local_float_group').prop('checked', false); > if ( parent_id ) { > $('#root-group-features-add').hide(); > } else { >@@ -336,22 +350,24 @@ > > } > >- function edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group ) { >+ function edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_local_float_group ) { > $('#edit-group-modal-id').val( id ); > $('#edit-group-modal-title').val( title ); > $('#edit-group-modal-description').val( description ); >- >+ console.log(ft_local_float_group); > if ( parent_id ) { > $('#edit-group-modal-ft_hide_patron_info').prop('checked', false); > $('#edit-group-modal-ft_search_groups_opac').prop('checked', false); > $('#edit-group-modal-ft_search_groups_staff').prop('checked', false); > $('#edit-group-modal-ft_local_hold_group').prop('checked', false); >+ $('#edit-group-modal-ft_local_float_group').prop('checked', false); > $('#root-group-features-edit').hide(); > } else { > $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false ); > $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false ); > $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false ); > $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false ); >+ $('#edit-group-modal-ft_local_float_group').prop('checked', ft_local_float_group ? true : false ); > $('#root-group-features-edit').show(); > } > >@@ -407,6 +423,9 @@ > [% IF group.ft_local_hold_group %] > <li>Is local hold group</li> > [% END %] >+ [% IF group.ft_local_float_group %] >+ <li>Is local float group</li> >+ [% END %] > </ul> > [% END %] > </td> >@@ -424,7 +443,7 @@ > </li> > > <li> >- <a class="edit-group" id="edit-group-[% group.id | html %]" href="#" data-group-id="[% group.id | html %]" data-group-parent-id="[% group.parent_id | html %]" data-group-title="[% group.title | html %]" data-group-description="[% group.description | html %]" data-group-ft_hide_patron_info="[% group.ft_hide_patron_info | html %]" data-group-ft_search_groups_opac="[% group.ft_search_groups_opac | html %]" data-group-ft_search_groups_staff="[% group.ft_search_groups_staff | html %]" data-group-ft_local_hold_group="[% group.ft_local_hold_group | html %]" > >+ <a class="edit-group" id="edit-group-[% group.id | html %]" href="#" data-group-id="[% group.id | html %]" data-group-parent-id="[% group.parent_id | html %]" data-group-title="[% group.title | html %]" data-group-description="[% group.description | html %]" data-group-ft_hide_patron_info="[% group.ft_hide_patron_info | html %]" data-group-ft_search_groups_opac="[% group.ft_search_groups_opac | html %]" data-group-ft_search_groups_staff="[% group.ft_search_groups_staff | html %]" data-group-ft_local_hold_group="[% group.ft_local_hold_group | html %]" data-group-ft_local_float_group="[% group.ft_local_float_group | html %]" > > <i class="fa fa-pencil"></i> Edit > </a> > </li> >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 dc0936efe2..faa76e9be9 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 >@@ -766,6 +766,13 @@ > [% END %] > Item floats > </option> >+ [% IF returnbranch.rule_value == 'returnbylibrarygroup' %] >+ <option value="returnbylibrarygroup" selected="selected"> >+ [% ELSE %] >+ <option value="returnbylibrarygroup"> >+ [% END %] >+ Item floats by library group >+ </option> > </select> > </td> > <td class="actions"> >@@ -1233,6 +1240,8 @@ > <span>Item returns to issuing branch</span> > [% ELSIF returnbranch == 'noreturn' %] > <span>Item floats</span> >+ [% ELSIF returnbranch == 'returnbylibrarygroup'%] >+ <span>Item floats by library group</span> > [% END %] > </td> > <td class="actions"> >@@ -1285,6 +1294,7 @@ > <option value="homebranch">Item returns home</option> > <option value="holdingbranch">Item returns to issuing library</option> > <option value="noreturn">Item floats</option> >+ <option value="returnbylibrarygroup">Item floats by library group</option> > </select> > </td> > <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td> >diff --git a/t/db_dependent/Koha/Libraries.t b/t/db_dependent/Koha/Libraries.t >index 86c68fd5c7..419dcbf0da 100755 >--- a/t/db_dependent/Koha/Libraries.t >+++ b/t/db_dependent/Koha/Libraries.t >@@ -331,6 +331,38 @@ subtest 'get_hold_libraries and validate_hold_sibling' => sub { > > }; > >+subtest 'get_float_libraries and validate_float_sibling' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $library1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library3 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library4 = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); >+ my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); >+ # Float group 1 >+ $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } ); >+ $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } ); >+ # Float group 2 >+ $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); >+ $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); >+ >+ my @libraries1 = $library1->get_float_libraries(); >+ is(scalar @libraries1, '2', '1st float group contains 2 libraries'); >+ >+ my @libraries2 = $library3->get_float_libraries(); >+ is(scalar @libraries2, '2', '2nd float group also contains 2 libraries'); >+ >+ ok($library1->validate_float_sibling({ branchcode => $library2->branchcode }), "Library1 and library2 belong in to the same float group."); >+ ok($library3->validate_float_sibling({ branchcode => $library4->branchcode }), "Library3 and library5 belong in to the same float group."); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'outgoing_transfers' => sub { > plan tests => 3; > >-- >2.30.2
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 9525
:
40077
|
40102
|
40103
|
44754
|
44756
|
44760
|
48310
|
100420
|
100421
|
100422
|
100741
|
100742
|
100743
|
103828
|
103829
|
103830
|
103831
|
112550
|
112551
|
112552
|
112553
|
124825
|
124826
|
124827
|
133071
|
133072
|
133073
|
139024
|
139025
|
139026
|
143740
|
143741
|
143742
|
143743
|
150241
|
150242
|
150243
|
150244
|
150245
|
150246
|
156330
|
156331
|
156332
|
156333
|
156334
|
156335
|
156336