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

(-)a/C4/Circulation.pm (-10 / +15 lines)
Lines 2126-2147 sub AddReturn { Link Here
2126
    }
2126
    }
2127
2127
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
2131
2132
    my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch });
2132
    # check if returnbranch and homebranch belong to the same float group
2133
        # get the proper branch to which to return the item
2133
    my $validate_float =
2134
        Koha::Libraries->find( $item->homebranch )->validate_float_sibling( { branchcode => $branch } );
2135
2136
    # get the proper branch to which to return the item
2134
    my $returnbranch;
2137
    my $returnbranch;
2135
    if($hbr eq 'noreturn'){
2138
    if ( $hbr eq 'noreturn' ) {
2136
        $returnbranch = $branch;
2139
        $returnbranch = $branch;
2137
    }elsif($hbr eq 'returnbylibrarygroup'){
2140
    } elsif ( $hbr eq 'returnbylibrarygroup' ) {
2138
            # if library isn't in same the float group, transfer item to homebranch
2141
2139
        $hbr = 'homebranch';
2142
        # if library isn't in same the float group, transfer item to homebranch
2143
        $hbr          = 'homebranch';
2140
        $returnbranch = $validate_float ? $branch : $item->$hbr;
2144
        $returnbranch = $validate_float ? $branch : $item->$hbr;
2141
    }else{
2145
    } else {
2142
        $returnbranch = $item->$hbr;
2146
        $returnbranch = $item->$hbr;
2143
    }
2147
    }
2144
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2148
2149
    # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
2145
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2150
    my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
2146
2151
2147
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2152
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
(-)a/Koha/Library.pm (-7 / +7 lines)
Lines 376-381 sub opac_info { Link Here
376
    });
376
    });
377
}
377
}
378
378
379
379
=head3 get_float_libraries
380
=head3 get_float_libraries
380
381
381
Return all libraries belonging to the same float group
382
Return all libraries belonging to the same float group
Lines 383-405 Return all libraries belonging to the same float group Link Here
383
=cut
384
=cut
384
385
385
sub get_float_libraries {
386
sub get_float_libraries {
386
    my ( $self ) = @_;
387
    my ($self) = @_;
387
388
388
    my $library_groups = $self->library_groups;
389
    my $library_groups = $self->library_groups;
389
    my @float_libraries;
390
    my @float_libraries;
390
391
391
    while ( my $library_group = $library_groups->next ) {
392
    while ( my $library_group = $library_groups->next ) {
392
        my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id});
393
        my $root = Koha::Library::Groups->get_root_ancestor( { id => $library_group->id } );
393
        if($root->ft_local_float_group) {
394
        if ( $root->ft_local_float_group ) {
394
            push @float_libraries, $root->all_libraries;
395
            push @float_libraries, $root->all_libraries;
395
        }
396
        }
396
    }
397
    }
397
398
398
    my %seen;
399
    my %seen;
399
    @float_libraries =
400
    @float_libraries =
400
      grep { !$seen{ $_->id }++ } @float_libraries;
401
        grep { !$seen{ $_->id }++ } @float_libraries;
401
402
402
    return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } });
403
    return Koha::Libraries->search( { branchcode => { '-in' => [ keys %seen ] } } );
