Bug 13321: Rename variables
[koha.git] / t / db_dependent / Acquisition / CancelReceipt.t
blob9f7ad1923186d2a0a8ef180f410cbea8e3d66ad9
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use Test::More tests => 12;
6 use C4::Context;
7 use C4::Acquisition;
8 use C4::Biblio;
9 use C4::Items;
10 use C4::Bookseller;
11 use C4::Budgets;
12 use t::lib::Mocks;
14 use Koha::Database;
15 use Koha::DateUtils;
16 use Koha::Acquisition::Order;
17 use MARC::Record;
19 my $schema = Koha::Database->new()->schema();
20 $schema->storage->txn_begin();
21 my $dbh = C4::Context->dbh;
22 $dbh->{RaiseError} = 1;
24 my $booksellerid1 = C4::Bookseller::AddBookseller(
26 name => "my vendor 1",
27 address1 => "bookseller's address",
28 phone => "0123456",
29 active => 1
33 my $basketno1 = C4::Acquisition::NewBasket(
34 $booksellerid1
37 my $budgetid = C4::Budgets::AddBudget(
39 budget_code => "budget_code_test_transferorder",
40 budget_name => "budget_name_test_transferorder",
44 my $budget = C4::Budgets::GetBudget( $budgetid );
46 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
47 my $itemnumber = AddItem({}, $biblionumber);
49 t::lib::Mocks::mock_preference('AcqCreateItem', 'receiving');
50 my $order = Koha::Acquisition::Order->new(
52 basketno => $basketno1,
53 quantity => 2,
54 biblionumber => $biblionumber,
55 budget_id => $budget->{budget_id},
57 )->insert;
58 my $ordernumber = $order->{ordernumber};
60 ModReceiveOrder(
62 biblionumber => $biblionumber,
63 order => $order,
64 quantityreceived => 2,
68 $order->add_item( $itemnumber );
70 CancelReceipt($ordernumber);
72 is(scalar GetItemnumbersFromOrder($ordernumber), 0, "Create items on receiving: 0 item exist after cancelling a receipt");
74 my $itemnumber1 = AddItem({}, $biblionumber);
75 my $itemnumber2 = AddItem({}, $biblionumber);
76 t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering');
77 t::lib::Mocks::mock_preference('AcqItemSetSubfieldsWhenReceiptIsCancelled', '7=9'); # notforloan is mapped with 952$7
78 $order = Koha::Acquisition::Order->new(
80 basketno => $basketno1,
81 quantity => 2,
82 biblionumber => $biblionumber,
83 budget_id => $budget->{budget_id},
85 )->insert;
86 $ordernumber = $order->{ordernumber};
88 is( $order->{parent_ordernumber}, $order->{ordernumber},
89 "Insert an order should set parent_order=ordernumber, if no parent_ordernumber given"
92 $order->add_item( $itemnumber1 );
93 $order->add_item( $itemnumber2 );
95 is(
96 scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ),
98 "Create items on ordering: 2 items should be linked to the order before receiving"
101 my ( undef, $new_ordernumber ) = ModReceiveOrder(
103 biblionumber => $biblionumber,
104 order => $order,
105 quantityreceived => 1,
106 received_items => [ $itemnumber1 ],
110 my $new_order = GetOrder( $new_ordernumber );
112 is( $new_order->{ordernumber}, $new_ordernumber,
113 "ModReceiveOrder should return a correct ordernumber" );
114 isnt( $new_ordernumber, $ordernumber,
115 "ModReceiveOrder should return a different ordernumber" );
116 is( $new_order->{parent_ordernumber}, $ordernumber,
117 "The new order created by ModReceiveOrder should be linked to the parent order"
121 scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ),
123 "Create items on ordering: 1 item should still be linked to the original order after receiving"
126 scalar( GetItemnumbersFromOrder($new_ordernumber) ),
128 "Create items on ordering: 1 item should be linked to new order after receiving"
131 CancelReceipt($new_ordernumber);
134 scalar( GetItemnumbersFromOrder($new_ordernumber) ),
136 "Create items on ordering: no item should be linked to the cancelled order"
139 scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ),
141 "Create items on ordering: items are not deleted after cancelling a receipt"
144 my $item1 = C4::Items::GetItem( $itemnumber1 );
145 is( $item1->{notforloan}, 9, "The notforloan value has been updated with '9'" );
147 my $item2 = C4::Items::GetItem( $itemnumber2 );
148 is( $item2->{notforloan}, 0, "The notforloan value has been updated with '9'" );
150 $schema->storage->txn_rollback();