View | Details | Raw Unified | Return to bug 9525
Collapse All | Expand All

(-)a/C4/Circulation.pm (-1 / +13 lines)
Lines 1828-1833 returnbranch => branch to which to return item. Possible values: Link Here
1828
  noreturn: do not return, let item remain where checked in (floating collections)
1828
  noreturn: do not return, let item remain where checked in (floating collections)
1829
  homebranch: return to item's home branch
1829
  homebranch: return to item's home branch
1830
  holdingbranch: return to issuer branch
1830
  holdingbranch: return to issuer branch
1831
  returnbylibrarygroup: if item is returned to float group library, let it float
1831
1832
1832
This searches branchitemrules in the following order:
1833
This searches branchitemrules in the following order:
1833
1834
Lines 2000-2007 sub AddReturn { Link Here
2000
2001
2001
        # full item data, but no borrowernumber or checkout info (no issue)
2002
        # full item data, but no borrowernumber or checkout info (no issue)
2002
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
2003
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
2004
        # check if returnbranch and homebranch belong to the same float group
2005
    my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch });
2003
        # get the proper branch to which to return the item
2006
        # get the proper branch to which to return the item
2004
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
2007
    my $returnbranch;
2008
    if($hbr eq 'noreturn'){
2009
        $returnbranch = $branch;
2010
    }elsif($hbr eq 'returnbylibrarygroup'){
2011
            # if library isn't in same the float group, transfer item to homebranch
2012
        $hbr = 'homebranch';
2013
        $returnbranch = $validate_float ? $branch : $item->$hbr;
2014
    }else{
2015
        $returnbranch = $item->$hbr;
2016
    }
2005
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2017
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2006
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2018
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2007
2019
(-)a/Koha/Library.pm (+42 lines)
Lines 298-303 sub validate_hold_sibling { Link Here
298
      ->count > 0;
298
      ->count > 0;
299
}
299
}
300
300
301
=head3 get_float_group_libraries
302
303
Return all libraries belonging to the same float group
304
305
=cut
306
307
sub get_float_libraries {
308
    my ( $self ) = @_;
309
310
    my $library_groups = $self->library_groups;
311
    my @float_libraries;
312
313
    while ( my $library_group = $library_groups->next ) {
314
        my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id});
315
        if($root->ft_local_float_group) {
316
            push @float_libraries, $root->all_libraries;
317
        }
318
    }
319
320
    my %seen;
321
    @float_libraries =
322
      grep { !$seen{ $_->id }++ } @float_libraries;
323
324
    return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } });
325
}
326
327
=head3 validate_float_sibling
328
329
Return if given library is a valid float group member
330
331
=cut
332
333
sub validate_float_sibling {
334
    my ( $self, $params ) = @_;
335
336
    return 1 if $params->{branchcode} eq $self->id;
337
338
    my $branchcode = $params->{branchcode};
339
    return $self->get_float_libraries->search( { branchcode => $branchcode } )
340
      ->count > 0;
341
}
342
301
=head2 Internal methods
343
=head2 Internal methods
302
344
303
=head3 _type
345
=head3 _type
(-)a/admin/library_groups.pl (+4 lines)
Lines 50-55 if ( $action eq 'add' ) { Link Here
50
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
50
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
51
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
51
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
52
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
52
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
53
    my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0;
53
54
54
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
55
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
55
        $template->param( error_duplicate_title => $title );
56
        $template->param( error_duplicate_title => $title );
Lines 65-70 if ( $action eq 'add' ) { Link Here
65
                    ft_search_groups_opac  => $ft_search_groups_opac,
66
                    ft_search_groups_opac  => $ft_search_groups_opac,
66
                    ft_search_groups_staff => $ft_search_groups_staff,
67
                    ft_search_groups_staff => $ft_search_groups_staff,
67
                    ft_local_hold_group    => $ft_local_hold_group,
68
                    ft_local_hold_group    => $ft_local_hold_group,
69
                    ft_local_float_group   => $ft_local_float_group,
68
                    branchcode             => $branchcode,
70
                    branchcode             => $branchcode,
69
                }
71
                }
70
            )->store();
72
            )->store();
