From dc5c361696c29e979ddd0e410145515401399280 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 Sep 2017 10:15:59 -0300 Subject: [PATCH] Bug 19256: Make Koha::Acq::Order using Koha::Object At the moment we have 2 different modules for acquisition orders: Koha::Tmp::Order[s] and Koha::Acquisition::Order The later has been added before the creation of Koha::Object. Koha::Tmp::Order[s] has been created to make the TT syntax for notices works with acquisition order data. This patch removes the temporary packages Koha::Tmp::Order[s] and adapt the code of Koha::Acquisition::Order[s] to be based on Koha::Object[s]. It also overloads Koha::Object->new to add the trick that was done in Koha::Acquisition::Order->insert. This is needed because acqui/addorder.pl is called from several places and CGI->Vars is used to retrieved order's attributes (and so much more). To avoid regression, the easiest (but not cleanest) way to do is to filter on aqorders column's names. This is *not* a pattern to follow! Test plan: Create basket and add orders from different ways, then continue a whole acquisition process Signed-off-by: Kyle M Hall --- C4/Acquisition.pm | 13 ++- C4/Letters.pm | 2 +- Koha/Acquisition/Order.pm | 114 +++++++++++---------- Koha/{Tmp => Acquisition}/Orders.pm | 8 +- Koha/Tmp/Order.pm | 44 -------- acqui/addorder.pl | 5 +- acqui/addorderiso2709.pl | 6 +- acqui/finishreceive.pl | 5 +- admin/currency.pl | 6 +- t/db_dependent/Acquisition.t | 18 ++-- t/db_dependent/Acquisition/CancelReceipt.t | 22 ++-- t/db_dependent/Acquisition/GetBasketAsCSV.t | 6 +- .../Acquisition/GetBasketsInfosByBookseller.t | 10 +- .../Acquisition/GetOrdersByBiblionumber.t | 14 +-- t/db_dependent/Acquisition/Invoices.t | 20 ++-- t/db_dependent/Acquisition/NewOrder.t | 16 +-- t/db_dependent/Acquisition/OrderFromSubscription.t | 8 +- t/db_dependent/Acquisition/OrderUsers.t | 15 ++- t/db_dependent/Acquisition/StandingOrders.t | 29 +++--- t/db_dependent/Acquisition/TransferOrder.t | 8 +- t/db_dependent/Acquisition/close_reopen_basket.t | 12 +-- t/db_dependent/Bookseller.t | 18 ++-- t/db_dependent/Budgets.t | 12 +-- t/db_dependent/Letters.t | 6 +- t/db_dependent/UsageStats.t | 2 +- 25 files changed, 187 insertions(+), 232 deletions(-) rename Koha/{Tmp => Acquisition}/Orders.pm (85%) delete mode 100644 Koha/Tmp/Order.pm diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index d0381ce..7639fef 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -28,8 +28,8 @@ use C4::Contract; use C4::Debug; use C4::Templates qw(gettemplate); use Koha::DateUtils qw( dt_from_string output_pref ); -use Koha::Acquisition::Order; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; use Koha::Biblios; use Koha::Items; use Koha::Number::Price; @@ -1485,7 +1485,7 @@ sub ModReceiveOrder { $order->{datereceived} = $datereceived; $order->{invoiceid} = $invoice->{invoiceid}; $order->{orderstatus} = 'complete'; - $new_ordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber}; + $new_ordernumber = Koha::Acquisition::Order->new($order)->store->ordernumber; # TODO What if the store fails? if ($received_items) { foreach my $itemnumber (@$received_items) { @@ -1951,8 +1951,11 @@ sub TransferOrder { return unless ($ordernumber and $basketno); - my $order = GetOrder( $ordernumber ); - return if $order->{datereceived}; + my $order = Koha::Acquisition::Orders->find( $ordernumber ) or return; + return if $order->datereceived; + + $order = $order->unblessed; + my $basket = GetBasket($basketno); return unless $basket; @@ -1971,7 +1974,7 @@ sub TransferOrder { delete $order->{parent_ordernumber}; $order->{'basketno'} = $basketno; - my $newordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber}; + my $newordernumber = Koha::Acquisition::Order->new($order)->store->ordernumber; $query = q{ UPDATE aqorders_items diff --git a/C4/Letters.pm b/C4/Letters.pm index 8c6fe85..759594e 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1525,7 +1525,7 @@ sub _get_tt_params { pk => 'idnew', }, aqorders => { - module => 'Koha::Tmp::Orders', # Should Koha::Acquisition::Orders when will be based on Koha::Objects + module => 'Koha::Acquisition::Orders', singular => 'order', plural => 'orders', pk => 'ordernumber', diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index ede8ddf..290ed03 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -1,95 +1,99 @@ package Koha::Acquisition::Order; +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + use Modern::Perl; +use Carp qw( croak ); + use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); -use Carp qw( croak ); +use base qw(Koha::Object); -use base qw( Class::Accessor ); +=head1 NAME -# TODO fetch order from itemnumber (GetOrderFromItemnnumber) -# TODO Move code from GetOrder -sub fetch { - my ( $class, $params ) = @_; - my $ordernumber = $params->{ordernumber}; - return unless $ordernumber; - my $schema = Koha::Database->new->schema; +Koha::Acquisition::Order Object class + +=head1 API + +=head2 Class Methods - my $order = - $schema->resultset('Aqorder')->find( { ordernumber => $ordernumber }, - { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ); - return $class->new( $order ); +=cut + +sub new { + my ( $self, $params ) = @_; + + my $schema = Koha::Database->new->schema; + my @columns = $schema->source('Aqorder')->columns; + + my $values = + { map { exists $params->{$_} ? ( $_ => $params->{$_} ) : () } @columns }; + return $self->SUPER::new($values); } -sub insert { +sub store { my ($self) = @_; my $schema = Koha::Database->new->schema; # Override quantity for standing orders - $self->{quantity} = 1 if ( $self->{basketno} && $schema->resultset('Aqbasket')->find( $self->{basketno} )->is_standing ); + $self->quantity(1) if ( $self->basketno && $schema->resultset('Aqbasket')->find( $self->basketno )->is_standing ); # if these parameters are missing, we can't continue for my $key (qw( basketno quantity biblionumber budget_id )) { croak "Cannot insert order: Mandatory parameter $key is missing" - unless $self->{$key}; + unless $self->$key; } - $self->{quantityreceived} ||= 0; - $self->{entrydate} ||= - output_pref( { dt => dt_from_string, dateformat => 'iso' } ); - - my @columns = $schema->source('Aqorder')->columns; - - $self->{ordernumber} ||= undef; + $self->quantityreceived(0) unless $self->quantityreceived; + $self->entrydate(output_pref( { dt => dt_from_string, dateformat => 'iso' } )) unless $self->entrydate; - my $rs = $schema->resultset('Aqorder')->create( - { - map { - exists $self->{$_} ? ( $_ => $self->{$_} ) : () - } @columns - } - ); - $self->{ordernumber} = $rs->id; + $self->ordernumber(undef) unless $self->ordernumber; + $self = $self->SUPER::store( $self ); - unless ( $self->{parent_ordernumber} ) { - $self->{parent_ordernumber} = $self->{ordernumber}; - $rs->update( { parent_ordernumber => $self->{parent_ordernumber} } ); + unless ( $self->parent_ordernumber ) { + $self->set( { parent_ordernumber => $self->ordernumber } ); + $self = $self->SUPER::store( $self ); } return $self; } +=head3 add_item + + $order->add_item( $itemnumber ); + +Link an item to this order. + +=cut + sub add_item { my ( $self, $itemnumber ) = @_; + my $schema = Koha::Database->new->schema; my $rs = $schema->resultset('AqordersItem'); - $rs->create({ ordernumber => $self->{ordernumber}, itemnumber => $itemnumber }); + $rs->create({ ordernumber => $self->ordernumber, itemnumber => $itemnumber }); } -# TODO Move code from ModItemOrder -sub update_item { - die "not implemented yet"; -} - -sub del_item { - die "not implemented yet"; -} +=head3 _type -# TODO Move code from ModOrder -sub update { - die "not implemented yet"; -} - -# TODO Move code from DelOrder -sub delete { - die "not implemented yet"; -} +=cut -# TODO Move code from TransferOrder -sub transfer { - die "not implemented yet"; +sub _type { + return 'Aqorder'; } 1; diff --git a/Koha/Tmp/Orders.pm b/Koha/Acquisition/Orders.pm similarity index 85% rename from Koha/Tmp/Orders.pm rename to Koha/Acquisition/Orders.pm index 4d56dc1..1302200 100644 --- a/Koha/Tmp/Orders.pm +++ b/Koha/Acquisition/Orders.pm @@ -1,4 +1,4 @@ -package Koha::Tmp::Orders; +package Koha::Acquisition::Orders; # This file is part of Koha. # @@ -21,13 +21,13 @@ use Carp; use Koha::Database; -use Koha::Tmp::Order; +use Koha::Acquisition::Order; use base qw(Koha::Objects); =head1 NAME -Koha::Tmp::Orders - This is a temporary class to make notices working with orders +Koha::Acquisition::Orders object set class =head1 API @@ -44,7 +44,7 @@ sub _type { } sub object_class { - return 'Koha::Tmp::Order'; + return 'Koha::Acquisition::Order'; } 1; diff --git a/Koha/Tmp/Order.pm b/Koha/Tmp/Order.pm deleted file mode 100644 index 2e5be43..0000000 --- a/Koha/Tmp/Order.pm +++ /dev/null @@ -1,44 +0,0 @@ -package Koha::Tmp::Order; - -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -use Modern::Perl; - -use Carp; - -use Koha::Database; - -use base qw(Koha::Object); - -=head1 NAME - -Koha::Tmp::Order - This is a temporary class to make notices working with orders - -=head1 API - -=head2 Class Methods - -=cut - -=head3 type - -=cut - -sub _type { - return 'Aqorder'; -} - -1; diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 81064ff..d3d2c9f 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -130,6 +130,7 @@ use C4::Budgets; use C4::Items; use C4::Output; use Koha::Acquisition::Currencies; +use Koha::Acquisition::Orders; use C4::Barcodes; ### "-------------------- addorder.pl ----------" @@ -224,7 +225,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); # get CGI parameters -my $orderinfo = $input->Vars; +my $orderinfo = $input->Vars; $orderinfo->{'list_price'} ||= 0; $orderinfo->{'uncertainprice'} ||= 0; $orderinfo->{subscriptionid} ||= undef; @@ -286,7 +287,7 @@ if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { ModOrderUsers( $orderinfo->{ordernumber}, @order_users ); } else { # else, it's a new line - $order->insert; + $order->store; } # now, add items if applicable diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 1469817..1aeaf3c 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -45,7 +45,7 @@ use C4::Members; use Koha::Number::Price; use Koha::Libraries; use Koha::Acquisition::Currencies; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use Koha::Acquisition::Booksellers; use Koha::Patrons; @@ -305,7 +305,7 @@ if ($op eq ""){ ) }; - my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert; + my $order = Koha::Acquisition::Order->new( \%orderinfo )->store; $order->add_item( $_ ) for @itemnumbers; } } @@ -375,7 +375,7 @@ if ($op eq ""){ ) }; - my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert; + my $order = Koha::Acquisition::Order->new( \%orderinfo )->store; # 4th, add items if applicable # parse the item sent by the form, and create an item just for the import_record_id we are dealing with diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index 71a07f6..b8854a6 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -33,6 +33,7 @@ use C4::Search; use Koha::Number::Price; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; use List::MoreUtils qw/any/; @@ -134,7 +135,7 @@ if ($quantityrec > $origquantityrec ) { push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i]; push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i]; } - my $order = Koha::Acquisition::Order->fetch({ ordernumber => $new_ordernumber }); + my $new_order = Koha::Acquisition::Orders->find( $new_ordernumber ); foreach my $item (keys %itemhash){ my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'}, $itemhash{$item}->{'subfields'}, @@ -144,7 +145,7 @@ if ($quantityrec > $origquantityrec ) { 'ITEM' ); my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber); - $order->add_item( $itemnumber ); + $new_order->add_item( $itemnumber ); } } } diff --git a/admin/currency.pl b/admin/currency.pl index 1c5ec3e..1719498 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -26,8 +26,8 @@ use C4::Context; use C4::Output; use Koha::Acquisition::Booksellers; -use Koha::Acquisition::Currency; use Koha::Acquisition::Currencies; +use Koha::Acquisition::Orders; my $input = CGI->new; my $searchfield = $input->param('searchfield') || $input->param('description') || q{}; @@ -92,9 +92,7 @@ if ( $op eq 'add_form' ) { } elsif ( $op eq 'delete_confirm' ) { my $currency = Koha::Acquisition::Currencies->find($currency_code); - # TODO rewrite the following when Koha::Acquisition::Orders will use Koha::Objects - my $schema = Koha::Database->schema; - my $nb_of_orders = $schema->resultset('Aqorder')->search( { currency => $currency->currency } )->count; + my $nb_of_orders = Koha::Acquisition::Orders->search( { currency => $currency->currency } )->count; my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } })->count; $template->param( currency => $currency, diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 646dd78..d6b922d 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -26,7 +26,7 @@ BEGIN { use_ok('C4::Acquisition'); use_ok('C4::Biblio'); use_ok('C4::Budgets'); - use_ok('Koha::Acquisition::Order'); + use_ok('Koha::Acquisition::Orders'); use_ok('Koha::Acquisition::Booksellers'); } @@ -188,7 +188,6 @@ my @order_content = ( ecost => 38.15, rrp => 40.15, discount => 5.1111, - tax_rate => 0.0515 } }, { @@ -216,7 +215,6 @@ my @order_content = ( ecost => 38.1, rrp => 11.0, discount => 5.1, - tax_rate => 0.1 } }, { @@ -236,7 +234,6 @@ my @order_content = ( rrp => 11.00, discount => 0, uncertainprice => 0, - tax_rate => 0 } }, { @@ -256,7 +253,6 @@ my @order_content = ( rrp => 10, discount => 0, uncertainprice => 0, - tax_rate => 0 } }, { @@ -276,7 +272,6 @@ my @order_content = ( rrp => 10, discount => 0, uncertainprice => 0, - tax_rate => 0 } } ); @@ -288,7 +283,8 @@ for ( 0 .. 5 ) { values %{ $order_content[$_]->{num} }; @ocontent{ keys %{ $order_content[$_]->{str} } } = values %{ $order_content[$_]->{str} }; - $ordernumbers[$_] = Koha::Acquisition::Order->new( \%ocontent )->insert->{ordernumber}; + use Data::Printer colored => 1; warn p %ocontent; + $ordernumbers[$_] = Koha::Acquisition::Order->new( \%ocontent )->store->ordernumber; $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_]; } @@ -305,7 +301,7 @@ my $invoice = GetInvoice( $invoiceid ); my ($datereceived, $new_ordernumber) = ModReceiveOrder( { biblionumber => $biblionumber4, - order => GetOrder( $ordernumbers[4] ), + order => Koha::Acquisition::Orders->find( $ordernumbers[4] )->unblessed, quantityreceived => 1, invoice => $invoice, budget_id => $order_content[4]->{str}->{budget_id}, @@ -404,7 +400,7 @@ is( "AddClaim : Check claimed_date" ); -my $order2 = GetOrder( $ordernumbers[1] ); +my $order2 = Koha::Acquisition::Orders->find( $ordernumbers[1] )->unblessed; $order2->{order_internalnote} = "my notes"; ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { @@ -445,7 +441,7 @@ my $budgetid2 = C4::Budgets::AddBudget( } ); -my $order3 = GetOrder( $ordernumbers[2] ); +my $order3 = Koha::Acquisition::Orders->find( $ordernumbers[2] )->unblessed; $order3->{order_internalnote} = "my other notes"; ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { @@ -472,7 +468,7 @@ is( $neworder->{'quantityreceived'}, 2, 'Splitting up order received items on new order' ); is( $neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed' ); -$order3 = GetOrder( $ordernumbers[2] ); +$order3 = Koha::Acquisition::Orders->find( $ordernumbers[2] )->unblessed; $order3->{order_internalnote} = "my third notes"; ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index 94aae51..20290da 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -30,7 +30,7 @@ use t::lib::Mocks; use Koha::Database; use Koha::DateUtils; use Koha::Acquisition::Booksellers; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use MARC::Record; my $schema = Koha::Database->new()->schema(); @@ -74,13 +74,13 @@ my $order = Koha::Acquisition::Order->new( biblionumber => $biblionumber, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber = $order->{ordernumber}; +)->store; +my $ordernumber = $order->ordernumber; ModReceiveOrder( { biblionumber => $biblionumber, - order => $order, + order => $order->unblessed, quantityreceived => 2, } ); @@ -103,10 +103,10 @@ $order = Koha::Acquisition::Order->new( biblionumber => $biblionumber, budget_id => $budget->{budget_id}, } -)->insert; -$ordernumber = $order->{ordernumber}; +)->store; +$ordernumber = $order->ordernumber; -is( $order->{parent_ordernumber}, $order->{ordernumber}, +is( $order->parent_ordernumber, $order->ordernumber, "Insert an order should set parent_order=ordernumber, if no parent_ordernumber given" ); @@ -114,7 +114,7 @@ $order->add_item( $itemnumber1 ); $order->add_item( $itemnumber2 ); is( - scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ), + scalar( GetItemnumbersFromOrder( $order->ordernumber ) ), 2, "Create items on ordering: 2 items should be linked to the order before receiving" ); @@ -122,7 +122,7 @@ is( my ( undef, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber, - order => $order, + order => $order->unblessed, quantityreceived => 1, received_items => [ $itemnumber1 ], } @@ -139,7 +139,7 @@ is( $new_order->{parent_ordernumber}, $ordernumber, ); is( - scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ), + scalar( GetItemnumbersFromOrder( $order->ordernumber ) ), 1, "Create items on ordering: 1 item should still be linked to the original order after receiving" ); @@ -157,7 +157,7 @@ is( "Create items on ordering: no item should be linked to the cancelled order" ); is( - scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ), + scalar( GetItemnumbersFromOrder( $order->ordernumber ) ), 2, "Create items on ordering: items are not deleted after cancelling a receipt" ); diff --git a/t/db_dependent/Acquisition/GetBasketAsCSV.t b/t/db_dependent/Acquisition/GetBasketAsCSV.t index 33e6f16..130de06 100644 --- a/t/db_dependent/Acquisition/GetBasketAsCSV.t +++ b/t/db_dependent/Acquisition/GetBasketAsCSV.t @@ -11,7 +11,7 @@ use C4::Biblio; use Koha::Database; use Koha::CsvProfile; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; my $schema = Koha::Database->new()->schema(); $schema->storage->txn_begin(); @@ -61,7 +61,7 @@ my $order = Koha::Acquisition::Order->new({ biblionumber => $biblionumber, budget_id => $budget_id, entrydate => '2016-01-02', -})->insert; +})->store; # Use user CSV profile my $basket_csv1 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile->export_format_id); @@ -72,7 +72,7 @@ is($basket_csv1, 'autor,title,quantity # Use default template my $basket_csv2 = C4::Acquisition::GetBasketAsCSV($basketno, $query); is($basket_csv2, 'Contract name,Order number,Entry date,ISBN,Author,Title,Publication year,Publisher,Collection title,Note for vendor,Quantity,RRP,Delivery place,Billing place -"",' . $order->{ordernumber} . ',2016-01-02,,"King, Stephen","Test Record",,"","","",3,,"","" +"",' . $order->ordernumber . ',2016-01-02,,"King, Stephen","Test Record",,"","","",3,,"","" ', 'CSV should be generated with default template'); my $basket_csv3 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile2->export_format_id); diff --git a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t index c25d11b..84ac14a 100644 --- a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t +++ b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t @@ -9,7 +9,7 @@ use C4::Biblio qw( AddBiblio ); use C4::Budgets qw( AddBudget ); use C4::Context; use Koha::Database; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; my $schema = Koha::Database->new()->schema(); $schema->storage->txn_begin(); @@ -50,8 +50,8 @@ my $order1 = Koha::Acquisition::Order->new( biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; +my $ordernumber1 = $order1->ordernumber; my $order2 = Koha::Acquisition::Order->new( { @@ -60,8 +60,8 @@ my $order2 = Koha::Acquisition::Order->new( biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber2 = $order2->{ordernumber}; +)->store; +my $ordernumber2 = $order2->ordernumber; my $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); is( scalar(@$baskets), 1, 'Start: 1 basket' ); diff --git a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t index 1d7b142..d01aeff 100644 --- a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t +++ b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t @@ -7,7 +7,7 @@ use C4::Acquisition; use C4::Biblio; use C4::Budgets; use Koha::Database; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use MARC::Record; @@ -48,8 +48,8 @@ my $order1 = Koha::Acquisition::Order->new( biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; +my $ordernumber1 = $order1->ordernumber; my $order2 = Koha::Acquisition::Order->new( { @@ -58,8 +58,8 @@ my $order2 = Koha::Acquisition::Order->new( biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber2 = $order1->{ordernumber}; +)->store; +my $ordernumber2 = $order2->ordernumber; my $order3 = Koha::Acquisition::Order->new( { @@ -68,8 +68,8 @@ my $order3 = Koha::Acquisition::Order->new( biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber3 = $order1->{ordernumber}; +)->store; +my $ordernumber3 = $order3->ordernumber; my @orders = GetOrdersByBiblionumber(); is(scalar(@orders), 0, 'GetOrdersByBiblionumber : no argument, return undef'); diff --git a/t/db_dependent/Acquisition/Invoices.t b/t/db_dependent/Acquisition/Invoices.t index 055b645..c308984 100644 --- a/t/db_dependent/Acquisition/Invoices.t +++ b/t/db_dependent/Acquisition/Invoices.t @@ -4,8 +4,8 @@ use Modern::Perl; use C4::Biblio qw( AddBiblio ); -use Koha::Acquisition::Order; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; use Koha::Database; use Test::More tests => 24; @@ -61,8 +61,8 @@ my $order1 = Koha::Acquisition::Order->new( biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; +my $ordernumber1 = $order1->ordernumber; my $order2 = Koha::Acquisition::Order->new( { @@ -71,8 +71,8 @@ my $order2 = Koha::Acquisition::Order->new( biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber2 = $order2->{ordernumber}; +)->store; +my $ordernumber2 = $order2->ordernumber; my $order3 = Koha::Acquisition::Order->new( { @@ -83,8 +83,8 @@ my $order3 = Koha::Acquisition::Order->new( ecost => 42, rrp => 42, } -)->insert; -my $ordernumber3 = $order3->{ordernumber}; +)->store; +my $ordernumber3 = $order3->ordernumber; my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown"); my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown", @@ -97,7 +97,7 @@ my $invoice2 = GetInvoice( $invoiceid2 ); my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber1, - order => $order1, + order => $order1->unblessed, quantityreceived => 2, invoice => $invoice1, } @@ -106,7 +106,7 @@ my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber2, - order => $order2, + order => $order2->unblessed, quantityreceived => 1, invoice => $invoice2, rrp => 42 @@ -116,7 +116,7 @@ my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber3, - order => $order3, + order => $order3->unblessed, quantityreceived => 1, invoice => $invoice2, } diff --git a/t/db_dependent/Acquisition/NewOrder.t b/t/db_dependent/Acquisition/NewOrder.t index a6deef8..cee35f7 100644 --- a/t/db_dependent/Acquisition/NewOrder.t +++ b/t/db_dependent/Acquisition/NewOrder.t @@ -10,7 +10,7 @@ use MARC::Record; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Booksellers; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; my $schema = Koha::Database->new()->schema(); $schema->storage->txn_begin(); @@ -44,7 +44,7 @@ my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); # returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing -my $order = eval { Koha::Acquisition::Order->new->insert }; +my $order = eval { Koha::Acquisition::Order->new->store }; my $return_error = $@; ok( ( ! defined $order ) @@ -63,7 +63,7 @@ foreach my $mandatoryparams_key (@mandatoryparams_keys) { my %test_missing_mandatoryparams = %$mandatoryparams; delete $test_missing_mandatoryparams{$mandatoryparams_key}; $order = eval { - Koha::Acquisition::Order->new( \%test_missing_mandatoryparams )->insert; + Koha::Acquisition::Order->new( \%test_missing_mandatoryparams )->store; }; $return_error = $@; my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing"; @@ -81,10 +81,10 @@ $order = Koha::Acquisition::Order->new( biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber = $order->{ordernumber}; -$order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber }); -is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' ); -is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' ); +)->store; +my $ordernumber = $order->ordernumber; +$order = Koha::Acquisition::Orders->find( $ordernumber ); +is( $order->quantityreceived, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' ); +is( $order->entrydate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->store set entrydate to today' ); $schema->storage->txn_rollback(); diff --git a/t/db_dependent/Acquisition/OrderFromSubscription.t b/t/db_dependent/Acquisition/OrderFromSubscription.t index 4f318b2..874459a 100644 --- a/t/db_dependent/Acquisition/OrderFromSubscription.t +++ b/t/db_dependent/Acquisition/OrderFromSubscription.t @@ -9,7 +9,7 @@ use_ok('C4::Biblio'); use_ok('C4::Budgets'); use_ok('C4::Serials'); -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use Koha::Database; # Start transaction @@ -68,16 +68,14 @@ my $order = Koha::Acquisition::Order->new({ quantity => 1, currency => $curcode, listprice => $cost, - notes => "This is a note", basketno => $basketno, rrp => $cost, ecost => $cost, - tax_rate => 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"); diff --git a/t/db_dependent/Acquisition/OrderUsers.t b/t/db_dependent/Acquisition/OrderUsers.t index 1c9a415..610f879 100644 --- a/t/db_dependent/Acquisition/OrderUsers.t +++ b/t/db_dependent/Acquisition/OrderUsers.t @@ -5,8 +5,8 @@ use C4::Acquisition; use C4::Biblio; use C4::Letters; use Koha::Database; -use Koha::Acquisition::Order; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; use t::lib::TestBuilder; @@ -51,14 +51,13 @@ my $order = Koha::Acquisition::Order->new( budget_id => $budgetid, entrydate => '01-01-2014', currency => $currency->{currency}, - notes => "This is a note1", orderstatus => 1, quantityreceived => 0, rrp => 10, ecost => 10, } -)->insert; -my $ordernumber = $order->{ordernumber}; +)->store; +my $ordernumber = $order->ordernumber; my $invoiceid = AddInvoice( invoicenumber => 'invoice', @@ -82,11 +81,11 @@ C4::Acquisition::ModOrderUsers( $ordernumber, $borrowernumber ); my $is_added = grep { /^$borrowernumber$/ } C4::Acquisition::GetOrderUsers( $ordernumber ); is( $is_added, 1, 'ModOrderUsers should link patrons to an order' ); -$order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber }); +$order = Koha::Acquisition::Orders->find( $ordernumber ); ModReceiveOrder( { biblionumber => $biblionumber, - order => $order, + order => $order->unblessed, quantityreceived => 1, cost => 10, ecost => 10, @@ -99,11 +98,11 @@ ModReceiveOrder( my $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber }); is( scalar( @$messages ), 0, 'The letter has not been sent to message queue on receiving the order, the order is not entire received'); -$order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber }); +$order = Koha::Acquisition::Orders->find( $ordernumber ); ModReceiveOrder( { biblionumber => $biblionumber, - order => $order, + order => $order->unblessed, quantityreceived => 1, cost => 10, ecost => 10, diff --git a/t/db_dependent/Acquisition/StandingOrders.t b/t/db_dependent/Acquisition/StandingOrders.t index 9750bae..1fbe88f 100644 --- a/t/db_dependent/Acquisition/StandingOrders.t +++ b/t/db_dependent/Acquisition/StandingOrders.t @@ -8,7 +8,7 @@ use C4::Acquisition; use C4::Biblio; use C4::Items; use C4::Budgets; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use t::lib::Mocks; use t::lib::TestBuilder; @@ -73,11 +73,10 @@ my $ordernumber = Koha::Acquisition::Order->new( unitprice => 12, unitprice_tax_included => 12, unitprice_tax_excluded => 12, - tax_rate => 0, tax_rate_on_ordering => 0, tax_rate_on_receiving => 0, } -)->insert->{ordernumber}; +)->store->ordernumber; isnt( $ordernumber, undef, 'standing order successfully created' ); @@ -98,12 +97,12 @@ my $invoiceid = AddInvoice( unknown => "unknown" ); -my $order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } ); +my $order = Koha::Acquisition::Orders->find( $ordernumber ); my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber, - order => $order, + order => $order->unblessed, quantityreceived => 2, invoiceid => $invoiceid, } @@ -112,16 +111,16 @@ my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( isnt( $ordernumber, $new_ordernumber, "standing order split on receive" ); #order has been updated, refetch -$order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } ); -my $neworder = Koha::Acquisition::Order->fetch( { ordernumber => $new_ordernumber } ); - -is( $order->{orderstatus}, 'partial', 'original order set to partially received' ); -is( $order->{quantity}, 1, 'original order quantity unchanged' ); -is( $order->{quantityreceived}, 0, 'original order has no received items' ); -isnt( $order->{unitprice}, 12, 'original order does not get cost' ); -is( $neworder->{orderstatus}, 'complete', 'new order set to complete' ); -is( $neworder->{quantityreceived}, 2, 'new order has received items' ); -cmp_ok( $neworder->{unitprice}, '==', 12, 'new order does get cost' ); +$order = Koha::Acquisition::Orders->find( $ordernumber ); +my $neworder = Koha::Acquisition::Orders->find( $new_ordernumber ); + +is( $order->orderstatus, 'partial', 'original order set to partially received' ); +is( $order->quantity, 1, 'original order quantity unchanged' ); +is( $order->quantityreceived, 0, 'original order has no received items' ); +isnt( $order->unitprice, 12, 'original order does not get cost' ); +is( $neworder->orderstatus, 'complete', 'new order set to complete' ); +is( $neworder->quantityreceived, 2, 'new order has received items' ); +cmp_ok( $neworder->unitprice, '==', 12, 'new order does get cost' ); $search_orders = SearchOrders( { basketno => $basketno, diff --git a/t/db_dependent/Acquisition/TransferOrder.t b/t/db_dependent/Acquisition/TransferOrder.t index a25d2a2..c0d001b 100644 --- a/t/db_dependent/Acquisition/TransferOrder.t +++ b/t/db_dependent/Acquisition/TransferOrder.t @@ -11,7 +11,7 @@ use C4::Budgets; use Koha::Database; use Koha::DateUtils; use Koha::Acquisition::Booksellers; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use MARC::Record; my $schema = Koha::Database->new()->schema(); @@ -65,8 +65,8 @@ my $order = Koha::Acquisition::Order->new( biblionumber => $biblionumber, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber = $order->{ordernumber}; +)->store; +my $ordernumber = $order->ordernumber; $order->add_item( $itemnumber ); # Begin tests @@ -95,7 +95,7 @@ $orders = SearchOrders({ ordernumber => $ordernumber }); is ( scalar( @$orders ), 1, 'SearchOrders returns 1 order with [old]ordernumber' ); is ( $orders->[0]->{ordernumber}, $newordernumber, 'SearchOrders returns newordernumber if [old]ordernumber is given' ); -my $neworder = GetOrder( $newordernumber ); +my $neworder = Koha::Acquisition::Orders->find( $newordernumber )->unblessed; ModReceiveOrder({ biblionumber => $biblionumber, diff --git a/t/db_dependent/Acquisition/close_reopen_basket.t b/t/db_dependent/Acquisition/close_reopen_basket.t index 191612a..51780f0 100644 --- a/t/db_dependent/Acquisition/close_reopen_basket.t +++ b/t/db_dependent/Acquisition/close_reopen_basket.t @@ -8,8 +8,8 @@ use C4::Biblio qw( AddBiblio DelBiblio ); use C4::Budgets; use C4::Context; use Koha::Database; -use Koha::Acquisition::Bookseller; -use Koha::Acquisition::Order; +use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; # Start transaction my $schema = Koha::Database->new()->schema(); @@ -54,8 +54,8 @@ my $order1 = Koha::Acquisition::Order->new( biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; +my $ordernumber1 = $order1->ordernumber; my $order2 = Koha::Acquisition::Order->new( { @@ -64,8 +64,8 @@ my $order2 = Koha::Acquisition::Order->new( biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber2 = $order2->{ordernumber}; +)->store; +my $ordernumber2 = $order2->ordernumber; my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno ); is ( $nb_biblio, 2, "There are 2 biblio for this basket" ); diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index 94293ac..416974c 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -18,7 +18,7 @@ use C4::Budgets; use C4::Biblio; use Koha::Acquisition::Booksellers; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use Koha::Database; BEGIN { @@ -365,8 +365,8 @@ my $order1 = Koha::Acquisition::Order->new( ecost => 10, datereceived => '01-06-2013' } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; +my $ordernumber1 = $order1->ordernumber; my $order2 = Koha::Acquisition::Order->new( { @@ -383,8 +383,8 @@ my $order2 = Koha::Acquisition::Order->new( rrp => 10, ecost => 10, } -)->insert; -my $ordernumber2 = $order2->{ordernumber}; +)->store; +my $ordernumber2 = $order2->ordernumber; my $order3 = Koha::Acquisition::Order->new( { @@ -401,8 +401,8 @@ my $order3 = Koha::Acquisition::Order->new( rrp => 11, ecost => 11, } -)->insert; -my $ordernumber3 = $order3->{ordernumber}; +)->store; +my $ordernumber3 = $order3->ordernumber; my $order4 = Koha::Acquisition::Order->new( { @@ -420,8 +420,8 @@ my $order4 = Koha::Acquisition::Order->new( ecost => 11, quantityreceived => 20 } -)->insert; -my $ordernumber4 = $order4->{ordernumber}; +)->store; +my $ordernumber4 = $order4->ordernumber; #Test cases: # Sample datas : diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index c626528..eefd36f 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -10,8 +10,8 @@ use C4::Biblio; use C4::Acquisition; use C4::Members qw( AddMember ); -use Koha::Acquisition::Order; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; use t::lib::TestBuilder; @@ -357,8 +357,8 @@ for my $infos (@order_infos) { discount => 0, uncertainprice => 0, } - )->insert; - my $ordernumber = $order->{ordernumber}; + )->store; + my $ordernumber = $order->ordernumber; push @{ $budgets{$infos->{budget_id}} }, $ordernumber; $number_of_orders_to_move++; } @@ -378,11 +378,11 @@ for my $infos (@order_infos) { discount => 0, uncertainprice => 0, } - )->insert; - my $ordernumber = $order->{ordernumber}; + )->store; + my $ordernumber = $order->ordernumber; ModReceiveOrder({ biblionumber => $biblionumber, - order => $order, + order => $order->unblessed, budget_id => $infos->{budget_id}, quantityreceived => $item_quantity, invoice => $invoice, diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index b54f1c7..21206f1 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -43,9 +43,9 @@ use t::lib::Mocks; use t::lib::TestBuilder; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); -use Koha::Acquisition::Order; use Koha::Acquisition::Booksellers; use Koha::Acquisition::Bookseller::Contacts; +use Koha::Acquisition::Orders; use Koha::Libraries; use Koha::Notice::Templates; my $schema = Koha::Database->schema; @@ -435,8 +435,8 @@ my $order = Koha::Acquisition::Order->new( biblionumber => $biblionumber, budget_id => $budgetid, } -)->insert; -my $ordernumber = $order->{ordernumber}; +)->store; +my $ordernumber = $order->ordernumber; C4::Acquisition::CloseBasket( $basketno ); my $err; diff --git a/t/db_dependent/UsageStats.t b/t/db_dependent/UsageStats.t index 5f4dfad..388bb31 100644 --- a/t/db_dependent/UsageStats.t +++ b/t/db_dependent/UsageStats.t @@ -31,7 +31,7 @@ BEGIN { use_ok( 'C4::AuthoritiesMarc', qw(AddAuthority) ); use_ok('C4::Reserves'); use_ok('MARC::Record'); - use_ok('Koha::Acquisition::Order'); + use_ok('Koha::Acquisition::Orders'); } can_ok( -- 2.10.2