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

(-)a/C4/Circulation.pm (-1 / +12 lines)
Lines 2128-2135 sub AddReturn { Link Here
2128
2128
2129
        # full item data, but no borrowernumber or checkout info (no issue)
2129
        # full item data, but no borrowernumber or checkout info (no issue)
2130
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
2130
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
2131
        # check if returnbranch and homebranch belong to the same float group
2132
    my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch });
2131
        # get the proper branch to which to return the item
2133
        # get the proper branch to which to return the item
2132
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
2134
    my $returnbranch;
2135
    if($hbr eq 'noreturn'){
2136
        $returnbranch = $branch;
2137
    }elsif($hbr eq 'returnbylibrarygroup'){
2138
            # if library isn't in same the float group, transfer item to homebranch
2139
        $hbr = 'homebranch';
2140
        $returnbranch = $validate_float ? $branch : $item->$hbr;
2141
    }else{
2142
        $returnbranch = $item->$hbr;
2143
    }
2133
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2144
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2134
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2145
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2135
2146
(-)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 158-163 Link Here
158
                                        Is local hold group
158
                                        Is local hold group
159
                                    </label>
159
                                    </label>
160
                                </p>
160
                                </p>
161
                                <p>
162
                                    <label>
163
                                        <input type="checkbox" name="ft_local_float_group" id="add-group-modal-ft_local_float_group" value="1" />
164
                                        Is local float group
165
                                    </label>
166
                                </p>
161
                            </div>
167
                            </div>
162
                        </div>
168
                        </div>
163
                    </div>
169
                    </div>
Lines 228-233 Link Here
228
                                        Is local hold group
234
                                        Is local hold group
229
                                    </label>
235
                                    </label>
230
                                </p>
236
                                </p>
237
                                <p>
238
                                    <label>
239
                                        <input type="checkbox" id="edit-group-modal-ft_local_float_group" name="ft_local_float_group" value="1" />
240
                                        Is local float group
241
                                    </label>
242
                                </p>
231
                            </div>
243
                            </div>
232
                        </div>
244
                        </div>
233
                    </div>
245
                    </div>
Lines 309-315 Link Here
309
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
321
                var ft_search_groups_opac = $(this).data('groupFt_search_groups_opac');
310
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
322
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
311
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
323
                var ft_local_hold_group = $(this).data('groupFt_local_hold_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_limit_item_editing );
324
                var ft_local_float_group = $(this).data('groupFt_local_float_group');
325
                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 );
313
            });
326
            });
314
327
315
            $('.delete-group').on('click', function(e) {
328
            $('.delete-group').on('click', function(e) {
Lines 346-351 Link Here
346
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
359
            $('#add-group-modal-ft_search_groups_opac').prop('checked', false);
347
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
360
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
348
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
361
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
362
            $('#add-group-modal-ft_local_float_group').prop('checked', false);
349
            if ( parent_id ) {
363
            if ( parent_id ) {
350
                $('#root-group-features-add').hide();
364
                $('#root-group-features-add').hide();
351
            } else {
365
            } else {
Lines 355-371 Link Here
355
369
356
        }
370
        }
357
371
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_limit_item_editing ) {
372
        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 ) {
359
            $('#edit-group-modal-id').val( id );
373
            $('#edit-group-modal-id').val( id );
360
            $('#edit-group-modal-title').val( title );
374
            $('#edit-group-modal-title').val( title );
361
            $('#edit-group-modal-description').val( description );
375
            $('#edit-group-modal-description').val( description );
362
376
            console.log(ft_local_float_group);
363
            if ( parent_id ) {
377
            if ( parent_id ) {
364
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
378
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', false);
365
                $('#edit-group-modal-ft_limit_item_editing').prop('checked', false);
379
                $('#edit-group-modal-ft_limit_item_editing').prop('checked', false);
366
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
380
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', false);
367
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
381
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
368
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
382
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
383
                $('#edit-group-modal-ft_local_float_group').prop('checked', false);
369
                $('#root-group-features-edit').hide();
384
                $('#root-group-features-edit').hide();
370
            } else {
385
            } else {
371
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
386
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
Lines 373-378 Link Here
373
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
388
                $('#edit-group-modal-ft_search_groups_opac').prop('checked', ft_search_groups_opac ? true : false );
374
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
389
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
375
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
390
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
391
                $('#edit-group-modal-ft_local_float_group').prop('checked', ft_local_float_group ? true : false );
376
                $('#root-group-features-edit').show();
392
                $('#root-group-features-edit').show();
377
            }
393
            }
378
394
Lines 431-436 Link Here
431
                [% IF group.ft_local_hold_group %]
447
                [% IF group.ft_local_hold_group %]
432
                    <li>Is local hold group</li>
448
                    <li>Is local hold group</li>
433
                [% END %]
449
                [% END %]
450
                [% IF group.ft_local_float_group %]
451
                    <li>Is local float group</li>
452
                [% END %]
434
              </ul>
453
              </ul>
435
            [% END %]
454
            [% END %]
436
        </td>
455
        </td>
Lines 448-454 Link Here
448
                       </li>
467
                       </li>
449
468
450
                        <li>
469
                        <li>
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_limit_item_editing="[% group.ft_limit_item_editing | html %]" >
470
                            <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 %]" >
452
                                <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit
471
                                <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit
453
                            </a>
472
                            </a>
454
                       </li>
473
                       </li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+10 lines)
Lines 771-776 Link Here
771
                                        [% END %]
771
                                        [% END %]
772
                                            Item floats
772
                                            Item floats
773
                                        </option>
773
                                        </option>
774
                                        [% IF returnbranch.rule_value == 'returnbylibrarygroup' %]
775
                                        <option value="returnbylibrarygroup" selected="selected">
776
                                        [% ELSE %]
777
                                        <option value="returnbylibrarygroup">
778
                                        [% END %]
779
                                            Item floats by library group
780
                                        </option>
774
                                    </select>
781
                                    </select>
775
                                </td>
782
                                </td>
776
                                <td class="actions">
783
                                <td class="actions">
Lines 1323-1328 Link Here
1323
                                                <span>Item returns to issuing branch</span>
1330
                                                <span>Item returns to issuing branch</span>
1324
                                            [% ELSIF returnbranch == 'noreturn' %]
1331
                                            [% ELSIF returnbranch == 'noreturn' %]
1325
                                                <span>Item floats</span>
1332
                                                <span>Item floats</span>
1333
                                            [% ELSIF returnbranch == 'returnbylibrarygroup'%]
1334
                                                <span>Item floats by library group</span>
1326
                                            [% END %]
1335
                                            [% END %]
1327
                                        </td>
1336
                                        </td>
1328
                                        <td class="actions">
1337
                                        <td class="actions">
Lines 1375-1380 Link Here
1375
                                        <option value="homebranch">Item returns home</option>
1384
                                        <option value="homebranch">Item returns home</option>
1376
                                        <option value="holdingbranch">Item returns to issuing library</option>
1385
                                        <option value="holdingbranch">Item returns to issuing library</option>
1377
                                        <option value="noreturn">Item floats</option>
1386
                                        <option value="noreturn">Item floats</option>
1387
                                        <option value="returnbylibrarygroup">Item floats by library group</option>
1378
                                    </select>
1388
                                    </select>
1379
                                </td>
1389
                                </td>
1380
                                <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
1390
                                <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