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

(-)a/C4/Circulation.pm (-1 / +13 lines)
Lines 1937-1942 returnbranch => branch to which to return item. Possible values: Link Here
1937
  noreturn: do not return, let item remain where checked in (floating collections)
1937
  noreturn: do not return, let item remain where checked in (floating collections)
1938
  homebranch: return to item's home branch
1938
  homebranch: return to item's home branch
1939
  holdingbranch: return to issuer branch
1939
  holdingbranch: return to issuer branch
1940
  returnbylibrarygroup: if item is returned to float group library, let it float
1940
1941
1941
This searches branchitemrules in the following order:
1942
This searches branchitemrules in the following order:
1942
1943
Lines 2096-2103 sub AddReturn { Link Here
2096
2097
2097
        # full item data, but no borrowernumber or checkout info (no issue)
2098
        # full item data, but no borrowernumber or checkout info (no issue)
2098
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
2099
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
2100
        # check if returnbranch and homebranch belong to the same float group
2101
    my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch });
2099
        # get the proper branch to which to return the item
2102
        # get the proper branch to which to return the item
2100
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
2103
    my $returnbranch;
2104
    if($hbr eq 'noreturn'){
2105
        $returnbranch = $branch;
2106
    }elsif($hbr eq 'returnbylibrarygroup'){
2107
            # if library isn't in same the float group, transfer item to homebranch
2108
        $hbr = 'homebranch';
2109
        $returnbranch = $validate_float ? $branch : $item->$hbr;
2110
    }else{
2111
        $returnbranch = $item->$hbr;
2112
    }
2101
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2113
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2102
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2114
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2103
2115
(-)a/Koha/Library.pm (+42 lines)
Lines 313-318 sub to_api_mapping { Link Here
313
    };
313
    };
314
}
314
}
315
315
316
=head3 get_float_group_libraries
317
318
Return all libraries belonging to the same float group
319
320
=cut
321
322
sub get_float_libraries {
323
    my ( $self ) = @_;
324
325
    my $library_groups = $self->library_groups;
326
    my @float_libraries;
327
328
    while ( my $library_group = $library_groups->next ) {
329
        my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id});
330
        if($root->ft_local_float_group) {
331
            push @float_libraries, $root->all_libraries;
332
        }
333
    }
334
335
    my %seen;
336
    @float_libraries =
337
      grep { !$seen{ $_->id }++ } @float_libraries;
338
339
    return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } });
340
}
341
342
=head3 validate_float_sibling
343
344
Return if given library is a valid float group member
345
346
=cut
347
348
sub validate_float_sibling {
349
    my ( $self, $params ) = @_;
350
351
    return 1 if $params->{branchcode} eq $self->id;
352
353
    my $branchcode = $params->{branchcode};
354
    return $self->get_float_libraries->search( { branchcode => $branchcode } )
355
      ->count > 0;
356
}
357
316
=head2 Internal methods
358
=head2 Internal methods
317
359
318
=head3 _type
360
=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 301-308 if ($barcode) { Link Here
301
301
302
        # make sure return branch respects home branch circulation rules, default to homebranch
302
        # make sure return branch respects home branch circulation rules, default to homebranch
303
        my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
303
        my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
304
        $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
304
        my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $userenv_branch });
305
305
        # get the proper branch to which to return the item
306
        # if library isn't in same the float group, transfer item to homelibrary
307
        $returnbranch = $hbr eq 'noreturn' ? $userenv_branch : $hbr eq 'returnbylibrarygroup' ? $validate_float ? $userenv_branch : $item->homebranch : $item->$hbr;
306
        my $materials = $item->materials;
308
        my $materials = $item->materials;
307
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
309
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
308
        $materials = $descriptions->{lib} // $materials;
310
        $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 766-771 Link Here
766
                            [% END %]
766
                            [% END %]
767
                                Item floats
767
                                Item floats
768
                            </option>
768
                            </option>
769
                            [% IF returnbranch.rule_value == 'returnbylibrarygroup' %]
770
                            <option value="returnbylibrarygroup" selected="selected">
771
                            [% ELSE %]
772
                            <option value="returnbylibrarygroup">
773
                            [% END %]
774
                                Item floats by library group
775
                            </option>
769
                        </select>
776
                        </select>
770
                    </td>
777
                    </td>
771
                    <td class="actions">
778
                    <td class="actions">
Lines 1233-1238 Link Here
1233
                                    <span>Item returns to issuing branch</span>
1240
                                    <span>Item returns to issuing branch</span>
1234
                                [% ELSIF returnbranch == 'noreturn' %]
1241
                                [% ELSIF returnbranch == 'noreturn' %]
1235
                                    <span>Item floats</span>
1242
                                    <span>Item floats</span>
1243
                                [% ELSIF returnbranch == 'returnbylibrarygroup'%]
1244
                                    <span>Item floats by library group</span>
1236
                                [% END %]
1245
                                [% END %]
1237
                            </td>
1246
                            </td>
1238
                            <td class="actions">
1247
                            <td class="actions">
Lines 1285-1290 Link Here
1285
                            <option value="homebranch">Item returns home</option>
1294
                            <option value="homebranch">Item returns home</option>
1286
                            <option value="holdingbranch">Item returns to issuing library</option>
1295
                            <option value="holdingbranch">Item returns to issuing library</option>
1287
                            <option value="noreturn">Item floats</option>
1296
                            <option value="noreturn">Item floats</option>
1297
                            <option value="returnbylibrarygroup">Item floats by library group</option>
1288
                        </select>
1298
                        </select>
1289
                    </td>
1299
                    </td>
1290
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
1300
                    <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