Lines 85-90 elsif ( $action eq 'edit' ) { Link Here
85
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
87
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
86
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
88
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
87
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
89
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
90
    my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0;
88
91
89
    if ($id) {
92
    if ($id) {
90
        my $group = Koha::Library::Groups->find($id);
93
        my $group = Koha::Library::Groups->find($id);
Lines 97-102 elsif ( $action eq 'edit' ) { Link Here
97
                ft_search_groups_opac    => $ft_search_groups_opac,
100
                ft_search_groups_opac    => $ft_search_groups_opac,
98
                ft_search_groups_staff   => $ft_search_groups_staff,
101
                ft_search_groups_staff   => $ft_search_groups_staff,
99
                ft_local_hold_group   => $ft_local_hold_group,
102
                ft_local_hold_group   => $ft_local_hold_group,
103
                ft_local_float_group     => $ft_local_float_group,
100
            }
104
            }
101
        )->store();
105
        )->store();
102
106
(-)a/circ/returns.pl (-2 / +4 lines)
Lines 264-271 if ($barcode) { Link Here
264
264
265
        # make sure return branch respects home branch circulation rules, default to homebranch
265
        # make sure return branch respects home branch circulation rules, default to homebranch
266
        my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
266
        my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
267
        $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
267
        my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $userenv_branch });
268
268
        # get the proper branch to which to return the item
269
        # if library isn't in same the float group, transfer item to homelibrary
270
        $returnbranch = $hbr eq 'noreturn' ? $userenv_branch : $hbr eq 'returnbylibrarygroup' ? $validate_float ? $userenv_branch : $item->homebranch : $item->$hbr;
269
        my $materials = $item->materials;
271
        my $materials = $item->materials;
270
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
272
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
271
        $materials = $descriptions->{lib} // $materials;
273
        $materials = $descriptions->{lib} // $materials;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt (-4 / +23 lines)
Lines 147-152 Link Here
147
                                        Is local hold group
147
                                        Is local hold group
148
                                    </label>
148
                                    </label>
149
                                </p>
149
                                </p>
150
                                <p>
151
                                    <label>
152
                                        <input type="checkbox" name="ft_local_float_group" id="add-group-modal-ft_local_float_group" value="1" />
153
                                        Is local float group
154
                                    </label>
155
                                </p>
150
                            </div>
156
                            </div>
151
                        </div>
157
                        </div>
152
                    </div>
158
                    </div>
Lines 211-216 Link Here
211
                                        Is local hold group
217
                                        Is local hold group
212
                                    </label>
218
                                    </label>
213
                                </p>
219
                                </p>
220
                                <p>
221
                                    <label>
222
                                        <input type="checkbox" id="edit-group-modal-ft_local_float_group" name="ft_local_float_group" value="1" />
223
                                        Is local float group
224
                                    </label>
225
                                </p>
214
                            </div>
226
                            </div>
215
                        </div>
227
                        </div>
216
                    </div>
228
                    </div>
Lines 291-297 Link Here
291
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
303
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
292
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
304
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
293
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
305
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
294
                edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group );
306
                var ft_local_float_group = $(this).data('groupFt_local_float_group');
307
                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 );
295
            });
308
            });
