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

(-)a/C4/Circulation.pm (-1 / +12 lines)
Lines 2129-2136 sub AddReturn { Link Here
2129
2129
2130
        # full item data, but no borrowernumber or checkout info (no issue)
2130
        # full item data, but no borrowernumber or checkout info (no issue)
2131
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
2131
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
2132
        # check if returnbranch and homebranch belong to the same float group
2133
    my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch });
2132
        # get the proper branch to which to return the item
2134
        # get the proper branch to which to return the item
2133
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
2135
    my $returnbranch;
2136
    if($hbr eq 'noreturn'){
2137
        $returnbranch = $branch;
2138
    }elsif($hbr eq 'returnbylibrarygroup'){
2139
            # if library isn't in same the float group, transfer item to homebranch
2140
        $hbr = 'homebranch';
2141
        $returnbranch = $validate_float ? $branch : $item->$hbr;
2142
    }else{
2143
        $returnbranch = $item->$hbr;
2144
    }
2134
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2145
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2135
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2146
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2136
2147
(-)a/Koha/Library.pm (+42 lines)
Lines 376-381 sub opac_info { Link Here
376
    });
376
    });
377
}
377
}
378
378
379
=head3 get_float_group_libraries
380
381
Return all libraries belonging to the same float group
382
383
=cut
384
385
sub get_float_libraries {
386
    my ( $self ) = @_;
387
388
    my $library_groups = $self->library_groups;
389
    my @float_libraries;
390
391
    while ( my $library_group = $library_groups->next ) {
392
        my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id});
393
        if($root->ft_local_float_group) {
394
            push @float_libraries, $root->all_libraries;
395
        }
396
    }
397
398
    my %seen;
399
    @float_libraries =
400
      grep { !$seen{ $_->id }++ } @float_libraries;
401
402
    return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } });
403
}
404
405
=head3 validate_float_sibling
406
407
Return if given library is a valid float group member
408
409
=cut
410
411
sub validate_float_sibling {
412
    my ( $self, $params ) = @_;
413
414
    return 1 if $params->{branchcode} eq $self->id;
415
416
    my $branchcode = $params->{branchcode};
417
    return $self->get_float_libraries->search( { branchcode => $branchcode } )
418
      ->count > 0;
419
}
420
379
=head2 Internal methods
421
=head2 Internal methods
380
422
381
=head3 _type
423
=head3 _type
(-)a/admin/library_groups.pl (+4 lines)
Lines 51-56 if ( $action eq 'add' ) { Link Here
51
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
51
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
52
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
52
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
53
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
53
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
54
    my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0;
54
55
55
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
56
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
56
        $template->param( error_duplicate_title => $title );
57
        $template->param( error_duplicate_title => $title );
Lines 67-72 if ( $action eq 'add' ) { Link Here
67
                    ft_search_groups_staff => $ft_search_groups_staff,
68
                    ft_search_groups_staff => $ft_search_groups_staff,
68
                    ft_local_hold_group    => $ft_local_hold_group,
69
                    ft_local_hold_group    => $ft_local_hold_group,
69
                    ft_limit_item_editing  => $ft_limit_item_editing,
70
                    ft_limit_item_editing  => $ft_limit_item_editing,
71
                    ft_local_float_group   => $ft_local_float_group,
70
                    branchcode             => $branchcode,
72
                    branchcode             => $branchcode,
71
                }
73
                }
72
            )->store();
74
            )->store();
Lines 88-93 elsif ( $action eq 'edit' ) { Link Here
88
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
90
    my $ft_search_groups_opac  = $cgi->param('ft_search_groups_opac')  || 0;
89
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
91
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
90
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
92
    my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
93
    my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0;
91
94
92
    if ($id) {
95
    if ($id) {
93
        my $group = Koha::Library::Groups->find($id);
96
        my $group = Koha::Library::Groups->find($id);
Lines 101-106 elsif ( $action eq 'edit' ) { Link Here
101
                ft_search_groups_opac    => $ft_search_groups_opac,
104
                ft_search_groups_opac    => $ft_search_groups_opac,
102
                ft_search_groups_staff   => $ft_search_groups_staff,
105
                ft_search_groups_staff   => $ft_search_groups_staff,
103
                ft_local_hold_group   => $ft_local_hold_group,
106
                ft_local_hold_group   => $ft_local_hold_group,
107
                ft_local_float_group     => $ft_local_float_group,
104
            }
108
            }
105
        )->store();
109
        )->store();
106
110
(-)a/circ/returns.pl (-2 / +4 lines)
Lines 298-305 if ($barcode) { Link Here
298
298
299
        # make sure return branch respects home branch circulation rules, default to homebranch
299
        # make sure return branch respects home branch circulation rules, default to homebranch
300
        my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
300
        my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
301
        $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
301
        my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $userenv_branch });
302
302
        # get the proper branch to which to return the item
303
        # if library isn't in same the float group, transfer item to homelibrary
304
        $returnbranch = $hbr eq 'noreturn' ? $userenv_branch : $hbr eq 'returnbylibrarygroup' ? $validate_float ? $userenv_branch : $item->homebranch : $item->$hbr;
303
        my $materials = $item->materials;
305
        my $materials = $item->materials;
304
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
306
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
305
        $materials = $descriptions->{lib} // $materials;
307
        $materials = $descriptions->{lib} // $materials;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt (-4 / +23 lines)
Lines 153-158 Link Here
153
                                        Is local hold group
153
                                        Is local hold group
154
                                    </label>
154
                                    </label>
155
                                </p>
