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

(-)a/Koha/StockRotationItem.pm (-19 / +19 lines)
Lines 57-71 sub _type { Link Here
57
    return 'Stockrotationitem';
57
    return 'Stockrotationitem';
58
}
58
}
59
59
60
=head3 itemnumber
60
=head3 item
61
61
62
  my $item = Koha::StockRotationItem->itemnumber;
62
  my $item = Koha::StockRotationItem->item;
63
63
64
Returns the item associated with the current stock rotation item.
64
Returns the item associated with the current stock rotation item.
65
65
66
=cut
66
=cut
67
67
68
sub itemnumber {
68
sub item {
69
    my ( $self ) = @_;
69
    my ( $self ) = @_;
70
    my $rs = $self->_result->itemnumber;
70
    my $rs = $self->_result->itemnumber;
71
    return Koha::Item->_new_from_dbic( $rs );
71
    return Koha::Item->_new_from_dbic( $rs );
Lines 96-103 according to our stockrotation plan. Link Here
96
96
97
sub needs_repatriating {
97
sub needs_repatriating {
98
    my ( $self ) = @_;
98
    my ( $self ) = @_;
99
    my ( $item, $stage ) = ( $self->itemnumber, $self->stage );
99
    my ( $item, $stage ) = ( $self->item, $self->stage );
100
    if ( $self->itemnumber->get_transfer ) {
100
    if ( $self->item->get_transfer ) {
101
        return 0;               # We're in transit.
101
        return 0;               # We're in transit.
102
    } elsif ( $item->holdingbranch ne $stage->branchcode_id
102
    } elsif ( $item->holdingbranch ne $stage->branchcode_id
103
                  || $item->homebranch ne $stage->branchcode_id ) {
103
                  || $item->homebranch ne $stage->branchcode_id ) {
Lines 117-125 Return 1 if this item is ready to be moved on to the next stage in its rota. Link Here
117
117
118
sub needs_advancing {
118
sub needs_advancing {
119
    my ( $self ) = @_;
119
    my ( $self ) = @_;
120
    return 0 if $self->itemnumber->get_transfer; # intransfer: don't advance.
120
    return 0 if $self->item->get_transfer; # intransfer: don't advance.
121
    return 1 if $self->fresh;                    # Just on rota: advance.
121
    return 1 if $self->fresh;                    # Just on rota: advance.
122
    my $completed = $self->itemnumber->_result->branchtransfers->search(
122
    my $completed = $self->item->_result->branchtransfers->search(
123
        { 'reason' => "StockrotationAdvance" },
123
        { 'reason' => "StockrotationAdvance" },
124
        { order_by => { -desc => 'datearrived' } }
124
        { order_by => { -desc => 'datearrived' } }
125
    );
125
    );
Lines 136-142 sub needs_advancing { Link Here
136
            return 0;
136
            return 0;
137
        }
137
        }
138
    } else {
138
    } else {
139
        warn "We have no historical branch transfer for itemnumber " . $self->itemnumber->itemnumber . "; This should not have happened!";
139
        warn "We have no historical branch transfer for item " . $self->item->itemnumber . "; This should not have happened!";
140
    }
140
    }
141
}
141
}
142
142
Lines 157-163 sub repatriate { Link Here
157
157
158
    # Create the transfer.
158
    # Create the transfer.
159
    my $transfer = try {
159
    my $transfer = try {
160
        $self->itemnumber->request_transfer(
160
        $self->item->request_transfer(
161
            {
161
            {
162
                to            => $self->stage->branchcode,
162
                to            => $self->stage->branchcode,
163
                reason        => "StockrotationRepatriation",
163
                reason        => "StockrotationRepatriation",
Lines 168-174 sub repatriate { Link Here
168
    };
168
    };
169
169
170
    # Ensure the homebranch is still in sync with the rota stage
170
    # Ensure the homebranch is still in sync with the rota stage
171
    $self->itemnumber->homebranch( $self->stage->branchcode_id )->store;
171
    $self->item->homebranch( $self->stage->branchcode_id )->store;
172
172
173
    return defined($transfer) ? 1 : 0;
173
    return defined($transfer) ? 1 : 0;
174
}
174
}
Lines 194-200 pass 'ignore_limits' in the call to request_transfer. Link Here
194
194
195
sub advance {
195
sub advance {
196
    my ($self)         = @_;
196
    my ($self)         = @_;
197
    my $item           = $self->itemnumber;
197
    my $item           = $self->item;
198
    my $current_branch = $item->holdingbranch;
198
    my $current_branch = $item->holdingbranch;
199
    my $transfer;
199
    my $transfer;
200
200
Lines 298-304 sub toggle_indemand { Link Here
298
298
299
    # Cancel 'StockrotationAdvance' transfer if one is in progress
299
    # Cancel 'StockrotationAdvance' transfer if one is in progress
300
    if ($new_indemand) {
300
    if ($new_indemand) {
301
        my $item = $self->itemnumber;
301
        my $item = $self->item;
302
        my $transfer = $item->get_transfer;
302
        my $transfer = $item->get_transfer;
303
        if ($transfer && $transfer->reason eq 'StockrotationAdvance') {
303
        if ($transfer && $transfer->reason eq 'StockrotationAdvance') {
304
            my $stage = $self->stage;
304
            my $stage = $self->stage;
Lines 332-347 generating stockrotation reports about this stockrotationitem. Link Here
332
sub investigate {
332
sub investigate {
333
    my ( $self ) = @_;
333
    my ( $self ) = @_;
334
    my $item_report = {
334
    my $item_report = {
335
        title      => $self->itemnumber->_result->biblioitem
335
        title      => $self->item->_result->biblioitem
336
            ->biblionumber->title,
336
            ->biblionumber->title,
337
        author     => $self->itemnumber->_result->biblioitem
337
        author     => $self->item->_result->biblioitem
338
            ->biblionumber->author,
338
            ->biblionumber->author,
339
        callnumber => $self->itemnumber->itemcallnumber,
339
        callnumber => $self->item->itemcallnumber,
340
        location   => $self->itemnumber->location,
340
        location   => $self->item->location,
341
        onloan     => $self->itemnumber->onloan,
341
        onloan     => $self->item->onloan,
342
        barcode    => $self->itemnumber->barcode,
342
        barcode    => $self->item->barcode,
343
        itemnumber => $self->itemnumber_id,
343
        itemnumber => $self->itemnumber_id,
344
        branch => $self->itemnumber->_result->holdingbranch,
344
        branch => $self->item->_result->holdingbranch,
345
        object => $self,
345
        object => $self,
346
    };
346
    };
347
    my $reason;
347
    my $reason;
(-)a/t/db_dependent/StockRotationItems.t (-58 / +57 lines)
Lines 63-70 subtest 'Basic object tests' => sub { Link Here
63
    );
63
    );
64
64
65
    # Relationship to rota
65
    # Relationship to rota
66
    isa_ok( $sritem->itemnumber, 'Koha::Item', "Fetched related item." );
66
    isa_ok( $sritem->item, 'Koha::Item', "Fetched related item." );
67
    is( $sritem->itemnumber->itemnumber, $itm->itemnumber, "Related rota OK." );
67
    is( $sritem->item->itemnumber, $itm->itemnumber, "Related rota OK." );
68
68
69
    # Relationship to stage
69
    # Relationship to stage
70
    isa_ok( $sritem->stage, 'Koha::StockRotationStage', "Fetched related stage." );
70
    isa_ok( $sritem->stage, 'Koha::StockRotationStage', "Fetched related stage." );
Lines 89-96 subtest 'Tests for needs_repatriating' => sub { Link Here
89
        }
89
        }
90
    );
90
    );
91
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
91
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
92
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id);
92
    $dbitem->item->homebranch($dbitem->stage->branchcode_id);
93
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
93
    $dbitem->item->holdingbranch($dbitem->stage->branchcode_id);
94
    $dbitem->stage->position(1);
94
    $dbitem->stage->position(1);
95
95
96
    my $dbrota = $dbitem->stage->rota;
96
    my $dbrota = $dbitem->stage->rota;
Lines 109-115 subtest 'Tests for needs_repatriating' => sub { Link Here
109
    );
109
    );
110
110
111
    my $branch = $builder->build({ source => 'Branch' });
111
    my $branch = $builder->build({ source => 'Branch' });
112
    $dbitem->itemnumber->holdingbranch($branch->{branchcode});
112
    $dbitem->item->holdingbranch($branch->{branchcode});
113
113
114
    # - homebranch != holdingbranch [1]
114
    # - homebranch != holdingbranch [1]
115
    is(
115
    is(
Lines 118-125 subtest 'Tests for needs_repatriating' => sub { Link Here
118
    );
118
    );
119
119
120
    # Set to incorrect homebranch.
120
    # Set to incorrect homebranch.
121
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
121
    $dbitem->item->holdingbranch($dbitem->stage->branchcode_id);
122
    $dbitem->itemnumber->homebranch($branch->{branchcode});
122
    $dbitem->item->homebranch($branch->{branchcode});
123
    # - homebranch != stockrotationstage.branch & not in transit [1]
123
    # - homebranch != stockrotationstage.branch & not in transit [1]
124
    is(
124
    is(
125
        $dbitem->needs_repatriating, 1,
125
        $dbitem->needs_repatriating, 1,
Lines 149-171 subtest "Tests for repatriate." => sub { Link Here
149
            }
149
            }
150
        }
150
        }
151
    );
151
    );
152
    my $item_id = $sritem_1->itemnumber->itemnumber;
152
    my $item_id = $sritem_1->item->itemnumber;
153
    my $srstage_1 = $sritem_1->stage;
153
    my $srstage_1 = $sritem_1->stage;
154
    $sritem_1->discard_changes;
154
    $sritem_1->discard_changes;
155
    $sritem_1->stage->position(1);
155
    $sritem_1->stage->position(1);
156
    $sritem_1->stage->duration(50);
156
    $sritem_1->stage->duration(50);
157
    my $branch = $builder->build({ source => 'Branch' });
157
    my $branch = $builder->build({ source => 'Branch' });
158
    $sritem_1->itemnumber->holdingbranch($branch->{branchcode});
158
    $sritem_1->item->holdingbranch($branch->{branchcode});
159
159
160
    # Test a straight up repatriate
160
    # Test a straight up repatriate
161
    ok($sritem_1->repatriate, "Repatriation done.");
161
    ok($sritem_1->repatriate, "Repatriation done.");
162
    my $intransfer = $sritem_1->itemnumber->get_transfer;
162
    my $intransfer = $sritem_1->item->get_transfer;
163
    is($intransfer->frombranch, $branch->{branchcode}, "Origin correct.");
163
    is($intransfer->frombranch, $branch->{branchcode}, "Origin correct.");
164
    is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct.");
164
    is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct.");
165
165
166
    # Reset
166
    # Reset
167
    $intransfer->datearrived(dt_from_string())->store;
167
    $intransfer->datearrived(dt_from_string())->store;
168
    $sritem_1->itemnumber->holdingbranch($branch->{branchcode});
168
    $sritem_1->item->holdingbranch($branch->{branchcode});
169
169
170
    # Setup a conflicting manual transfer
170
    # Setup a conflicting manual transfer
171
    my $item = Koha::Items->find($item_id);
171
    my $item = Koha::Items->find($item_id);
Lines 179-185 subtest "Tests for repatriate." => sub { Link Here
179
179
180
    # Reset
180
    # Reset
181
    $intransfer->datearrived(dt_from_string())->store;
181
    $intransfer->datearrived(dt_from_string())->store;
182
    $sritem_1->itemnumber->holdingbranch($branch->{branchcode});
182
    $sritem_1->item->holdingbranch($branch->{branchcode});
183
183
184
    # Confirm that stockrotation ignores transfer limits
184
    # Confirm that stockrotation ignores transfer limits
185
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
185
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
Lines 188-200 subtest "Tests for repatriate." => sub { Link Here
188
        {
188
        {
189
            fromBranch => $branch->{branchcode},
189
            fromBranch => $branch->{branchcode},
190
            toBranch   => $srstage_1->branchcode_id,
190
            toBranch   => $srstage_1->branchcode_id,
191
            itemtype   => $sritem_1->itemnumber->effective_itemtype,
191
            itemtype   => $sritem_1->item->effective_itemtype,
192
        }
192
        }
193
    )->store;
193
    )->store;
194
194
195
    # Stockrotation should overrule transfer limits
195
    # Stockrotation should overrule transfer limits
196
    ok($sritem_1->repatriate, "Repatriation done regardless of transfer limits.");
196
    ok($sritem_1->repatriate, "Repatriation done regardless of transfer limits.");
197
    $intransfer = $sritem_1->itemnumber->get_transfer;
197
    $intransfer = $sritem_1->item->get_transfer;
198
    is($intransfer->frombranch, $branch->{branchcode}, "Origin correct.");
198
    is($intransfer->frombranch, $branch->{branchcode}, "Origin correct.");
199
    is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct.");
199
    is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct.");
200
200
Lines 229-236 subtest "Tests for needs_advancing." => sub { Link Here
229
        }
229
        }
230
    );
230
    );
231
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
231
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
232
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id);
232
    $dbitem->item->homebranch($dbitem->stage->branchcode_id);
233
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id);
233
    $dbitem->item->holdingbranch($dbitem->stage->branchcode_id);
234
    $dbitem->stage->position(1);
234
    $dbitem->stage->position(1);
235
    $dbitem->stage->duration(50);
235
    $dbitem->stage->duration(50);
236
236
Lines 267-273 subtest "Tests for needs_advancing." => sub { Link Here
267
    )->store;
267
    )->store;
268
    is($dbitem->needs_advancing, 1, "Ready to be advanced.");
268
    is($dbitem->needs_advancing, 1, "Ready to be advanced.");
269
    $dbtransfer->delete;
269
    $dbtransfer->delete;
270
    warning_is {$dbitem->needs_advancing} "We have no historical branch transfer for itemnumber " . $dbitem->itemnumber->itemnumber . "; This should not have happened!", "Missing transfer is warned.";
270
    warning_is {$dbitem->needs_advancing} "We have no historical branch transfer for itemnumber " . $dbitem->item->itemnumber . "; This should not have happened!", "Missing transfer is warned.";
271
271
272
    $schema->storage->txn_rollback;
272
    $schema->storage->txn_rollback;
273
};
273
};
Lines 286-298 subtest "Tests for advance." => sub { Link Here
286
        }
