X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=t%2Fdb_dependent%2FAcquisition%2FOrderFromSubscription.t;h=d9db71c18039319d14c90112765624c4ddeef73c;hb=9d6d641d1f8b77271800f43bc027b651f9aea52b;hp=91691a7d73aed9a1a7d0faf621be6745c0169ad7;hpb=fc395b5f8cb5b7d151cbdbabc360643a5daa205d;p=srvgit diff --git a/t/db_dependent/Acquisition/OrderFromSubscription.t b/t/db_dependent/Acquisition/OrderFromSubscription.t old mode 100644 new mode 100755 index 91691a7d73..d9db71c180 --- a/t/db_dependent/Acquisition/OrderFromSubscription.t +++ b/t/db_dependent/Acquisition/OrderFromSubscription.t @@ -1,36 +1,38 @@ use Modern::Perl; -use Test::More tests => 13; +use Test::More tests => 12; -use_ok('C4::Acquisition'); -use_ok('C4::Biblio'); -use_ok('C4::Bookseller'); -use_ok('C4::Budgets'); -use_ok('C4::Serials'); +use t::lib::TestBuilder; -use Koha::Acquisition::Order; +use_ok('C4::Acquisition', qw( NewBasket AddInvoice GetInvoice ModReceiveOrder GetInvoices )); +use_ok('C4::Biblio', qw( AddBiblio )); +use_ok('C4::Budgets', qw( AddBudgetPeriod AddBudget )); +use_ok('C4::Serials', qw( NewSubscription GetSubscription subscriptionCurrentlyOnOrder )); + +use Koha::Acquisition::Orders; use Koha::Database; # Start transaction my $schema = Koha::Database->new()->schema(); $schema->storage->txn_begin(); +my $builder = t::lib::TestBuilder->new; my $dbh = C4::Context->dbh; -$dbh->{RaiseError} = 1; -my $booksellerid = C4::Bookseller::AddBookseller( +my $curcode = $builder->build({ source => 'Currency' })->{currencycode}; + +my $bookseller = Koha::Acquisition::Bookseller->new( { name => "my vendor", address1 => "bookseller's address", phone => "0123456", active => 1 } -); +)->store; my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); -my $budgetid; my $bpid = AddBudgetPeriod({ - budget_period_startdate => '01-01-2015', - budget_period_enddate => '12-31-2015', + budget_period_startdate => '2015-01-01', + budget_period_enddate => '2015-12-31', budget_period_description => "budget desc" }); @@ -44,66 +46,73 @@ my $budget_id = AddBudget({ my $subscriptionid = NewSubscription( undef, "", undef, undef, $budget_id, $biblionumber, - '01-01-2013',undef, undef, undef, undef, + '2013-01-01',undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, - 1, "notes",undef, '01-01-2013', undef, undef, + 1, "notes",undef, '2013-01-01', undef, undef, undef, undef, 0, "intnotes", 0, - undef, undef, 0, undef, '31-12-2013', 0 + undef, undef, 0, undef, '2013-12-31', 0 ); die unless $subscriptionid; -my ($basket, $basketno); -ok($basketno = NewBasket($booksellerid, 1), "NewBasket( $booksellerid , 1 ) returns $basketno"); +my $basketno; +ok($basketno = NewBasket($bookseller->id, 1), "NewBasket( " . $bookseller->id . ", 1 ) returns $basketno"); my $cost = 42.00; my $subscription = GetSubscription( $subscriptionid ); my $order = Koha::Acquisition::Order->new({ biblionumber => $subscription->{biblionumber}, - entrydate => '01-01-2013', + entrydate => '2013-01-01', quantity => 1, - currency => 'USD', + currency => $curcode, listprice => $cost, - notes => "This is a note", basketno => $basketno, rrp => $cost, ecost => $cost, - gstrate => 0.0500, orderstatus => 'new', subscriptionid => $subscription->{subscriptionid}, budget_id => $budget_id, -})->insert; -my $ordernumber = $order->{ordernumber}; +})->store; +my $ordernumber = $order->ordernumber; my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} ); is ( $is_currently_on_order, 1, "The subscription is currently on order"); -$order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} ); +$order = Koha::Acquisition::Orders->search({ subscriptionid => $subscription->{subscriptionid}, datereceived => undef })->next->unblessed; is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received"); ok( $order->{ecost} == $cost, "test cost for the last order not received"); $dbh->do(q{DELETE FROM aqinvoices}); -my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown"); +my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $bookseller->id, unknown => "unknown"); + +my $invoice = GetInvoice( $invoiceid ); +$invoice->{datereceived} = '2013-01-02'; my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber, - ordernumber => $ordernumber, + order => $order, quantityreceived => 1, - cost => $cost, - ecost => $cost, - rrp => $cost, budget_id => $budget_id, - invoiceid => $invoiceid, + invoice => $invoice, } ); -$order = GetLastOrderReceivedFromSubscriptionid( $subscription->{subscriptionid} ); +$order = Koha::Acquisition::Orders->search( + { + subscriptionid => $subscriptionid, + datereceived => { '!=' => undef } + }, + { + order_by => [ { -desc => 'datereceived' }, { -desc => 'ordernumber' } ] + } +)->next->unblessed; + is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received"); ok( $order->{ecost} == $cost, "test cost for the last order received"); -$order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} ); -is ( $order, undef, "test no not received order for a received order"); +$order = Koha::Acquisition::Orders->search({ subscriptionid => $subscription->{subscriptionid}, datereceived => undef }); +is ( $order->count, 0, "test no not received order for a received order"); my @invoices = GetInvoices(); my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;