5 use Test
::More tests
=> 13;
12 use Koha
::Acquisition
::Order
;
14 use t
::lib
::TestBuilder
;
16 my $schema = Koha
::Database
->schema;
17 $schema->storage->txn_begin;
18 my $builder = t
::lib
::TestBuilder
->new;
20 # Set up configuration data
22 my $branch = $builder->build( { source
=> 'Branch' } );
23 my $bookseller = $builder->build( { source
=> 'Aqbookseller' } );
24 my $budget = $builder->build( { source
=> 'Aqbudget' } );
25 my $staffmember = $builder->build( { source
=> 'Borrower' } );
27 # Create baskets and orders
29 my $basketno = NewBasket
(
31 $staffmember->{borrowernumber
},
32 'Standing order basket', # basketname
34 '', # basketbooksellernote
35 undef, # basketcontractnumber
36 $branch->{branchcode
}, # deliveryplace
37 $branch->{branchcode
}, # billingplace
41 my $nonstandingbasketno = NewBasket
(
43 $staffmember->{borrowernumber
},
44 'Non-standing order basket', # basketname
46 '', # basketbooksellernote
47 undef, # basketcontractnumber
48 $branch->{branchcode
}, # deliveryplace
49 $branch->{branchcode
}, # billingplace
53 my $basket = GetBasket
($basketno);
55 is
( $basket->{is_standing
}, 1, 'basket correctly created as standing order basket' );
57 my ( $biblionumber, $biblioitemnumber ) = C4
::Biblio
::AddBiblio
( MARC
::Record
->new, '' );
60 my $ordernumber = Koha
::Acquisition
::Order
->new(
62 basketno
=> $basketno,
63 biblionumber
=> $biblionumber,
64 budget_id
=> $budget->{budget_id
},
68 rrp_tax_included
=> 42,
69 rrp_tax_excluded
=> 42,
71 ecost_tax_included
=> 22,
72 ecost_tax_excluded
=> 22,
74 unitprice_tax_included
=> 12,
75 unitprice_tax_excluded
=> 12,
77 tax_rate_on_ordering
=> 0,
78 tax_rate_on_receiving
=> 0,
80 )->insert->{ordernumber
};
82 isnt
( $ordernumber, undef, 'standing order successfully created' );
84 my $search_orders = SearchOrders
( {
85 basketno
=> $basketno,
91 scalar @
$search_orders == 1 && $search_orders->[0]->{ordernumber
} == $ordernumber,
92 'standing order counts as a pending/ordered order'
95 my $invoiceid = AddInvoice
(
96 invoicenumber
=> 'invoice',
97 booksellerid
=> $bookseller->{id
},
101 my $order = Koha
::Acquisition
::Order
->fetch( { ordernumber
=> $ordernumber } );
103 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder
(
105 biblionumber
=> $biblionumber,
107 quantityreceived
=> 2,
108 invoiceid
=> $invoiceid,
112 isnt
( $ordernumber, $new_ordernumber, "standing order split on receive" );
114 #order has been updated, refetch
115 $order = Koha
::Acquisition
::Order
->fetch( { ordernumber
=> $ordernumber } );
116 my $neworder = Koha
::Acquisition
::Order
->fetch( { ordernumber
=> $new_ordernumber } );
118 is
( $order->{orderstatus
}, 'partial', 'original order set to partially received' );
119 is
( $order->{quantity
}, 1, 'original order quantity unchanged' );
120 is
( $order->{quantityreceived
}, 0, 'original order has no received items' );
121 isnt
( $order->{unitprice
}, 12, 'original order does not get cost' );
122 is
( $neworder->{orderstatus
}, 'complete', 'new order set to complete' );
123 is
( $neworder->{quantityreceived
}, 2, 'new order has received items' );
124 cmp_ok
( $neworder->{unitprice
}, '==', 12, 'new order does get cost' );
126 $search_orders = SearchOrders
( {
127 basketno
=> $basketno,
132 is
( scalar @
$search_orders, 1, 'only one pending order after receive' );
133 is
( $search_orders->[0]->{ordernumber
}, $ordernumber, 'original order is only pending order' );
135 $schema->storage->txn_rollback();