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

(-)a/Koha/Library/FloatLimits.pm (-2 / +34 lines)
Lines 41-47 Koha::Library::FloatLimits - Koha Library::FloatLimit object set class Link Here
41
41
42
sub lowest_ratio_library {
42
sub lowest_ratio_library {
43
    my ( $self, $item, $branchcode ) = @_;
43
    my ( $self, $item, $branchcode ) = @_;
44
45
    my $schema = Koha::Database->new->schema;
44
    my $schema = Koha::Database->new->schema;
46
45
47
    my @float_limits = $schema->resultset('LibraryFloatLimit')->search(
46
    my @float_limits = $schema->resultset('LibraryFloatLimit')->search(
Lines 51-56 sub lowest_ratio_library { Link Here
51
        }
50
        }
52
    )->all;
51
    )->all;
53
52
53
    # check the items return policy
54
    my $hbr = Koha::CirculationRules->get_return_branch_policy($item);
55
56
    # if item only floats in the library group we must eliminate all other canditates
57
    if ( $hbr && $hbr eq 'returnbylibrarygroup' ) {
58
        my @allowed_branchcodes = ();
59
60
        my @current_groups = Koha::Libraries->find($branchcode)->library_groups->as_list;
61
        for my $group (@current_groups) {
62
            my $parent_id = $group->parent_id;
63
64
            if ($parent_id) {
65
                my @sibling_groups = $schema->resultset('LibraryGroup')->search(
66
                    {
67
                        parent_id  => $parent_id,
68
                        branchcode => { '!=' => undef }
69
                    }
70
                )->all;
71
72
                for my $sibling (@sibling_groups) {
73
                    push @allowed_branchcodes, $sibling->get_column('branchcode');
74
                }
75
            }
76
        }
77
78
        if (@allowed_branchcodes) {
79
            my %allowed_branches = map { $_ => 1 } @allowed_branchcodes;
80
            @float_limits = grep { $allowed_branches{ $_->get_column('branchcode') } } @float_limits;
81
        }
82
    }
83
54
    return unless @float_limits;
84
    return unless @float_limits;
55
85
56
    my @candidates;
86
    my @candidates;
Lines 162-173 sub lowest_ratio_library { Link Here
162
192
163
    my $transfer_branch;
193
    my $transfer_branch;
164
    for my $candidate (@candidates) {
194
    for my $candidate (@candidates) {
195
165
        if ($UseBranchTransferLimits) {
196
        if ($UseBranchTransferLimits) {
197
166
            my $allowed = C4::Circulation::IsBranchTransferAllowed(
198
            my $allowed = C4::Circulation::IsBranchTransferAllowed(
167
                $candidate->{branchcode},
199
                $candidate->{branchcode},
168
                $branchcode,
200
                $branchcode,
169
                $item->$BranchTransferLimitsType
201
                $item->$BranchTransferLimitsType
170
            );
202
            );
203
171
            $transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed;
204
            $transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed;
172
            last;
205
            last;
173
        } else {
206
        } else {
174
- 

Return to bug 28530