From 2690c0fb26ec15c536e34a7cce2f0d6424b082a6 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 10 Jan 2017 17:08:51 +0100 Subject: [PATCH] Bug 11708: Move acq related Koha::Objects to Koha::Acquisition namespace and fix Koha::Acquisition::Order usage everywhere --- C4/Acquisition.pm | 10 +- Koha/{ => Acquisition}/Basket.pm | 6 +- Koha/{ => Acquisition}/Basketgroup.pm | 8 +- Koha/{ => Acquisition}/Basketgroups.pm | 6 +- Koha/{ => Acquisition}/Baskets.pm | 6 +- Koha/Acquisition/Order.pm | 104 +++++++++------------ Koha/{ => Acquisition}/Orders.pm | 6 +- Koha/Bookseller.pm | 26 ------ Koha/Booksellers.pm | 32 ------- Koha/Order.pm | 26 ------ acqui/addorder.pl | 2 +- acqui/addorderiso2709.pl | 2 +- acqui/finishreceive.pl | 3 +- admin/currency.pl | 5 +- t/db_dependent/Acquisition.t | 11 +-- t/db_dependent/Acquisition/CancelReceipt.t | 20 ++-- .../Acquisition/GetBasketsInfosByBookseller.t | 8 +- .../Acquisition/GetOrdersByBiblionumber.t | 15 ++- t/db_dependent/Acquisition/Invoices.t | 37 +++++--- t/db_dependent/Acquisition/NewOrder.t | 16 ++-- t/db_dependent/Acquisition/OrderFromSubscription.t | 13 +-- t/db_dependent/Acquisition/OrderUsers.t | 18 ++-- t/db_dependent/Acquisition/StandingOrders.t | 29 +++--- t/db_dependent/Acquisition/TransferOrder.t | 4 +- t/db_dependent/Acquisition/close_reopen_basket.t | 10 +- t/db_dependent/Bookseller.t | 32 +++---- t/db_dependent/Budgets.t | 15 ++- t/db_dependent/Letters.t | 4 +- 28 files changed, 181 insertions(+), 293 deletions(-) rename Koha/{ => Acquisition}/Basket.pm (85%) rename Koha/{ => Acquisition}/Basketgroup.pm (87%) rename Koha/{ => Acquisition}/Basketgroups.pm (87%) rename Koha/{ => Acquisition}/Baskets.pm (88%) rename Koha/{ => Acquisition}/Orders.pm (88%) delete mode 100644 Koha/Bookseller.pm delete mode 100644 Koha/Booksellers.pm delete mode 100644 Koha/Order.pm diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 67a907f..d5b6b2d 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -28,7 +28,7 @@ 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::Orders; use Koha::Acquisition::Booksellers; use Koha::Number::Price; use Koha::Libraries; @@ -1448,7 +1448,9 @@ sub ModReceiveOrder { $order->{datereceived} = $datereceived; $order->{invoiceid} = $invoice->{invoiceid}; $order->{orderstatus} = 'complete'; - $new_ordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber}; + my @columns = Koha::Acquisition::Orders->columns; + my %filtered_order = map { exists $order->{$_} ? ($_ => $order->{$_}) : () } @columns; + $new_ordernumber = Koha::Acquisition::Order->new(\%filtered_order)->store->ordernumber; if ($received_items) { foreach my $itemnumber (@$received_items) { @@ -1926,7 +1928,9 @@ sub TransferOrder { delete $order->{parent_ordernumber}; $order->{'basketno'} = $basketno; - my $newordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber}; + my @columns = Koha::Acquisition::Orders->columns; + my %filtered_order = map { exists $order->{$_} ? ($_ => $order->{$_}) : () } @columns; + my $newordernumber = Koha::Acquisition::Order->new(\%filtered_order)->store->ordernumber; $query = q{ UPDATE aqorders_items diff --git a/Koha/Basket.pm b/Koha/Acquisition/Basket.pm similarity index 85% rename from Koha/Basket.pm rename to Koha/Acquisition/Basket.pm index 4703101..1b8f051 100644 --- a/Koha/Basket.pm +++ b/Koha/Acquisition/Basket.pm @@ -1,4 +1,4 @@ -package Koha::Basket; +package Koha::Acquisition::Basket; # This file is part of Koha. # @@ -17,7 +17,7 @@ package Koha::Basket; use Modern::Perl; -use Koha::Orders; +use Koha::Acquisition::Orders; use base qw(Koha::Object); @@ -28,7 +28,7 @@ sub _type { sub orders { my ($self) = @_; - $self->{_orders} ||= Koha::Orders->search({ basketno => $self->basketno }); + $self->{_orders} ||= Koha::Acquisition::Orders->search({ basketno => $self->basketno }); return wantarray ? $self->{_orders}->as_list : $self->{_orders}; } diff --git a/Koha/Basketgroup.pm b/Koha/Acquisition/Basketgroup.pm similarity index 87% rename from Koha/Basketgroup.pm rename to Koha/Acquisition/Basketgroup.pm index e624a35..80e2211 100644 --- a/Koha/Basketgroup.pm +++ b/Koha/Acquisition/Basketgroup.pm @@ -1,4 +1,4 @@ -package Koha::Basketgroup; +package Koha::Acquisition::Basketgroup; # This file is part of Koha. # @@ -19,7 +19,7 @@ use Modern::Perl; use List::MoreUtils qw/uniq/; -use Koha::Baskets; +use Koha::Acquisition::Baskets; use base qw(Koha::Object); @@ -30,13 +30,13 @@ sub _type { sub bookseller { my ($self) = @_; - return Koha::Booksellers->find($self->booksellerid); + return Koha::Acquisition::Booksellers->find($self->booksellerid); } sub baskets { my ($self) = @_; - $self->{_baskets} ||= Koha::Baskets->search({ basketgroupid => $self->id }); + $self->{_baskets} ||= Koha::Acquisition::Baskets->search({ basketgroupid => $self->id }); return wantarray ? $self->{_baskets}->as_list : $self->{_baskets}; } diff --git a/Koha/Basketgroups.pm b/Koha/Acquisition/Basketgroups.pm similarity index 87% rename from Koha/Basketgroups.pm rename to Koha/Acquisition/Basketgroups.pm index 1dbc6d1..6f648cc 100644 --- a/Koha/Basketgroups.pm +++ b/Koha/Acquisition/Basketgroups.pm @@ -1,4 +1,4 @@ -package Koha::Basketgroups; +package Koha::Acquisition::Basketgroups; # This file is part of Koha. # @@ -17,7 +17,7 @@ package Koha::Basketgroups; use Modern::Perl; -use Koha::Basketgroup; +use Koha::Acquisition::Basketgroup; use base qw(Koha::Objects); @@ -26,7 +26,7 @@ sub _type { } sub object_class { - return 'Koha::Basketgroup'; + return 'Koha::Acquisition::Basketgroup'; } 1; diff --git a/Koha/Baskets.pm b/Koha/Acquisition/Baskets.pm similarity index 88% rename from Koha/Baskets.pm rename to Koha/Acquisition/Baskets.pm index badd91a..e29f2e1 100644 --- a/Koha/Baskets.pm +++ b/Koha/Acquisition/Baskets.pm @@ -1,4 +1,4 @@ -package Koha::Baskets; +package Koha::Acquisition::Baskets; # This file is part of Koha. # @@ -17,7 +17,7 @@ package Koha::Baskets; use Modern::Perl; -use Koha::Basket; +use Koha::Acquisition::Basket; use base qw(Koha::Objects); @@ -26,7 +26,7 @@ sub _type { } sub object_class { - return 'Koha::Basket'; + return 'Koha::Acquisition::Basket'; } 1; diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index ede8ddf..c212c5d 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -1,61 +1,58 @@ 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 Koha::Acquisition::Baskets; -use Carp qw( croak ); - -use base qw( Class::Accessor ); - -# 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; +use base qw(Koha::Object); - my $order = - $schema->resultset('Aqorder')->find( { ordernumber => $ordernumber }, - { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ); - return $class->new( $order ); -} - -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 ); + if ($self->basketno) { + my $basket = Koha::Acquisition::Baskets->find($self->basketno); + if ($basket->is_standing) { + $self->quantity(1); + } + } # 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; + unless ($self->quantityreceived) { + $self->quantityreceived(0); + } - $self->{ordernumber} ||= undef; + unless ($self->entrydate) { + $self->entrydate(output_pref( { dt => dt_from_string, dateformat => 'iso' } )); + } - my $rs = $schema->resultset('Aqorder')->create( - { - map { - exists $self->{$_} ? ( $_ => $self->{$_} ) : () - } @columns - } - ); - $self->{ordernumber} = $rs->id; + $self = $self->SUPER::store($self); - unless ( $self->{parent_ordernumber} ) { - $self->{parent_ordernumber} = $self->{ordernumber}; - $rs->update( { parent_ordernumber => $self->{parent_ordernumber} } ); + if ($self && !$self->parent_ordernumber) { + $self->parent_ordernumber($self->ordernumber); + $self = $self->SUPER::store($self); } return $self; @@ -63,33 +60,18 @@ sub insert { sub add_item { my ( $self, $itemnumber ) = @_; + my $schema = Koha::Database->new->schema; my $rs = $schema->resultset('AqordersItem'); - $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"; -} - -# TODO Move code from ModOrder -sub update { - die "not implemented yet"; -} -# TODO Move code from DelOrder -sub delete { - die "not implemented yet"; + $rs->create({ + ordernumber => $self->ordernumber, + itemnumber => $itemnumber, + }); } -# TODO Move code from TransferOrder -sub transfer { - die "not implemented yet"; +sub _type { + return 'Aqorder'; } 1; diff --git a/Koha/Orders.pm b/Koha/Acquisition/Orders.pm similarity index 88% rename from Koha/Orders.pm rename to Koha/Acquisition/Orders.pm index 49f616b..9af45ee 100644 --- a/Koha/Orders.pm +++ b/Koha/Acquisition/Orders.pm @@ -1,4 +1,4 @@ -package Koha::Orders; +package Koha::Acquisition::Orders; # This file is part of Koha. # @@ -17,7 +17,7 @@ package Koha::Orders; use Modern::Perl; -use Koha::Order; +use Koha::Acquisition::Order; use base qw(Koha::Objects); @@ -26,7 +26,7 @@ sub _type { } sub object_class { - return 'Koha::Order'; + return 'Koha::Acquisition::Order'; } 1; diff --git a/Koha/Bookseller.pm b/Koha/Bookseller.pm deleted file mode 100644 index 1979f62..0000000 --- a/Koha/Bookseller.pm +++ /dev/null @@ -1,26 +0,0 @@ -package Koha::Bookseller; - -# 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 base qw(Koha::Object); - -sub _type { - return 'Aqbookseller'; -} - -1; diff --git a/Koha/Booksellers.pm b/Koha/Booksellers.pm deleted file mode 100644 index fb689c7..0000000 --- a/Koha/Booksellers.pm +++ /dev/null @@ -1,32 +0,0 @@ -package Koha::Booksellers; - -# 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 Koha::Bookseller; - -use base qw(Koha::Objects); - -sub _type { - return 'Aqbookseller'; -} - -sub object_class { - return 'Koha::Bookseller'; -} - -1; diff --git a/Koha/Order.pm b/Koha/Order.pm deleted file mode 100644 index 7ab7ed1..0000000 --- a/Koha/Order.pm +++ /dev/null @@ -1,26 +0,0 @@ -package Koha::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 base qw(Koha::Object); - -sub _type { - return 'Aqorder'; -} - -1; diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 81064ff..d045e93 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -286,7 +286,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 b64ddad..e8f4ef0 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -258,7 +258,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 2c6340c..23bafb0 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -32,6 +32,7 @@ use C4::Items; use C4::Search; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; use List::MoreUtils qw/any/; @@ -131,7 +132,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 $order = Koha::Acquisition::Orders->find($new_ordernumber); foreach my $item (keys %itemhash){ my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'}, $itemhash{$item}->{'subfields'}, diff --git a/admin/currency.pl b/admin/currency.pl index 09b6a74..0b3efe7 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -26,6 +26,7 @@ use C4::Context; use C4::Output; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; use Koha::Acquisition::Currency; use Koha::Acquisition::Currencies; @@ -92,9 +93,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->count; my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } }); $template->param( currency => $currency, diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index b51dc9c..9049289 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -179,7 +179,6 @@ my @order_content = ( uncertainprice => 0, order_internalnote => "internal note", order_vendornote => "vendor note", - ordernumber => '', }, num => { quantity => 24, @@ -187,7 +186,7 @@ my @order_content = ( ecost => 38.15, rrp => 40.15, discount => 5.1111, - tax_rate => 0.0515 + tax_rate_on_ordering => 0.0515 } }, { @@ -215,7 +214,7 @@ my @order_content = ( ecost => 38.1, rrp => 11.0, discount => 5.1, - tax_rate => 0.1 + tax_rate_on_ordering => 0.1 } }, { @@ -235,7 +234,7 @@ my @order_content = ( rrp => 11.00, discount => 0, uncertainprice => 0, - tax_rate => 0 + tax_rate_on_ordering => 0 } }, { @@ -255,7 +254,7 @@ my @order_content = ( rrp => 10, discount => 0, uncertainprice => 0, - tax_rate => 0 + tax_rate_on_ordering => 0 } } ); @@ -267,7 +266,7 @@ for ( 0 .. 4 ) { values %{ $order_content[$_]->{num} }; @ocontent{ keys %{ $order_content[$_]->{str} } } = values %{ $order_content[$_]->{str} }; - $ordernumbers[$_] = Koha::Acquisition::Order->new( \%ocontent )->insert->{ordernumber}; + $ordernumbers[$_] = Koha::Acquisition::Order->new( \%ocontent )->store->ordernumber; $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_]; } diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index 94aae51..df3bac9 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -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/GetBasketsInfosByBookseller.t b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t index c25d11b..b196303 100644 --- a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t +++ b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t @@ -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 1d7b1426..fcd1618 100644 --- a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t +++ b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t @@ -41,35 +41,32 @@ my $budget = C4::Budgets::GetBudget( $budgetid ); my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); -my $order1 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno, quantity => 24, biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; -my $order2 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno, quantity => 42, biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber2 = $order1->{ordernumber}; +)->store; -my $order3 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno, quantity => 4, biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber3 = $order1->{ordernumber}; +)->store; 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..62bbf95 100644 --- a/t/db_dependent/Acquisition/Invoices.t +++ b/t/db_dependent/Acquisition/Invoices.t @@ -44,12 +44,22 @@ my $budgetid = C4::Budgets::AddBudget( my $budget = C4::Budgets::GetBudget( $budgetid ); my $bibrec1 = MARC::Record->new(); -$bibrec1->append_fields( - MARC::Field->new('020', '', '', 'a' => '1234567890'), - MARC::Field->new('100', '', '', 'a' => 'Shakespeare, Billy'), - MARC::Field->new('245', '', '', 'a' => 'Bug 8854'), - MARC::Field->new('260', '', '', 'b' => 'Scholastic Publishing', c => 'c2012'), -); +if (C4::Context->preference('marcflavour') eq 'UNIMARC') { + $bibrec1->append_fields( + MARC::Field->new('010', '', '', 'a' => '1234567890'), + MARC::Field->new('200', '', '', 'f' => 'Shakespeare, Billy'), + MARC::Field->new('200', '', '', 'a' => 'Bug 8854'), + MARC::Field->new('210', '', '', 'c' => 'Scholastic Publishing', d => '2012'), + ); +} else { + $bibrec1->append_fields( + MARC::Field->new('020', '', '', 'a' => '1234567890'), + MARC::Field->new('100', '', '', 'a' => 'Shakespeare, Billy'), + MARC::Field->new('245', '', '', 'a' => 'Bug 8854'), + MARC::Field->new('260', '', '', 'b' => 'Scholastic Publishing', c => '2012'), + ); +} + my ($biblionumber1, $biblioitemnumber1) = AddBiblio($bibrec1, ''); my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, ''); @@ -61,8 +71,7 @@ my $order1 = Koha::Acquisition::Order->new( biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; my $order2 = Koha::Acquisition::Order->new( { @@ -71,8 +80,7 @@ my $order2 = Koha::Acquisition::Order->new( biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber2 = $order2->{ordernumber}; +)->store; my $order3 = Koha::Acquisition::Order->new( { @@ -83,8 +91,7 @@ my $order3 = Koha::Acquisition::Order->new( ecost => 42, rrp => 42, } -)->insert; -my $ordernumber3 = $order3->{ordernumber}; +)->store; my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown"); my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown", @@ -97,7 +104,7 @@ my $invoice2 = GetInvoice( $invoiceid2 ); my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber1, - order => $order1, + order => $order1->unblessed, quantityreceived => 2, invoice => $invoice1, } @@ -106,7 +113,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 +123,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..af67ee1 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->store 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 4641894..37f1a8e 100644 --- a/t/db_dependent/Acquisition/OrderFromSubscription.t +++ b/t/db_dependent/Acquisition/OrderFromSubscription.t @@ -26,7 +26,6 @@ my $bookseller = Koha::Acquisition::Bookseller->new( )->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', @@ -51,33 +50,31 @@ my $subscriptionid = NewSubscription( ); die unless $subscriptionid; -my ($basket, $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({ +Koha::Acquisition::Order->new({ biblionumber => $subscription->{biblionumber}, entrydate => '01-01-2013', quantity => 1, currency => 'USD', listprice => $cost, - notes => "This is a note", basketno => $basketno, rrp => $cost, ecost => $cost, - tax_rate => 0.0500, + tax_rate_on_ordering => 0.0500, orderstatus => 'new', subscriptionid => $subscription->{subscriptionid}, budget_id => $budget_id, -})->insert; -my $ordernumber = $order->{ordernumber}; +})->store; my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} ); is ( $is_currently_on_order, 1, "The subscription is currently on order"); -$order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} ); +my $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} ); 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"); diff --git a/t/db_dependent/Acquisition/OrderUsers.t b/t/db_dependent/Acquisition/OrderUsers.t index 4a50440..92fcd58 100644 --- a/t/db_dependent/Acquisition/OrderUsers.t +++ b/t/db_dependent/Acquisition/OrderUsers.t @@ -5,7 +5,7 @@ use C4::Acquisition; use C4::Biblio; use C4::Letters; use Koha::Database; -use Koha::Acquisition::Order; +use Koha::Acquisition::Orders; use Koha::Acquisition::Booksellers; use t::lib::TestBuilder; @@ -38,7 +38,6 @@ my $budgetid = C4::Budgets::AddBudget( ); my $budget = C4::Budgets::GetBudget($budgetid); -my @ordernumbers; my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( MARC::Record->new, '' ); my $order = Koha::Acquisition::Order->new( @@ -49,15 +48,14 @@ my $order = Koha::Acquisition::Order->new( budget_id => $budgetid, entrydate => '01-01-2014', currency => 'EUR', - notes => "This is a note1", - gstrate => 0.0500, + tax_rate_on_ordering => 0.0500, orderstatus => 1, quantityreceived => 0, rrp => 10, ecost => 10, } -)->insert; -my $ordernumber = $order->{ordernumber}; +)->store; +my $ordernumber = $order->ordernumber; my $invoiceid = AddInvoice( invoicenumber => 'invoice', @@ -83,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, @@ -100,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 f0e7dc8..af36cfa 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; @@ -72,11 +72,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' ); @@ -97,12 +96,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, } @@ -111,16 +110,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..15a5884 100644 --- a/t/db_dependent/Acquisition/TransferOrder.t +++ b/t/db_dependent/Acquisition/TransferOrder.t @@ -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 diff --git a/t/db_dependent/Acquisition/close_reopen_basket.t b/t/db_dependent/Acquisition/close_reopen_basket.t index aba4824..6c55929 100644 --- a/t/db_dependent/Acquisition/close_reopen_basket.t +++ b/t/db_dependent/Acquisition/close_reopen_basket.t @@ -47,25 +47,23 @@ my $budget = C4::Budgets::GetBudget( $budgetid ); my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); -my $order1 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno, quantity => 24, biblionumber => $biblionumber1, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; -my $order2 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno, quantity => 42, biblionumber => $biblionumber2, budget_id => $budget->{budget_id}, } -)->insert; -my $ordernumber2 = $order2->{ordernumber}; +)->store; 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 77cf3ef..dad4ffa 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -343,7 +343,7 @@ is(scalar(@subscriptions), 1, 'search for subscriptions by call number'); is(scalar(@subscriptions), 1, 'search for subscriptions by location'); #Add 4 orders -my $order1 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno1, quantity => 24, @@ -351,8 +351,7 @@ my $order1 = Koha::Acquisition::Order->new( budget_id => $id_budget, entrydate => '01-01-2013', currency => 'EUR', - notes => "This is a note1", - tax_rate => 0.0500, + tax_rate_on_ordering => 0.0500, orderstatus => 1, subscriptionid => $id_subscription1, quantityreceived => 2, @@ -360,10 +359,9 @@ my $order1 = Koha::Acquisition::Order->new( ecost => 10, datereceived => '01-06-2013' } -)->insert; -my $ordernumber1 = $order1->{ordernumber}; +)->store; -my $order2 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno2, quantity => 20, @@ -371,17 +369,15 @@ my $order2 = Koha::Acquisition::Order->new( budget_id => $id_budget, entrydate => '01-01-2013', currency => 'EUR', - notes => "This is a note2", - tax_rate => 0.0500, + tax_rate_on_ordering => 0.0500, orderstatus => 1, subscriptionid => $id_subscription2, rrp => 10, ecost => 10, } -)->insert; -my $ordernumber2 = $order2->{ordernumber}; +)->store; -my $order3 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno3, quantity => 20, @@ -389,17 +385,15 @@ my $order3 = Koha::Acquisition::Order->new( budget_id => $id_budget, entrydate => '02-02-2013', currency => 'EUR', - notes => "This is a note3", - tax_rate => 0.0500, + tax_rate_on_ordering => 0.0500, orderstatus => 2, subscriptionid => $id_subscription3, rrp => 11, ecost => 11, } -)->insert; -my $ordernumber3 = $order3->{ordernumber}; +)->store; -my $order4 = Koha::Acquisition::Order->new( +Koha::Acquisition::Order->new( { basketno => $basketno4, quantity => 20, @@ -407,16 +401,14 @@ my $order4 = Koha::Acquisition::Order->new( budget_id => $id_budget, entrydate => '02-02-2013', currency => 'EUR', - notes => "This is a note3", - tax_rate => 0.0500, + tax_rate_on_ordering => 0.0500, orderstatus => 2, subscriptionid => $id_subscription3, rrp => 11, ecost => 11, quantityreceived => 20 } -)->insert; -my $ordernumber4 = $order4->{ordernumber}; +)->store; #Test cases: # Sample datas : diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 0611389..4c6cac2 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -332,15 +332,15 @@ for my $infos (@order_infos) { order_internalnote => "internal note", order_vendornote => "vendor note", quantity => 2, - cost_tax_included => $item_price, + ecost_tax_included => $item_price, rrp_tax_included => $item_price, listprice => $item_price, - ecost_tax_include => $item_price, + ecost_tax_included => $item_price, 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++; } @@ -353,18 +353,17 @@ for my $infos (@order_infos) { order_internalnote => "internal note", order_vendornote => "vendor note", quantity => $item_quantity, - cost => $item_price, + ecost => $item_price, rrp_tax_included => $item_price, listprice => $item_price, ecost_tax_included => $item_price, discount => 0, uncertainprice => 0, } - )->insert; - my $ordernumber = $order->{ordernumber}; + )->store; 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 8219e5b..b084839 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -405,8 +405,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; -- 2.1.4