155
                                </p>
156
                                <p>
157
                                    <label>
158
                                        <input type="checkbox" name="ft_local_float_group" id="add-group-modal-ft_local_float_group" value="1" />
159
                                        Is local float group
160
                                    </label>
161
                                </p>
156
                            </div>
162
                            </div>
157
                        </div>
163
                        </div>
158
                    </div>
164
                    </div>
Lines 223-228 Link Here
223
                                        Is local hold group
229
                                        Is local hold group
224
                                    </label>
230
                                    </label>
225
                                </p>
231
                                </p>
232
                                <p>
233
                                    <label>
234
                                        <input type="checkbox" id="edit-group-modal-ft_local_float_group" name="ft_local_float_group" value="1" />
235
                                        Is local float group
236
                                    </label>
237
                                </p>
226
                            </div>
238
                            </div>
227
                        </div>
239
                        </div>
228
                    </div>
240
                    </div>
Lines 304-310 Link Here
304
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
316
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
305
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
317
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
306
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
318
                var ft_local_hold_group = $(this).data('groupFt_local_hold_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_limit_item_editing );
319
                var ft_local_float_group = $(this).data('groupFt_local_float_group');
320
                edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group );
308
            });
321
            });
309
322
310
            $('.delete-group').on('click', function(e) {
323
            $('.delete-group').on('click', function(e) {
Lines 341-346 Link Here
341
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
354
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
342
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
355
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
343
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
356
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
357
            $('#add-group-modal-ft_local_float_group').prop('checked', false);
344
            if ( parent_id ) {
358
            if ( parent_id ) {
345
                $('#root-group-features-add').hide();
359
                $('#root-group-features-add').hide();
346
            } else {
360
            } else {
Lines 350-366 Link Here
350
364
351
        }
365
        }
352
366
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_limit_item_editing ) {
367
        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_limit_item_editing, ft_local_float_group ) {
354
            $('#edit-group-modal-id').val( id );
368
            $('#edit-group-modal-id').val( id );
355
            $('#edit-group-modal-title').val( title );
369
            $('#edit-group-modal-title').val( title );
356
            $('#edit-group-modal-description').val( description );
370
            $('#edit-group-modal-description').val( description );
357
371
            console.log(ft_local_float_group);
358
            if ( parent_id ) {
372
            if ( parent_id ) {
359
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
373
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
360
                $('#edit-group-modal-ft_limit_item_editing').prop('checked', false);
374
                $('#edit-group-modal-ft_limit_item_editing').prop('checked', false);
361
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
375
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
362
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
376
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
363
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
377
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
378
                $('#edit-group-modal-ft_local_float_group').prop('checked', false);
364
                $('#root-group-features-edit').hide();
379
                $('#root-group-features-edit').hide();
365
            } else {
380
            } else {
366
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
381
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
Lines 368-373 Link Here
368
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
383
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
369
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
384
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
370
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
385
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
386
                $('#edit-group-modal-ft_local_float_group').prop('checked', ft_local_float_group ? true : false );
371
                $('#root-group-features-edit').show();
387
                $('#root-group-features-edit').show();
372
            }
388
            }
373
389
Lines 426-431 Link Here
426
                [% IF group.ft_local_hold_group %]
442
                [% IF group.ft_local_hold_group %]
427
                    <li>Is local hold group</li>
443
                    <li>Is local hold group</li>
428
                [% END %]
444
                [% END %]
445
                [% IF group.ft_local_float_group %]
446
                    <li>Is local float group</li>
447
                [% END %]
429
              </ul>
448
              </ul>
430
            [% END %]
449
            [% END %]
431
        </td>
450
        </td>
Lines 443-449 Link Here
443
                       </li>
462
                       </li>
444
463
445
                        <li>
464
                        <li>
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_limit_item_editing="[% group.ft_limit_item_editing | html %]" >
465
                            <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_limit_item_editing="[% group.ft_limit_item_editing | html %]" data-group-ft_local_float_group="[% group.ft_local_float_group | html %]" >
447
                                <i class="fa fa-pencil"></i> Edit
466
                                <i class="fa fa-pencil"></i> Edit
448
                            </a>
467
                            </a>
449
                       </li>
468
                       </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 1318-1323 Link Here
1318
                                                <span>Item returns to issuing branch</span>
1325
                                                <span>Item returns to issuing branch</span>
1319
                                            [% ELSIF returnbranch == 'noreturn' %]
1326
                                            [% ELSIF returnbranch == 'noreturn' %]
1320
                                                <span>Item floats</span>
1327
                                                <span>Item floats</span>
1328
                                            [% ELSIF returnbranch == 'returnbylibrarygroup'%]
1329
                                                <span>Item floats by library group</span>
1321
                                            [% END %]
1330
                                            [% END %]
1322
                                        </td>
1331
                                        </td>
1323
                                        <td class="actions">
1332
                                        <td class="actions">
Lines 1370-1375 Link Here
1370
                                        <option value="homebranch">Item returns home</option>
1379
                                        <option value="homebranch">Item returns home</option>
1371
                                        <option value="holdingbranch">Item returns to issuing library</option>
1380
                                        <option value="holdingbranch">Item returns to issuing library</option>
1372
                                        <option value="noreturn">Item floats</option>
1381
                                        <option value="noreturn">Item floats</option>
1382
                                        <option value="returnbylibrarygroup">Item floats by library group</option>
1373
                                    </select>
1383
                                    </select>
1374
                                </td>
1384
                                </td>
1375
                                <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
1385
                                <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