Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
|
24 |
|
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
Lines 158-160
subtest 'filter_by_id_including_transfers() tests' => sub {
Link Here
|
158 |
|
158 |
|
159 |
$schema->storage->txn_rollback; |
159 |
$schema->storage->txn_rollback; |
160 |
}; |
160 |
}; |
161 |
- |
161 |
|
|
|
162 |
subtest 'filter_by_obsolete and cancel' => sub { |
163 |
plan tests => 11; |
164 |
$schema->storage->txn_begin; |
165 |
|
166 |
my $order_1 = $builder->build_object( { class => 'Koha::Acquisition::Orders' } ); |
167 |
my $order_2 = $builder->build_object( { class => 'Koha::Acquisition::Orders' } ); |
168 |
my $order_3 = $builder->build_object( { class => 'Koha::Acquisition::Orders' } ); |
169 |
|
170 |
# First make order 1 obsolete by removing biblio, and order 3 by status problem. |
171 |
my $date = Koha::DateUtils::dt_from_string->subtract( days => 7 ); |
172 |
$order_1->orderstatus('ordered')->quantity(2)->quantityreceived(0)->datecancellationprinted(undef) |
173 |
->entrydate($date)->store; |
174 |
Koha::Biblios->find( $order_1->biblionumber )->delete; |
175 |
$order_1->discard_changes; |
176 |
$order_2->orderstatus('ordered')->quantity(3)->quantityreceived(0)->datecancellationprinted(undef)->store; |
177 |
$order_3->orderstatus('cancelled')->datecancellationprinted(undef)->store; |
178 |
|
179 |
my $limit = { ordernumber => { '>=', $order_1->ordernumber } }; |
180 |
my $rs = Koha::Acquisition::Orders->filter_by_obsolete->search($limit); |
181 |
is( $rs->count, 2, 'Two obsolete' ); |
182 |
is( $rs->search( { ordernumber => $order_1->ordernumber } )->count, 1, 'Including order_1' ); |
183 |
is( $rs->search( { ordernumber => $order_2->ordernumber } )->count, 0, 'Excluding order_2' ); |
184 |
|
185 |
# Test param age |
186 |
$rs = Koha::Acquisition::Orders->filter_by_obsolete( { age => 6 } )->search($limit); |
187 |
is( $rs->count, 1, 'Age 6: Including order_1' ); |
188 |
$rs = Koha::Acquisition::Orders->filter_by_obsolete( { age => 7 } )->search($limit); |
189 |
is( $rs->count, 0, 'Age 7: Excluding order_1' ); |
190 |
|
191 |
# Make order 2 obsolete too |
192 |
Koha::Biblios->find( $order_2->biblionumber )->delete; |
193 |
$order_2->discard_changes; |
194 |
|
195 |
# Use the plural cancel method |
196 |
$rs = Koha::Acquisition::Orders->filter_by_obsolete->search($limit); |
197 |
is( $rs->count, 3, 'Three obsolete' ); |
198 |
my @results = $rs->cancel; |
199 |
is( $results[0], 3, 'All should be cancelled' ); |
200 |
is( @{ $results[1] }, 0, 'No messages' ); |
201 |
is( $order_1->discard_changes->orderstatus, 'cancelled', 'Check orderstatus of order_1' ); |
202 |
isnt( $order_2->discard_changes->datecancellationprinted, undef, 'Cancellation date of order_2 filled' ); |
203 |
isnt( $order_3->discard_changes->datecancellationprinted, undef, 'Cancellation date of order_3 filled' ); |
204 |
|
205 |
$schema->storage->txn_rollback; |
206 |
}; |