|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
| 23 |
|
23 |
|
| 24 |
use Koha::Database; |
24 |
use Koha::Database; |
| 25 |
use C4::Circulation qw(CreateBranchTransferLimit); |
25 |
use C4::Circulation qw(CreateBranchTransferLimit); |
|
Lines 199-202
subtest 'onloan items excluded from ratio calculation' => sub {
Link Here
|
| 199 |
); |
199 |
); |
| 200 |
}; |
200 |
}; |
| 201 |
|
201 |
|
|
|
202 |
subtest 'items in transit counted toward destination branch' => sub { |
| 203 |
plan tests => 6; |
| 204 |
|
| 205 |
# Reset transfer limits for clean test |
| 206 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); |
| 207 |
|
| 208 |
Koha::Items->search( |
| 209 |
{ |
| 210 |
holdingbranch => $library3->{branchcode}, |
| 211 |
itype => $itemtype->itemtype, |
| 212 |
onloan => { '!=' => undef } |
| 213 |
} |
| 214 |
)->update( { onloan => undef } ); |
| 215 |
|
| 216 |
# Verify initial counts |
| 217 |
my $library2_initial = Koha::Items->search( |
| 218 |
{ |
| 219 |
holdingbranch => $library2->{branchcode}, |
| 220 |
itype => $itemtype->itemtype, |
| 221 |
onloan => undef |
| 222 |
} |
| 223 |
)->count; |
| 224 |
|
| 225 |
my $library3_initial = Koha::Items->search( |
| 226 |
{ |
| 227 |
holdingbranch => $library3->{branchcode}, |
| 228 |
itype => $itemtype->itemtype, |
| 229 |
onloan => undef |
| 230 |
} |
| 231 |
)->count; |
| 232 |
|
| 233 |
is( $library2_initial, 10, "Library2 initially has 10 available items" ); |
| 234 |
is( $library3_initial, 15, "Library3 initially has 15 available items" ); |
| 235 |
|
| 236 |
# Initial selection should be library3 |
| 237 |
is( |
| 238 |
Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode, |
| 239 |
$library3->{branchcode}, |
| 240 |
"Library3 initially selected (ratio: 15/1000 = 0.015)" |
| 241 |
); |
| 242 |
|
| 243 |
# Create items in transit TO library2 |
| 244 |
my @transit_items; |
| 245 |
for ( 1 .. 2 ) { |
| 246 |
my $transit_item = $builder->build_sample_item( |
| 247 |
{ |
| 248 |
biblionumber => $biblio->biblionumber, |
| 249 |
homebranch => $library1->{branchcode}, |
| 250 |
holdingbranch => $library1->{branchcode}, |
| 251 |
itype => $itemtype->itemtype, |
| 252 |
} |
| 253 |
); |
| 254 |
push @transit_items, $transit_item; |
| 255 |
} |
| 256 |
|
| 257 |
# Create active transfers to library2 |
| 258 |
my $transfer_date = dt_from_string(); |
| 259 |
for my $transit_item (@transit_items) { |
| 260 |
Koha::Item::Transfer->new( |
| 261 |
{ |
| 262 |
itemnumber => $transit_item->itemnumber, |
| 263 |
frombranch => $library1->{branchcode}, |
| 264 |
tobranch => $library2->{branchcode}, |
| 265 |
daterequested => $transfer_date, |
| 266 |
datesent => $transfer_date, |
| 267 |
reason => 'LibraryFloatLimit' |
| 268 |
} |
| 269 |
)->store; |
| 270 |
} |
| 271 |
|
| 272 |
# Verify that items in transit are counted toward destination |
| 273 |
my $in_transit_count = Koha::Items->search( |
| 274 |
{ |
| 275 |
itype => $itemtype->itemtype, |
| 276 |
}, |
| 277 |
{ |
| 278 |
join => 'branchtransfers', |
| 279 |
where => { |
| 280 |
'branchtransfers.tobranch' => $library2->{branchcode}, |
| 281 |
'branchtransfers.datearrived' => undef, |
| 282 |
'branchtransfers.datecancelled' => undef, |
| 283 |
}, |
| 284 |
distinct => 1 |
| 285 |
} |
| 286 |
)->count; |
| 287 |
|
| 288 |
is( $in_transit_count, 2, "2 items are in transit to library2" ); |
| 289 |
|
| 290 |
# Test 5: Library2's physical count should still be 10 |
| 291 |
my $library2_physical = Koha::Items->search( |
| 292 |
{ |
| 293 |
holdingbranch => $library2->{branchcode}, |
| 294 |
itype => $itemtype->itemtype, |
| 295 |
onloan => undef |
| 296 |
} |
| 297 |
)->count; |
| 298 |
|
| 299 |
is( $library2_physical, 10, "Library2 still has 10 physical items" ); |
| 300 |
|
| 301 |
# Library2's count should now be 10 + 2 = 12 |
| 302 |
is( |
| 303 |
Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode, |
| 304 |
$library3->{branchcode}, |
| 305 |
"Library3 still selected after items in transit to library2" |
| 306 |
); |
| 307 |
}; |
| 308 |
|
| 202 |
$schema->storage->txn_rollback; |
309 |
$schema->storage->txn_rollback; |
| 203 |
- |
|
|