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

(-)a/C4/Circulation.pm (-1 / +12 lines)
Lines 2099-2106 sub AddReturn { Link Here
2099
2099
2100
        # full item data, but no borrowernumber or checkout info (no issue)
2100
        # full item data, but no borrowernumber or checkout info (no issue)
2101
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
2101
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
2102
        # check if returnbranch and homebranch belong to the same float group
2103
    my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch });
2102
        # get the proper branch to which to return the item
2104
        # get the proper branch to which to return the item
2103
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
2105
    my $returnbranch;
2106
    if($hbr eq 'noreturn'){
2107
        $returnbranch = $branch;
2108
    }elsif($hbr eq 'returnbylibrarygroup'){
2109
            # if library isn't in same the float group, transfer item to homebranch
2110
        $hbr = 'homebranch';
2111
        $returnbranch = $validate_float ? $branch : $item->$hbr;
2112
    }else{
2113
        $returnbranch = $item->$hbr;
2114
    }
2104
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2115
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2105
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2116
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2106
2117
(-)a/Koha/Library.pm (+42 lines)
Lines 333-338 sub opac_info { Link Here
333
    });
333
    });
334
}
334
}
335
335
336
=head3 get_float_group_libraries
337
338
Return all libraries belonging to the same float group
339
340
=cut
341
342
sub get_float_libraries {
343
    my ( $self ) = @_;
344
345
    my $library_groups = $self->library_groups;
346
    my @float_libraries;
347
348
    while ( my $library_group = $library_groups->next ) {
349
        my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id});
350
        if($root->ft_local_float_group) {
351
            push @float_libraries, $root->all_libraries;
352
        }
353
    }
354
355
    my %seen;
356
    @float_libraries =
357
      grep { !$seen{ $_->id }++ } @float_libraries;
358
359
    return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } });
360
}
361
362
=head3 validate_float_sibling
363
364
Return if given library is a valid float group member
365
366
=cut
367
368
sub validate_float_sibling {
369
    my ( $self, $params ) = @_;
370
371
    return 1 if $params->{branchcode} eq $self->id;
372
373
    my $branchcode = $params->{branchcode};
374
    return $self->get_float_libraries->search( { branchcode => $branchcode } )
375
      ->count > 0;
376
}
377
336
=head2 Internal methods
378
=head2 Internal methods
337
379
338
=head3 _type
380
=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 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 152-157 Link Here
152
                                        Is local hold group
152
                                        Is local hold group
153
                                    </label>
153
                                    </label>
154
                                </p>
154
                                </p>
155
                                <p>
156
                                    <label>
157
                                        <input type="checkbox" name="ft_local_float_group" id="add-group-modal-ft_local_float_group" value="1" />
158
                                        Is local float group
159
                                    </label>
160
                                </p>
155
                            </div>
161
                            </div>
156
                        </div>
162
                        </div>
157
                    </div>
163
                    </div>
Lines 216-221 Link Here
216
                                        Is local hold group
222
                                        Is local hold group
217
                                    </label>
223
                                    </label>
218
                                </p>
224
                                </p>
225
                                <p>
226
                                    <label>
227
                                        <input type="checkbox" id="edit-group-modal-ft_local_float_group" name="ft_local_float_group" value="1" />
228
                                        Is local float group
229
                                    </label>
230
                                </p>
219
                            </div>
231
                            </div>
220
                        </div>
232
                        </div>
221
                    </div>
233
                    </div>
Lines 296-302 Link Here
296
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
308
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
297
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
309
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
298
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
310
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
299
                edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group );
311
                var ft_local_float_group = $(this).data('groupFt_local_float_group');
312
                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 );
300
            });
313
            });