286
        }
287
    );
287
    );
288
    $sritem_1->discard_changes;
288
    $sritem_1->discard_changes;
289
    $sritem_1->itemnumber->holdingbranch($sritem_1->stage->branchcode_id);
289
    $sritem_1->item->holdingbranch($sritem_1->stage->branchcode_id);
290
    my $item_id = $sritem_1->itemnumber->itemnumber;
290
    my $item_id = $sritem_1->item->itemnumber;
291
    my $srstage_1 = $sritem_1->stage;
291
    my $srstage_1 = $sritem_1->stage;
292
    $srstage_1->position(1)->duration(50)->store; # Configure stage.
292
    $srstage_1->position(1)->duration(50)->store; # Configure stage.
293
    # Configure item
293
    # Configure item
294
    $sritem_1->itemnumber->holdingbranch($srstage_1->branchcode_id)->store;
294
    $sritem_1->item->holdingbranch($srstage_1->branchcode_id)->store;
295
    $sritem_1->itemnumber->homebranch($srstage_1->branchcode_id)->store;
295
    $sritem_1->item->homebranch($srstage_1->branchcode_id)->store;
296
    # Sanity check
296
    # Sanity check
297
    is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage sanity check.");
297
    is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage sanity check.");
298
298
Lines 333-350 subtest "Tests for advance." => sub { Link Here
333
    ## Test results
333
    ## Test results
334
    is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated.");
334
    is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated.");
335
    is(
335
    is(
336
        $sritem_1->itemnumber->homebranch,
336
        $sritem_1->item->homebranch,
337
        $srstage_2->branchcode_id,
337
        $srstage_2->branchcode_id,
338
        "Item homebranch updated"
338
        "Item homebranch updated"
339
    );
339
    );
340
    my $transfer_request = $sritem_1->itemnumber->get_transfer;
340
    my $transfer_request = $sritem_1->item->get_transfer;
341
    is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct.");
341
    is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct.");
342
    is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target Correct.");
342
    is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target Correct.");
343
    is($transfer_request->datesent, undef, "Transfer requested, but not sent.");
343
    is($transfer_request->datesent, undef, "Transfer requested, but not sent.");
344
344
345
    # Arrive at new branch
345
    # Arrive at new branch
346
    $transfer_request->datearrived(dt_from_string())->store;
346
    $transfer_request->datearrived(dt_from_string())->store;
347
    $sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store;
347
    $sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store;
348
348
349
    # Test a cyclical advance
349
    # Test a cyclical advance
350
    ok($sritem_1->advance, "Cyclical advancement done.");
350
    ok($sritem_1->advance, "Cyclical advancement done.");
Lines 353-369 subtest "Tests for advance." => sub { Link Here
353
    ## Test results
353
    ## Test results
354
    is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage updated.");
354
    is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage updated.");
355
    is(
355
    is(
356
        $sritem_1->itemnumber->homebranch,
356
        $sritem_1->item->homebranch,
357
        $srstage_1->branchcode_id,
357
        $srstage_1->branchcode_id,
358
        "Item homebranch updated"
358
        "Item homebranch updated"
359
    );
359
    );
360
    $transfer_request = $sritem_1->itemnumber->get_transfer;
360
    $transfer_request = $sritem_1->item->get_transfer;
361
    is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct.");
361
    is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct.");
362
    is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct.");
362
    is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct.");
363
363
364
    # Arrive at new branch
364
    # Arrive at new branch
365
    $transfer_request->datearrived(dt_from_string())->store;
365
    $transfer_request->datearrived(dt_from_string())->store;
366
    $sritem_1->itemnumber->holdingbranch($srstage_1->branchcode_id)->store;
366
    $sritem_1->item->holdingbranch($srstage_1->branchcode_id)->store;
367
367
368
    # Confirm that stockrotation ignores transfer limits
368
    # Confirm that stockrotation ignores transfer limits
369
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
369
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
Lines 372-378 subtest "Tests for advance." => sub { Link Here
372
        {
372
        {
373
            fromBranch => $srstage_1->branchcode_id,
373
            fromBranch => $srstage_1->branchcode_id,
374
            toBranch   => $srstage_2->branchcode_id,
374
            toBranch   => $srstage_2->branchcode_id,
375
            itemtype   => $sritem_1->itemnumber->effective_itemtype,
375
            itemtype   => $sritem_1->item->effective_itemtype,
376
        }
376
        }
377
    )->store;
377
    )->store;
378
378
Lines 382-398 subtest "Tests for advance." => sub { Link Here
382
    ## Test results
382
    ## Test results
383
    is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated ignoring transfer limits.");
383
    is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated ignoring transfer limits.");
384
    is(
384
    is(
385
        $sritem_1->itemnumber->homebranch,
385
        $sritem_1->item->homebranch,
386
        $srstage_2->branchcode_id,
386
        $srstage_2->branchcode_id,
387
        "Item homebranch updated ignoring transfer limits"
387
        "Item homebranch updated ignoring transfer limits"
388
    );
388
    );
389
    $transfer_request = $sritem_1->itemnumber->get_transfer;
389
    $transfer_request = $sritem_1->item->get_transfer;
390
    is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct ignoring transfer limits.");
390
    is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct ignoring transfer limits.");
391
    is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct ignoring transfer limits.");
391
    is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct ignoring transfer limits.");
392
392
393
    # Arrive at new branch
393
    # Arrive at new branch
394
    $transfer_request->datearrived(dt_from_string())->store;
394
    $transfer_request->datearrived(dt_from_string())->store;
395
    $sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store;
395
    $sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store;
396
396
397
    # Setup a conflicting manual transfer
397
    # Setup a conflicting manual transfer
398
    my $item = Koha::Items->find($item_id);
398
    my $item = Koha::Items->find($item_id);
Lines 413-426 subtest "Tests for advance." => sub { Link Here
413
    isnt($transfer_request->datecancelled, undef, "Conflicting manual transfer was cancelled");
413
    isnt($transfer_request->datecancelled, undef, "Conflicting manual transfer was cancelled");
414
414
415
    # StockRotationAdvance transfer added
415
    # StockRotationAdvance transfer added
416
    $transfer_request = $sritem_1->itemnumber->get_transfer;
416
    $transfer_request = $sritem_1->item->get_transfer;
417
    is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer added");
417
    is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer added");
418
    is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct.");
418
    is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct.");
419
    is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct.");
419
    is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct.");
420
420
421
    # Arrive at new branch
421
    # Arrive at new branch
422
    $transfer_request->datearrived(dt_from_string())->store;
422
    $transfer_request->datearrived(dt_from_string())->store;
423
    $sritem_1->itemnumber->holdingbranch($srstage_1->branchcode_id)->store;
423
    $sritem_1->item->holdingbranch($srstage_1->branchcode_id)->store;
424
424
425
    # Setup a conflicting reserve transfer
425
    # Setup a conflicting reserve transfer
426
    $item->request_transfer({ to => $srstage_2->branchcode, reason => "Reserve" });
426
    $item->request_transfer({ to => $srstage_2->branchcode, reason => "Reserve" });
Lines 442-448 subtest "Tests for advance." => sub { Link Here
442
    # StockRotationAdvance transfer added
442
    # StockRotationAdvance transfer added
443
    my $transfer_requests = Koha::Item::Transfers->search(
443
    my $transfer_requests = Koha::Item::Transfers->search(
444
        {
444
        {
445
            itemnumber    => $sritem_1->itemnumber->itemnumber,
445
            itemnumber    => $sritem_1->item->itemnumber,
446
            datearrived   => undef,
446
            datearrived   => undef,
447
            datecancelled => undef
447
            datecancelled => undef
448
        }
448
        }
Lines 451-467 subtest "Tests for advance." => sub { Link Here
451
451
452
    # Arrive at new branch
452
    # Arrive at new branch
453
    $transfer_request->datearrived(dt_from_string())->store;
453
    $transfer_request->datearrived(dt_from_string())->store;
454
    $sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store;
454
    $sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store;
455
455
456
    # StockRotationAdvance transfer added
456
    # StockRotationAdvance transfer added
457
    $transfer_request = $sritem_1->itemnumber->get_transfer;
457
    $transfer_request = $sritem_1->item->get_transfer;
458
    is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer remains after reserve is met");
458
    is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer remains after reserve is met");
459
    is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct.");
459
    is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct.");
460
    is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct.");
460
    is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct.");
461
461
462
    # Arrive at new branch
462
    # Arrive at new branch
463
    $transfer_request->datearrived(dt_from_string())->store;
463
    $transfer_request->datearrived(dt_from_string())->store;
464
    $sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store;
464
    $sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store;
465
465
466
    $srstage_1->rota->cyclical(0)->store;         # Set Rota to non-cyclical.
466
    $srstage_1->rota->cyclical(0)->store;         # Set Rota to non-cyclical.
467
467
Lines 478-484 subtest "Tests for advance." => sub { Link Here
478
478
479
    # Arrive at new branch
479
    # Arrive at new branch
480
    $transfer_request->datearrived(dt_from_string())->store;
480
    $transfer_request->datearrived(dt_from_string())->store;
481
    $sritem_1->itemnumber->holdingbranch($srstage_3->branchcode_id)->store;
481
    $sritem_1->item->holdingbranch($srstage_3->branchcode_id)->store;
482
482
483
    # Advance again, Remove from rota.
483
    # Advance again, Remove from rota.
484
    ok($sritem_1->advance, "Non-cyclical advance.");
484
    ok($sritem_1->advance, "Non-cyclical advance.");
Lines 519-526 subtest "Tests for investigate (singular)." => sub { Link Here
519
        }
519
        }
520
    );
520
    );
521
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
521
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
522
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store;
522
    $dbitem->item->homebranch($dbitem->stage->branchcode_id)->store;
523
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store;
523
    $dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store;
524
    is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates.");
524
    is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates.");
525
525
526
    # Test item not at stagebranch with branchtransfer history ['repatriation']
526
    # Test item not at stagebranch with branchtransfer history ['repatriation']
Lines 536-543 subtest "Tests for investigate (singular)." => sub { Link Here
536
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
536
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
537
    my $dbtransfer = Koha::Item::Transfer->new({
537
    my $dbtransfer = Koha::Item::Transfer->new({
538
        'itemnumber'  => $dbitem->itemnumber_id,
538
        'itemnumber'  => $dbitem->itemnumber_id,
539
        'frombranch'  => $dbitem->itemnumber->homebranch,
539
        'frombranch'  => $dbitem->item->homebranch,
540
        'tobranch'    => $dbitem->itemnumber->homebranch,
540
        'tobranch'    => $dbitem->item->homebranch,
541
        'datesent'    => dt_from_string(),
541
        'datesent'    => dt_from_string(),
542
        'datearrived' => dt_from_string(),
542
        'datearrived' => dt_from_string(),
543
        'reason'      => "StockrotationAdvance",
543
        'reason'      => "StockrotationAdvance",
Lines 557-570 subtest "Tests for investigate (singular)." => sub { Link Here
557
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
557
    $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
558
    $dbtransfer = Koha::Item::Transfer->new({
558
    $dbtransfer = Koha::Item::Transfer->new({
559
        'itemnumber'  => $dbitem->itemnumber_id,
559
        'itemnumber'  => $dbitem->itemnumber_id,
560
        'frombranch'  => $dbitem->itemnumber->homebranch,
560
        'frombranch'  => $dbitem->item->homebranch,
561
        'tobranch'    => $dbitem->stage->branchcode_id,
561
        'tobranch'    => $dbitem->stage->branchcode_id,
562
        'datesent'    => dt_from_string(),
562
        'datesent'    => dt_from_string(),
563
        'datearrived' => dt_from_string(),
563
        'datearrived' => dt_from_string(),
564
        'reason'      => "StockrotationAdvance",
564
        'reason'      => "StockrotationAdvance",
565
    })->store;
565
    })->store;
566
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store;
566
    $dbitem->item->homebranch($dbitem->stage->branchcode_id)->store;
567
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store;
567
    $dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store;
568
    is($dbitem->investigate->{reason}, 'not-ready', "older item at stagebranch not-ready.");
568
    is($dbitem->investigate->{reason}, 'not-ready', "older item at stagebranch not-ready.");
569
569
570
    # Test item due for advancement ['advancement']
570
    # Test item due for advancement ['advancement']
Lines 584-597 subtest "Tests for investigate (singular)." => sub { Link Here
584
    my $arrived_duration =  DateTime::Duration->new( days => 52);
584
    my $arrived_duration =  DateTime::Duration->new( days => 52);
585
    $dbtransfer = Koha::Item::Transfer->new({
585
    $dbtransfer = Koha::Item::Transfer->new({
586
        'itemnumber'  => $dbitem->itemnumber_id,
586
        'itemnumber'  => $dbitem->itemnumber_id,
587
        'frombranch'  => $dbitem->itemnumber->homebranch,
587
        'frombranch'  => $dbitem->item->homebranch,
588
        'tobranch'    => $dbitem->stage->branchcode_id,
588
        'tobranch'    => $dbitem->stage->branchcode_id,
589
        'datesent'    => dt_from_string() - $sent_duration,
589
        'datesent'    => dt_from_string() - $sent_duration,
590
        'datearrived' => dt_from_string() - $arrived_duration,
590
        'datearrived' => dt_from_string() - $arrived_duration,
591
        'reason'      => "StockrotationAdvance",
591
        'reason'      => "StockrotationAdvance",
592
    })->store;
592
    })->store;
593
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store;
593
    $dbitem->item->homebranch($dbitem->stage->branchcode_id)->store;
594
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store;
594
    $dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store;
595
    is($dbitem->investigate->{reason}, 'advancement',
595
    is($dbitem->investigate->{reason}, 'advancement',
596
       "Item ready for advancement.");
596
       "Item ready for advancement.");
597
597
Lines 612-625 subtest "Tests for investigate (singular)." => sub { Link Here
612
    $arrived_duration =  DateTime::Duration->new( days => 52);
612
    $arrived_duration =  DateTime::Duration->new( days => 52);
613
    $dbtransfer = Koha::Item::Transfer->new({
613
    $dbtransfer = Koha::Item::Transfer->new({
614
        'itemnumber'  => $dbitem->itemnumber_id,
614
        'itemnumber'  => $dbitem->itemnumber_id,
615
        'frombranch'  => $dbitem->itemnumber->homebranch,
615
        'frombranch'  => $dbitem->item->homebranch,
616
        'tobranch'    => $dbitem->stage->branchcode_id,
616
        'tobranch'    => $dbitem->stage->branchcode_id,
617
        'datesent'    => dt_from_string() - $sent_duration,
617
        'datesent'    => dt_from_string() - $sent_duration,
618
        'datearrived' => dt_from_string() - $arrived_duration,
618
        'datearrived' => dt_from_string() - $arrived_duration,
619
        'reason'      => "StockrotationAdvance",
619
        'reason'      => "StockrotationAdvance",
620
    })->store;
620
    })->store;
621
    $dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store;
621
    $dbitem->item->homebranch($dbitem->stage->branchcode_id)->store;
622
    $dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store;
622
    $dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store;
623
    is($dbitem->investigate->{reason}, 'in-demand',
623
    is($dbitem->investigate->{reason}, 'in-demand',
624
       "Item advances, but in-demand.");
624
       "Item advances, but in-demand.");
625
625
Lines 640-646 subtest "Tests for investigate (singular)." => sub { Link Here
640
    $arrived_duration =  DateTime::Duration->new( days => 52);
640
    $arrived_duration =  DateTime::Duration->new( days => 52);
641
    $dbtransfer = Koha::Item::Transfer->new({
641
    $dbtransfer = Koha::Item::Transfer->new({
642
        'itemnumber'  => $dbitem->itemnumber_id,
642
        'itemnumber'  => $dbitem->itemnumber_id,
643
        'frombranch'  => $dbitem->itemnumber->homebranch,
643
        'frombranch'  => $dbitem->item->homebranch,
644
        'tobranch'    => $dbitem->stage->branchcode_id,
644
        'tobranch'    => $dbitem->stage->branchcode_id,
645
        'datesent'    => dt_from_string() - $sent_duration,
645
        'datesent'    => dt_from_string() - $sent_duration,
646
        'datearrived' => dt_from_string() - $arrived_duration,
646
        'datearrived' => dt_from_string() - $arrived_duration,
Lines 662-673 subtest "Tests for toggle_indemand" => sub { Link Here
662
    });
662
    });
663
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
663
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
664
    my $firstbranch = $dbitem->stage->branchcode_id;
664
    my $firstbranch = $dbitem->stage->branchcode_id;
665
    $dbitem->itemnumber->holdingbranch($firstbranch)->store;
665
    $dbitem->item->holdingbranch($firstbranch)->store;
666
    my $dbstage = $dbitem->stage;
666
    my $dbstage = $dbitem->stage;
667
    $dbstage->position(1)->duration(50)->store; # Configure stage.
667
    $dbstage->position(1)->duration(50)->store; # Configure stage.
668
    # Configure item
668
    # Configure item
669
    $dbitem->itemnumber->holdingbranch($firstbranch)->store;
669
    $dbitem->item->holdingbranch($firstbranch)->store;
670
    $dbitem->itemnumber->homebranch($firstbranch)->store;
670
    $dbitem->item->homebranch($firstbranch)->store;
671
    # Sanity check
671
    # Sanity check
672
    is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check.");
672
    is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check.");
673
673
Lines 691-697 subtest "Tests for toggle_indemand" => sub { Link Here
691
    # Test an item in transfer, toggle cancels transfer and resets indemand.
691
    # Test an item in transfer, toggle cancels transfer and resets indemand.
692
    ok($dbitem->advance, "Advancement done.");
692
    ok($dbitem->advance, "Advancement done.");
693
    $dbitem->get_from_storage;
693
    $dbitem->get_from_storage;
694
    my $transfer = $dbitem->itemnumber->get_transfer;
694
    my $transfer = $dbitem->item->get_transfer;
695
    is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected');
695
    is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected');
696
    is($transfer->frombranch, $firstbranch, 'Transfer from set correctly');
696
    is($transfer->frombranch, $firstbranch, 'Transfer from set correctly');
697
    is($transfer->tobranch, $secondbranch, 'Transfer to set correctly');
697
    is($transfer->tobranch, $secondbranch, 'Transfer to set correctly');
Lines 703-709 subtest "Tests for toggle_indemand" => sub { Link Here
703
    isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected');
703
    isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected');
704
    is($dbitem->indemand, 0, "Item retains indemand as expected.");
704
    is($dbitem->indemand, 0, "Item retains indemand as expected.");
705
    is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.');
705
    is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.');
706
    is($dbitem->itemnumber->homebranch, $firstbranch, 'Item homebranch reset as expected.');
706
    is($dbitem->item->homebranch, $firstbranch, 'Item homebranch reset as expected.');
707
707
708
    $schema->storage->txn_rollback;
708
    $schema->storage->txn_rollback;
709
};
709
};
710
- 

Return to bug 29809