296
309
297
            $('.delete-group').on('click', function(e) {
310
            $('.delete-group').on('click', function(e) {
Lines 327-332 Link Here
327
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
340
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
328
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
341
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
329
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
342
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
343
            $('#add-group-modal-ft_local_float_group').prop('checked', false);
330
            if ( parent_id ) {
344
            if ( parent_id ) {
331
                $('#root-group-features-add').hide();
345
                $('#root-group-features-add').hide();
332
            } else {
346
            } else {
Lines 336-357 Link Here
336
350
337
        }
351
        }
338
352
339
        function edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group ) {
353
        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 ) {
340
            $('#edit-group-modal-id').val( id );
354
            $('#edit-group-modal-id').val( id );
341
            $('#edit-group-modal-title').val( title );
355
            $('#edit-group-modal-title').val( title );
342
            $('#edit-group-modal-description').val( description );
356
            $('#edit-group-modal-description').val( description );
343
357
            console.log(ft_local_float_group);
344
            if ( parent_id ) {
358
            if ( parent_id ) {
345
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
359
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
346
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
360
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
347
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
361
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
348
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
362
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
363
                $('#edit-group-modal-ft_local_float_group').prop('checked', false);
349
                $('#root-group-features-edit').hide();
364
                $('#root-group-features-edit').hide();
350
            } else {
365
            } else {
351
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
366
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
352
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
367
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
353
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
368
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
354
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
369
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
370
                $('#edit-group-modal-ft_local_float_group').prop('checked', ft_local_float_group ? true : false );
355
                $('#root-group-features-edit').show();
371
                $('#root-group-features-edit').show();
356
            }
372
            }
357
373
Lines 407-412 Link Here
407
                [% IF group.ft_local_hold_group %]
423
                [% IF group.ft_local_hold_group %]
408
                    <li>Is local hold group</li>
424
                    <li>Is local hold group</li>
409
                [% END %]
425
                [% END %]
426
                [% IF group.ft_local_float_group %]
427
                    <li>Is local float group</li>
428
                [% END %]
410
              </ul>
429
              </ul>
411
            [% END %]
430
            [% END %]
412
        </td>
431
        </td>
Lines 424-430 Link Here
424
                       </li>
443
                       </li>
425
444
426
                        <li>
445
                        <li>
427
                            <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 %]" >
446
                            <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 %]" >
428
                                <i class="fa fa-pencil"></i> Edit
447
                                <i class="fa fa-pencil"></i> Edit
429
                            </a>
448
                            </a>
430
                       </li>
449
                       </li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+10 lines)
Lines 694-699 Link Here
694
                            [% END %]
694
                            [% END %]
695
                                Item floats
695
                                Item floats
696
                            </option>
696
                            </option>
697
                            [% IF returnbranch.rule_value == 'returnbylibrarygroup' %]
698
                            <option value="returnbylibrarygroup" selected="selected">
699
                            [% ELSE %]
700
                            <option value="returnbylibrarygroup">
701
                            [% END %]
702
                                Item floats by library group
703
                            </option>
697
                        </select>
704
                        </select>
698
                    </td>
705
                    </td>
699
                    <td class="actions">
706
                    <td class="actions">
Lines 963-968 Link Here
963
                                    <span>Item returns to issuing branch</span>
970
                                    <span>Item returns to issuing branch</span>
964
                                [% ELSIF returnbranch == 'noreturn' %]
971
                                [% ELSIF returnbranch == 'noreturn' %]
965
                                    <span>Item floats</span>
972
                                    <span>Item floats</span>
973
                                [% ELSIF returnbranch == 'returnbylibrarygroup'%]
974
                                    <span>Item floats by library group</span>
966
                                [% END %]
975
                                [% END %]
967
                            </td>
976
                            </td>
968
                            <td class="actions">
977
                            <td class="actions">
Lines 1015-1020 Link Here
1015
                            <option value="homebranch">Item returns home</option>
1024
                            <option value="homebranch">Item returns home</option>
1016
                            <option value="holdingbranch">Item returns to issuing library</option>
1025
                            <option value="holdingbranch">Item returns to issuing library</option>
1017
                            <option value="noreturn">Item floats</option>
1026
                            <option value="noreturn">Item floats</option>
1027
                            <option value="returnbylibrarygroup">Item floats by library group</option>
1018
                        </select>
1028
                        </select>
1019
                    </td>
1029
                    </td>
1020
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
1030
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
(-)a/t/db_dependent/Koha/Libraries.t (-1 / +32 lines)
Lines 331-336 subtest 'get_hold_libraries and validate_hold_sibling' => sub { Link Here
331
331
332
};
332
};
333
333
334
subtest 'get_float_libraries and validate_float_sibling' => sub {
335
336
    plan tests => 4;
337
338
    $schema->storage->txn_begin;
339
340
    my $library1 = $builder->build_object({ class => 'Koha::Libraries' });
341
    my $library2 = $builder->build_object({ class => 'Koha::Libraries' });
342
    my $library3 = $builder->build_object({ class => 'Koha::Libraries' });
343
    my $library4 = $builder->build_object({ class => 'Koha::Libraries' });
344
345
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
346
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
347
    # Float group 1
348
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
349
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
350
    # Float group 2
351
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
352
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
353
354
    my @libraries1 = $library1->get_float_libraries();
355
    is(scalar @libraries1, '2', '1st float group contains 2 libraries');
356
357
    my @libraries2 = $library3->get_float_libraries();
358
    is(scalar @libraries2, '2', '2nd float group also contains 2 libraries');
359
360
    ok($library1->validate_float_sibling({ branchcode => $library2->branchcode }), "Library1 and library2 belong in to the same float group.");
361
    ok($library3->validate_float_sibling({ branchcode => $library4->branchcode }), "Library3 and library5 belong in to the same float group.");
362
363
    $schema->storage->txn_rollback;
364
};
365
334
subtest 'outgoing_transfers' => sub {
366
subtest 'outgoing_transfers' => sub {
335
    plan tests => 3;
367
    plan tests => 3;
336
368
337
- 

Return to bug 9525