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

(-)a/Koha/Library/FloatLimits.pm (-5 / +5 lines)
Lines 68-83 sub lowest_ratio_library { Link Here
68
            $item_count = Koha::Items->search(
68
            $item_count = Koha::Items->search(
69
                {
69
                {
70
                    itype         => $item->effective_itemtype,
70
                    itype         => $item->effective_itemtype,
71
                    holdingbranch => $branch
71
                    holdingbranch => $branch,
72
                }
72
                    onloan        => undef
73
                },
73
            )->count;
74
            )->count;
74
        } else {
75
        } else {
75
            $item_count = Koha::Items->search(
76
            $item_count = Koha::Items->search(
76
                {
77
                {
77
                    holdingbranch         => $branch,
78
                    holdingbranch         => $branch,
78
                    'biblioitem.itemtype' => $item->effective_itemtype
79
                    'biblioitem.itemtype' => $item->effective_itemtype,
80
                    onloan                => undef
79
                },
81
                },
80
                { join => 'biblioitem' }
81
            )->count;
82
            )->count;
82
        }
83
        }
83
84
Lines 107-113 sub lowest_ratio_library { Link Here
107
            return Koha::Libraries->find( $candidate->{branchcode} );
108
            return Koha::Libraries->find( $candidate->{branchcode} );
108
        }
109
        }
109
    }
110
    }
110
111
    return;
111
    return;
112
}
112
}
113
113
(-)a/t/db_dependent/Koha/Library/FloatLimits.t (-4 / +72 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use C4::Circulation qw(CreateBranchTransferLimit);
25
use C4::Circulation qw(CreateBranchTransferLimit);
26
use Koha::DateUtils qw( dt_from_string );
26
27
27
use t::lib::Mocks;
28
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
Lines 110-116 my $float_limit3 = Koha::Library::FloatLimit->new( Link Here
110
)->store();
111
)->store();
111
112
112
is(
113
is(
113
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library3->{branchcode},
114
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode,
115
    $library3->{branchcode},
114
    "Correct library selected for float limit transfer"
116
    "Correct library selected for float limit transfer"
115
);
117
);
116
118
Lines 126-133 is( C4::Circulation::IsBranchTransferAllowed( $to, $from, $code ), 0, "Transfer Link Here
126
say "C4::Circulation::IsBranchTransferAllowed( $to, $from, $code )";
128
say "C4::Circulation::IsBranchTransferAllowed( $to, $from, $code )";
127
129
128
is(
130
is(
129
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library2->{branchcode},
131
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode,
132
    $library2->{branchcode},
130
    "Correct library selected for float limit transfer when best cannot be used"
133
    "Correct library selected for float limit transfer when best cannot be used"
131
);
134
);
132
135
136
subtest 'onloan items excluded from ratio calculation' => sub {
137
    plan tests => 5;
138
139
    # Reset transfer limits for clean test
140
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' );
141
142
    # Verify initial item counts
143
    my $library2_initial = Koha::Items->search(
144
        {
145
            holdingbranch => $library2->{branchcode},
146
            itype         => $itemtype->itemtype,
147
            onloan        => undef
148
        }
149
    )->count;
150
151
    my $library3_initial = Koha::Items->search(
152
        {
153
            holdingbranch => $library3->{branchcode},
154
            itype         => $itemtype->itemtype,
155
            onloan        => undef
156
        }
157
    )->count;
158
159
    is( $library2_initial, 10, "Library2 initially has 10 available items" );
160
    is( $library3_initial, 15, "Library3 initially has 15 available items" );
161
162
    # Initial library selection based on ratios
163
    is(
164
        Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode,
165
        $library3->{branchcode},
166
        "Library3 initially selected (lowest ratio: 15/1000 = 0.015)"
167
    );
168
169
    # Check out enough items from library3 to change the selection
170
    my @library3_items = Koha::Items->search(
171
        {
172
            holdingbranch => $library3->{branchcode},
173
            itype         => $itemtype->itemtype,
174
            onloan        => undef
175
        }
176
    )->as_list;
177
178
    my $checkout_date = dt_from_string();
179
    for my $i ( 0 .. 9 ) {
180
        $library3_items[$i]->onloan($checkout_date)->store;
181
    }
182
183
    # Verify the count decreased
184
    my $library3_after_checkout = Koha::Items->search(
185
        {
186
            holdingbranch => $library3->{branchcode},
187
            itype         => $itemtype->itemtype,
188
            onloan        => undef
189
        }
190
    )->count;
191
192
    is( $library3_after_checkout, 5, "Library3 now has 5 available items after 10 checkouts" );
193
194
    # Library3 should still be selected
195
    is(
196
        Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode,
197
        $library3->{branchcode},
198
        "Library3 still selected after checkouts (ratio now 5/1000 = 0.005, still better than library2's 10/100 = 0.1)"
199
    );
200
};
201
133
$schema->storage->txn_rollback;
202
$schema->storage->txn_rollback;
134
- 

Return to bug 28530