301
314
302
            $('.delete-group').on('click', function(e) {
315
            $('.delete-group').on('click', function(e) {
Lines 332-337 Link Here
332
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
345
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
333
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
346
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
334
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
347
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
348
            $('#add-group-modal-ft_local_float_group').prop('checked', false);
335
            if ( parent_id ) {
349
            if ( parent_id ) {
336
                $('#root-group-features-add').hide();
350
                $('#root-group-features-add').hide();
337
            } else {
351
            } else {
Lines 341-362 Link Here
341
355
342
        }
356
        }
343
357
344
        function edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group ) {
358
        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 ) {
345
            $('#edit-group-modal-id').val( id );
359
            $('#edit-group-modal-id').val( id );
346
            $('#edit-group-modal-title').val( title );
360
            $('#edit-group-modal-title').val( title );
347
            $('#edit-group-modal-description').val( description );
361
            $('#edit-group-modal-description').val( description );
348
362
            console.log(ft_local_float_group);
349
            if ( parent_id ) {
363
            if ( parent_id ) {
350
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
364
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
351
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
365
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
352
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
366
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
353
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
367
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
368
                $('#edit-group-modal-ft_local_float_group').prop('checked', false);
354
                $('#root-group-features-edit').hide();
369
                $('#root-group-features-edit').hide();
355
            } else {
370
            } else {
356
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
371
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
357
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
372
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
358
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
373
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
359
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
374
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
375
                $('#edit-group-modal-ft_local_float_group').prop('checked', ft_local_float_group ? true : false );
360
                $('#root-group-features-edit').show();
376
                $('#root-group-features-edit').show();
361
            }
377
            }
362
378
Lines 412-417 Link Here
412
                [% IF group.ft_local_hold_group %]
428
                [% IF group.ft_local_hold_group %]
413
                    <li>Is local hold group</li>
429
                    <li>Is local hold group</li>
414
                [% END %]
430
                [% END %]
431
                [% IF group.ft_local_float_group %]
432
                    <li>Is local float group</li>
433
                [% END %]
415
              </ul>
434
              </ul>
416
            [% END %]
435
            [% END %]
417
        </td>
436
        </td>
Lines 429-435 Link Here
429
                       </li>
448
                       </li>
430
449
431
                        <li>
450
                        <li>
432
                            <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 %]" >
451
                            <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 %]" >
433
                                <i class="fa fa-pencil"></i> Edit
452
                                <i class="fa fa-pencil"></i> Edit
434
                            </a>
453
                            </a>
435
                       </li>
454
                       </li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+10 lines)
Lines 773-778 Link Here
773
                                        [% END %]
773
                                        [% END %]
774
                                            Item floats
774
                                            Item floats
775
                                        </option>
775
                                        </option>
776
                                        [% IF returnbranch.rule_value == 'returnbylibrarygroup' %]
777
                                        <option value="returnbylibrarygroup" selected="selected">
778
                                        [% ELSE %]
779
                                        <option value="returnbylibrarygroup">
780
                                        [% END %]
781
                                            Item floats by library group
782
                                        </option>
776
                                    </select>
783
                                    </select>
777
                                </td>
784
                                </td>
778
                                <td class="actions">
785
                                <td class="actions">
Lines 1325-1330 Link Here
1325
                                                <span>Item returns to issuing branch</span>
1332
                                                <span>Item returns to issuing branch</span>
1326
                                            [% ELSIF returnbranch == 'noreturn' %]
1333
                                            [% ELSIF returnbranch == 'noreturn' %]
1327
                                                <span>Item floats</span>
1334
                                                <span>Item floats</span>
1335
                                            [% ELSIF returnbranch == 'returnbylibrarygroup'%]
1336
                                                <span>Item floats by library group</span>
1328
                                            [% END %]
1337
                                            [% END %]
1329
                                        </td>
1338
                                        </td>
1330
                                        <td class="actions">
1339
                                        <td class="actions">
Lines 1377-1382 Link Here
1377
                                        <option value="homebranch">Item returns home</option>
1386
                                        <option value="homebranch">Item returns home</option>
1378
                                        <option value="holdingbranch">Item returns to issuing library</option>
1387
                                        <option value="holdingbranch">Item returns to issuing library</option>
1379
                                        <option value="noreturn">Item floats</option>
1388
                                        <option value="noreturn">Item floats</option>
1389
                                        <option value="returnbylibrarygroup">Item floats by library group</option>
1380
                                    </select>
1390
                                    </select>
1381
                                </td>
1391
                                </td>
1382
                                <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
1392
                                <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