403
}
404
}
404
405
405
=head3 validate_float_sibling
406
=head3 validate_float_sibling
Lines 414-421 sub validate_float_sibling { Link Here
414
    return 1 if $params->{branchcode} eq $self->id;
415
    return 1 if $params->{branchcode} eq $self->id;
415
416
416
    my $branchcode = $params->{branchcode};
417
    my $branchcode = $params->{branchcode};
417
    return $self->get_float_libraries->search( { branchcode => $branchcode } )
418
    return $self->get_float_libraries->search( { branchcode => $branchcode } )->count > 0;
418
      ->count > 0;
419
}
419
}
420
420
421
=head2 Internal methods
421
=head2 Internal methods
(-)a/admin/library_groups.pl (-12 / +12 lines)
Lines 50-57 if ( $action eq 'add' ) { Link Here
50
    my $ft_limit_item_editing  = $cgi->param('ft_limit_item_editing')  || 0;
50
    my $ft_limit_item_editing  = $cgi->param('ft_limit_item_editing')  || 0;
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
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
55
55
56
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
56
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
57
        $template->param( error_duplicate_title => $title );
57
        $template->param( error_duplicate_title => $title );
Lines 89-110 elsif ( $action eq 'edit' ) { Link Here
89
    my $ft_limit_item_editing  = $cgi->param('ft_limit_item_editing')  || 0;
89
    my $ft_limit_item_editing  = $cgi->param('ft_limit_item_editing')  || 0;
90
    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;
91
    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;
92
    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;
93
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
94
94
95
    if ($id) {
95
    if ($id) {
96
        my $group = Koha::Library::Groups->find($id);
96
        my $group = Koha::Library::Groups->find($id);
97
97
98
        $group->set(
98
        $group->set(
99
            {
99
            {
100
                title       => $title,
100
                title                  => $title,
101
                description => $description,
101
                description            => $description,
102
                ft_hide_patron_info      => $ft_hide_patron_info,
102
                ft_hide_patron_info    => $ft_hide_patron_info,
103
                ft_limit_item_editing    => $ft_limit_item_editing,
103
                ft_limit_item_editing  => $ft_limit_item_editing,
104
                ft_search_groups_opac    => $ft_search_groups_opac,
104
                ft_search_groups_opac  => $ft_search_groups_opac,
105
                ft_search_groups_staff   => $ft_search_groups_staff,
105
                ft_search_groups_staff => $ft_search_groups_staff,
106
                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,
107
                ft_local_float_group   => $ft_local_float_group,
108
            }
108
            }
109
        )->store();
109
        )->store();
110
110
(-)a/circ/returns.pl (-2 / +10 lines)
Lines 298-307 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
        my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $userenv_branch });
301
        my $validate_float =
302
            Koha::Libraries->find( $item->homebranch )->validate_float_sibling( { branchcode => $userenv_branch } );
303
302
        # get the proper branch to which to return the item
304
        # get the proper branch to which to return the item
303
        # if library isn't in same the float group, transfer item to homelibrary
305
        # 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;
306
        $returnbranch =
307
              $hbr eq 'noreturn'
308
            ? $userenv_branch
309
            : $hbr eq 'returnbylibrarygroup' ? $validate_float
310
                ? $userenv_branch
311
                : $item->homebranch
312
            : $item->$hbr;
305
        my $materials = $item->materials;
313
        my $materials = $item->materials;
306
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
314
        my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
307
        $materials = $descriptions->{lib} // $materials;
315
        $materials = $descriptions->{lib} // $materials;
(-)a/t/db_dependent/Koha/Libraries.t (-13 / +28 lines)
Lines 337-364 subtest 'get_float_libraries and validate_float_sibling' => sub { Link Here
337
337
338
    $schema->storage->txn_begin;
338
    $schema->storage->txn_begin;
339
339
340
    my $library1 = $builder->build_object({ class => 'Koha::Libraries' });
340
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
341
    my $library2 = $builder->build_object({ class => 'Koha::Libraries' });
341
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
342
    my $library3 = $builder->build_object({ class => 'Koha::Libraries' });
342
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
343
    my $library4 = $builder->build_object({ class => 'Koha::Libraries' });
343
    my $library4 = $builder->build_object( { class => 'Koha::Libraries' } );
344
344
345
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_float_group => 1 } } );
345
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_float_group => 1 } } );
346
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_float_group => 1 } } );
346
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_float_group => 1 } } );
347
347
    # Float group 1
348
    # Float group 1
348
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
349
    $builder->build_object(
349
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
350
        { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } }
351
    );
352
    $builder->build_object(
353
        { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } }
354
    );
355
350
    # Float group 2
356
    # Float group 2
351
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
357
    $builder->build_object(
352
    $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
358
        { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } }
359
    );
360
    $builder->build_object(
361
        { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } }
362
    );
353
363
354
    my @libraries1 = $library1->get_float_libraries()->as_list;
364
    my @libraries1 = $library1->get_float_libraries()->as_list;
355
    is(scalar @libraries1, '2', '1st float group contains 2 libraries');
365
    is( scalar @libraries1, '2', '1st float group contains 2 libraries' );
356
366
357
    my @libraries2 = $library3->get_float_libraries()->as_list;
367
    my @libraries2 = $library3->get_float_libraries()->as_list;
358
    is(scalar @libraries2, '2', '2nd float group also contains 2 libraries');
368
    is( scalar @libraries2, '2', '2nd float group also contains 2 libraries' );
359
369
360
    ok($library1->validate_float_sibling({ branchcode => $library2->branchcode }), "Library1 and library2 belong in to the same float group.");
370
    ok(
361
    ok($library3->validate_float_sibling({ branchcode => $library4->branchcode }), "Library3 and library5 belong in to the same float group.");
371
        $library1->validate_float_sibling( { branchcode => $library2->branchcode } ),
372
        "Library1 and library2 belong in to the same float group."
373
    );
374
    ok(
375
        $library3->validate_float_sibling( { branchcode => $library4->branchcode } ),
376
        "Library3 and library5 belong in to the same float group."
377
    );
362
378
363
    $schema->storage->txn_rollback;
379
    $schema->storage->txn_rollback;
364
};
380
};
365
- 

Return to bug 9525