2 use strict; use warnings;
3 use Test::More tests => 11;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Utils::CStoreEditor qw/:funcs/;
6 use OpenILS::Application::Acq::Order;
8 diag("Tests ACQ purchase orders");
10 my $script = OpenILS::Utils::TestUtils->new();
13 $script->authenticate({
15 password => 'demo123',
19 my $e = $script->editor(authtoken=>$script->authtoken);
22 ok($script->authtoken, 'Have an authtoken');
24 my $conn; # dummy for now
25 my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn);
27 my $origpo = $e->retrieve_acq_purchase_order(2);
28 is($origpo->state, 'on-order', 'order starts at expected state') or
29 BAIL_OUT('order 2 does not have expected state');
31 my $origli3 = $e->retrieve_acq_lineitem(3);
32 my $origli4 = $e->retrieve_acq_lineitem(4);
33 my $origli5 = $e->retrieve_acq_lineitem(5);
35 is($origli3->state, 'on-order', 'line item 3 starts at expected state') or
36 BAIL_OUT('line item 3 does not have expected state');
37 is($origli4->state, 'cancelled', 'line item 4 starts at expected state') or
38 BAIL_OUT('line item 4 does not have expected state');
39 is($origli5->state, 'cancelled', 'line item 5 starts at expected state') or
40 BAIL_OUT('line item 5 does not have expected state');
41 is($origli4->cancel_reason, 1283, 'line item 4 starts at expected cancel_reason') or
42 BAIL_OUT('line item 4 does not have expected cancel_reason');
43 is($origli5->cancel_reason, 1, 'line item 5 starts at expected cancel_reason') or
44 BAIL_OUT('line item 5 does not have expected cancel_reason');
46 my $ret = OpenILS::Application::Acq::Order::check_purchase_order_received($mgr, 2);
47 is($ret->state, 'on-order', 'order cannot be received (yet)');
49 OpenILS::Application::Acq::Order::receive_lineitem($mgr, 3, 1);
50 my $li = $e->retrieve_acq_lineitem(3);
51 is($li->state, 'received', 'line item 3 received');
53 $ret = OpenILS::Application::Acq::Order::check_purchase_order_received($mgr, 2);
54 is($ret->state, 'on-order', 'order still cannot be received');
56 $li = $e->retrieve_acq_lineitem(4);
57 $li->cancel_reason(2); # this one has keep_debits = false, i.e., we don't expect
58 # this one to ever show up
59 $e->update_acq_lineitem($li);
61 $ret = OpenILS::Application::Acq::Order::check_purchase_order_received($mgr, 2);
62 is($ret->state, 'received', 'LP#1257915: order now received');