|
Lines 40-52
subtest 'Basic object tests' => sub {
Link Here
|
| 40 |
|
40 |
|
| 41 |
$schema->storage->txn_begin; |
41 |
$schema->storage->txn_begin; |
| 42 |
|
42 |
|
| 43 |
my $itm = $builder->build({ source => 'Item' }); |
43 |
my $itm = $builder->build_sample_item; |
| 44 |
my $stage = $builder->build({ source => 'Stockrotationstage' }); |
44 |
my $stage = $builder->build({ source => 'Stockrotationstage' }); |
| 45 |
|
45 |
|
| 46 |
my $item = $builder->build({ |
46 |
my $item = $builder->build({ |
| 47 |
source => 'Stockrotationitem', |
47 |
source => 'Stockrotationitem', |
| 48 |
value => { |
48 |
value => { |
| 49 |
itemnumber_id => $itm->{itemnumber}, |
49 |
itemnumber_id => $itm->itemnumber, |
| 50 |
stage_id => $stage->{stage_id}, |
50 |
stage_id => $stage->{stage_id}, |
| 51 |
}, |
51 |
}, |
| 52 |
}); |
52 |
}); |
|
Lines 60-66
subtest 'Basic object tests' => sub {
Link Here
|
| 60 |
|
60 |
|
| 61 |
# Relationship to rota |
61 |
# Relationship to rota |
| 62 |
isa_ok( $sritem->itemnumber, 'Koha::Item', "Fetched related item." ); |
62 |
isa_ok( $sritem->itemnumber, 'Koha::Item', "Fetched related item." ); |
| 63 |
is( $sritem->itemnumber->itemnumber, $itm->{itemnumber}, "Related rota OK." ); |
63 |
is( $sritem->itemnumber->itemnumber, $itm->itemnumber, "Related rota OK." ); |
| 64 |
|
64 |
|
| 65 |
# Relationship to stage |
65 |
# Relationship to stage |
| 66 |
isa_ok( $sritem->stage, 'Koha::StockRotationStage', "Fetched related stage." ); |
66 |
isa_ok( $sritem->stage, 'Koha::StockRotationStage', "Fetched related stage." ); |
|
Lines 130-147
subtest 'Tests for needs_repatriating' => sub {
Link Here
|
| 130 |
subtest "Tests for repatriate." => sub { |
130 |
subtest "Tests for repatriate." => sub { |
| 131 |
plan tests => 3; |
131 |
plan tests => 3; |
| 132 |
$schema->storage->txn_begin; |
132 |
$schema->storage->txn_begin; |
| 133 |
my $sritem = $builder->build({ source => 'Stockrotationitem' }); |
133 |
my $item = $builder->build_sample_item; |
| 134 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
134 |
my $rota_item = $builder->build_object( |
| 135 |
$dbitem->stage->position(1); |
135 |
{ |
| 136 |
$dbitem->stage->duration(50); |
136 |
class => 'Koha::StockRotationItems', |
|
|
137 |
value => { itemnumber_id => $item->itemnumber } |
| 138 |
} |
| 139 |
); |
| 140 |
$rota_item->stage->position(1); |
| 141 |
$rota_item->stage->duration(50); |
| 137 |
my $branch = $builder->build({ source => 'Branch' }); |
142 |
my $branch = $builder->build({ source => 'Branch' }); |
| 138 |
$dbitem->itemnumber->holdingbranch($branch->{branchcode}); |
143 |
$rota_item->itemnumber->holdingbranch($branch->{branchcode}); |
| 139 |
|
144 |
|
| 140 |
# Test a straight up repatriate |
145 |
# Test a straight up repatriate |
| 141 |
ok($dbitem->repatriate, "Repatriation done."); |
146 |
ok($rota_item->repatriate, "Repatriation done."); |
| 142 |
my $intransfer = $dbitem->itemnumber->get_transfer; |
147 |
my $intransfer = $rota_item->itemnumber->get_transfer; |
| 143 |
is($intransfer->frombranch, $branch->{branchcode}, "Origin correct."); |
148 |
is($intransfer->frombranch, $branch->{branchcode}, "Origin correct."); |
| 144 |
is($intransfer->tobranch, $dbitem->stage->branchcode_id, "Target Correct."); |
149 |
is($intransfer->tobranch, $rota_item->stage->branchcode_id, "Target Correct."); |
| 145 |
|
150 |
|
| 146 |
$schema->storage->txn_rollback; |
151 |
$schema->storage->txn_rollback; |
| 147 |
}; |
152 |
}; |
|
Lines 209-219
subtest "Tests for advance." => sub {
Link Here
|
| 209 |
plan tests => 15; |
214 |
plan tests => 15; |
| 210 |
$schema->storage->txn_begin; |
215 |
$schema->storage->txn_begin; |
| 211 |
|
216 |
|
| 212 |
my $sritem = $builder->build({ |
217 |
my $item = $builder->build_sample_item; |
| 213 |
source => 'Stockrotationitem', |
218 |
my $rota_item = $builder->build_object( |
| 214 |
value => { 'fresh' => 1 } |
219 |
{ |
| 215 |
}); |
220 |
class => 'Koha::StockRotationItems', |
| 216 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
221 |
value => { itemnumber_id => $item->itemnumber, fresh => 1 } |
|
|
222 |
} |
| 223 |
); |
| 224 |
my $dbitem = Koha::StockRotationItems->find($rota_item->itemnumber_id); |
| 217 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id); |
225 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id); |
| 218 |
my $dbstage = $dbitem->stage; |
226 |
my $dbstage = $dbitem->stage; |
| 219 |
$dbstage->position(1)->duration(50)->store; # Configure stage. |
227 |
$dbstage->position(1)->duration(50)->store; # Configure stage. |
|
Lines 233-246
subtest "Tests for advance." => sub {
Link Here
|
| 233 |
$dbstage->rota->cyclical(1)->store; # Set Rota to cyclical. |
241 |
$dbstage->rota->cyclical(1)->store; # Set Rota to cyclical. |
| 234 |
ok($dbitem->advance, "Single stage cyclical advance done."); |
242 |
ok($dbitem->advance, "Single stage cyclical advance done."); |
| 235 |
## Refetch dbitem |
243 |
## Refetch dbitem |
| 236 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
244 |
$dbitem = Koha::StockRotationItems->find($rota_item->itemnumber_id); |
| 237 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Single stage cyclical stage OK."); |
245 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Single stage cyclical stage OK."); |
| 238 |
|
246 |
|
| 239 |
# Test with indemand advance |
247 |
# Test with indemand advance |
| 240 |
$dbitem->indemand(1)->store; |
248 |
$dbitem->indemand(1)->store; |
| 241 |
ok($dbitem->advance, "Indemand item advance done."); |
249 |
ok($dbitem->advance, "Indemand item advance done."); |
| 242 |
## Refetch dbitem |
250 |
## Refetch dbitem |
| 243 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
251 |
$dbitem = Koha::StockRotationItems->find($rota_item->itemnumber_id); |
| 244 |
is($dbitem->indemand, 0, "Indemand OK."); |
252 |
is($dbitem->indemand, 0, "Indemand OK."); |
| 245 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Indemand item advance stage OK."); |
253 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Indemand item advance stage OK."); |
| 246 |
|
254 |
|
|
Lines 256-262
subtest "Tests for advance." => sub {
Link Here
|
| 256 |
# Test a straight up advance |
264 |
# Test a straight up advance |
| 257 |
ok($dbitem->advance, "Advancement done."); |
265 |
ok($dbitem->advance, "Advancement done."); |
| 258 |
## Refetch dbitem |
266 |
## Refetch dbitem |
| 259 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
267 |
$dbitem = Koha::StockRotationItems->find($rota_item->itemnumber_id); |
| 260 |
## Test results |
268 |
## Test results |
| 261 |
is($dbitem->stage->stage_id, $dbstage2->stage_id, "Stage updated."); |
269 |
is($dbitem->stage->stage_id, $dbstage2->stage_id, "Stage updated."); |
| 262 |
my $intransfer = $dbitem->itemnumber->get_transfer; |
270 |
my $intransfer = $dbitem->itemnumber->get_transfer; |
|
Lines 273-279
subtest "Tests for advance." => sub {
Link Here
|
| 273 |
# Advance again, Remove from rota. |
281 |
# Advance again, Remove from rota. |
| 274 |
ok($dbitem->advance, "Non-cyclical advance."); |
282 |
ok($dbitem->advance, "Non-cyclical advance."); |
| 275 |
## Refetch dbitem |
283 |
## Refetch dbitem |
| 276 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
284 |
$dbitem = Koha::StockRotationItems->find($rota_item->itemnumber_id); |
| 277 |
is($dbitem, undef, "StockRotationItem has been removed."); |
285 |
is($dbitem, undef, "StockRotationItem has been removed."); |
| 278 |
|
286 |
|
| 279 |
$schema->storage->txn_rollback; |
287 |
$schema->storage->txn_rollback; |
|
Lines 284-305
subtest "Tests for investigate (singular)." => sub {
Link Here
|
| 284 |
$schema->storage->txn_begin; |
292 |
$schema->storage->txn_begin; |
| 285 |
|
293 |
|
| 286 |
# Test brand new item's investigation ['initiation'] |
294 |
# Test brand new item's investigation ['initiation'] |
| 287 |
my $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1 } }); |
295 |
my $sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1, itemnumber_id => $builder->build_sample_item->itemnumber } }); |
| 288 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
296 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 289 |
is($dbitem->investigate->{reason}, 'initiation', "fresh item initiates."); |
297 |
is($dbitem->investigate->{reason}, 'initiation', "fresh item initiates."); |
| 290 |
|
298 |
|
| 291 |
# Test brand new item at stagebranch ['initiation'] |
299 |
# Test brand new item at stagebranch ['initiation'] |
| 292 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1 } }); |
300 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1, itemnumber_id => $builder->build_sample_item->itemnumber } }); |
| 293 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
301 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 294 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
302 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
| 295 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store; |
303 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store; |
| 296 |
is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates."); |
304 |
is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates."); |
| 297 |
|
305 |
|
| 298 |
# Test item not at stagebranch with branchtransfer history ['repatriation'] |
306 |
# Test item not at stagebranch with branchtransfer history ['repatriation'] |
| 299 |
$sritem = $builder->build({ |
307 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1, itemnumber_id => $builder->build_sample_item->itemnumber } }); |
| 300 |
source => 'Stockrotationitem', |
|
|
| 301 |
value => { 'fresh' => 0,} |
| 302 |
}); |
| 303 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
308 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 304 |
my $dbtransfer = Koha::Item::Transfer->new({ |
309 |
my $dbtransfer = Koha::Item::Transfer->new({ |
| 305 |
'itemnumber' => $dbitem->itemnumber_id, |
310 |
'itemnumber' => $dbitem->itemnumber_id, |
|
Lines 312-321
subtest "Tests for investigate (singular)." => sub {
Link Here
|
| 312 |
is($dbitem->investigate->{reason}, 'repatriation', "older item repatriates."); |
317 |
is($dbitem->investigate->{reason}, 'repatriation', "older item repatriates."); |
| 313 |
|
318 |
|
| 314 |
# Test item at stagebranch with branchtransfer history ['not-ready'] |
319 |
# Test item at stagebranch with branchtransfer history ['not-ready'] |
| 315 |
$sritem = $builder->build({ |
320 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1, itemnumber_id => $builder->build_sample_item->itemnumber } }); |
| 316 |
source => 'Stockrotationitem', |
|
|
| 317 |
value => { 'fresh' => 0,} |
| 318 |
}); |
| 319 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
321 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 320 |
$dbtransfer = Koha::Item::Transfer->new({ |
322 |
$dbtransfer = Koha::Item::Transfer->new({ |
| 321 |
'itemnumber' => $dbitem->itemnumber_id, |
323 |
'itemnumber' => $dbitem->itemnumber_id, |
|
Lines 330-336
subtest "Tests for investigate (singular)." => sub {
Link Here
|
| 330 |
is($dbitem->investigate->{reason}, 'not-ready', "older item at stagebranch not-ready."); |
332 |
is($dbitem->investigate->{reason}, 'not-ready', "older item at stagebranch not-ready."); |
| 331 |
|
333 |
|
| 332 |
# Test item due for advancement ['advancement'] |
334 |
# Test item due for advancement ['advancement'] |
| 333 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } }); |
335 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1, itemnumber_id => $builder->build_sample_item->itemnumber } }); |
| 334 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
336 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 335 |
$dbitem->indemand(0)->store; |
337 |
$dbitem->indemand(0)->store; |
| 336 |
$dbitem->stage->duration(50)->store; |
338 |
$dbitem->stage->duration(50)->store; |
|
Lines 350-356
subtest "Tests for investigate (singular)." => sub {
Link Here
|
| 350 |
"Item ready for advancement."); |
352 |
"Item ready for advancement."); |
| 351 |
|
353 |
|
| 352 |
# Test item due for advancement but in-demand ['in-demand'] |
354 |
# Test item due for advancement but in-demand ['in-demand'] |
| 353 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } }); |
355 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1, itemnumber_id => $builder->build_sample_item->itemnumber } }); |
| 354 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
356 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 355 |
$dbitem->indemand(1)->store; |
357 |
$dbitem->indemand(1)->store; |
| 356 |
$dbitem->stage->duration(50)->store; |
358 |
$dbitem->stage->duration(50)->store; |
|
Lines 370-376
subtest "Tests for investigate (singular)." => sub {
Link Here
|
| 370 |
"Item advances, but in-demand."); |
372 |
"Item advances, but in-demand."); |
| 371 |
|
373 |
|
| 372 |
# Test item ready for advancement, but at wrong library ['repatriation'] |
374 |
# Test item ready for advancement, but at wrong library ['repatriation'] |
| 373 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 0 } }); |
375 |
$sritem = $builder->build({ source => 'Stockrotationitem', value => { fresh => 1, itemnumber_id => $builder->build_sample_item->itemnumber } }); |
| 374 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
376 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 375 |
$dbitem->indemand(0)->store; |
377 |
$dbitem->indemand(0)->store; |
| 376 |
$dbitem->stage->duration(50)->store; |
378 |
$dbitem->stage->duration(50)->store; |
| 377 |
- |
|
|