From 8d776af65e68d6688c8428e2b77e6a3203c5e7b5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 Sep 2014 15:56:56 +0200 Subject: [PATCH 4/4] Bug 12896: Move the bookseller-related code into Koha::Acquisition::Bookseller The C4::Acquisition module should be exploded in order to add readability and maintainability to this part of the code. This patch is a POC, it introduces a new Koha::Acquisition::Bookseller module and put in it the code from GetBookSeller and GetBookSellerFromId. Test plan: 1/ Create a bookseller, modify it. 2/ Add contacts for this bookseller 3/ Create an order, receive it, transfer it 4/ Launch the prove command on all unit tests modified by this patch and verify that all pass. Signed-off-by: Paola Rossi --- C4/Acquisition.pm | 4 +- C4/Bookseller.pm | 53 +-------- Koha/Acquisition/Bookseller.pm | 124 ++++++++++++++++++++ acqui/addorderiso2709.pl | 4 +- acqui/basket.pl | 5 +- acqui/basketgroup.pl | 10 +- acqui/basketheader.pl | 6 +- acqui/booksellers.pl | 7 +- acqui/finishreceive.pl | 5 +- acqui/invoice.pl | 5 +- acqui/invoices.pl | 3 +- acqui/modordernotes.pl | 5 +- acqui/neworderbiblio.pl | 5 +- acqui/neworderempty.pl | 5 +- acqui/newordersubscription.pl | 5 +- acqui/newordersuggestion.pl | 5 +- acqui/orderreceive.pl | 5 +- acqui/parcel.pl | 6 +- acqui/parcels.pl | 5 +- acqui/supplier.pl | 6 +- acqui/transferorder.pl | 11 +- acqui/uncertainprice.pl | 5 +- acqui/z3950_search.pl | 5 +- admin/aqcontract.pl | 5 +- catalogue/moredetail.pl | 5 +- serials/acqui-search-result.pl | 5 +- serials/subscription-detail.pl | 8 +- t/db_dependent/Acquisition.t | 7 +- t/db_dependent/Acquisition/Invoices.t | 8 +- t/db_dependent/Acquisition/OrderFromSubscription.t | 4 +- t/db_dependent/Bookseller.t | 90 +++++++------- t/db_dependent/Letters.t | 7 +- 32 files changed, 263 insertions(+), 170 deletions(-) create mode 100644 Koha/Acquisition/Bookseller.pm diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 53e1fab..f1a1ca1 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -28,10 +28,10 @@ use C4::Suggestions; use C4::Biblio; use C4::Contract; use C4::Debug; -use C4::Bookseller qw(GetBookSellerFromId); use C4::Templates qw(gettemplate); use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; use Time::localtime; use HTML::Entities; @@ -366,7 +366,7 @@ sub GetBasketGroupAsCSV { my $contract = GetContract({ contractnumber => $basket->{contractnumber} }); - my $bookseller = GetBookSellerFromId( $$basket{booksellerid} ); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); my $basketgroup = GetBasketgroup( $$basket{basketgroupid} ); foreach my $order (@orders) { diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index 702b37c..3b1e58f 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -28,7 +28,7 @@ use C4::Bookseller::Contact; # set the version for version checking our $VERSION = 3.07.00.049; our @EXPORT_OK = qw( - GetBookSeller GetBooksellersWithLateOrders GetBookSellerFromId + GetBooksellersWithLateOrders ModBookseller DelBookseller AddBookseller @@ -50,55 +50,6 @@ a bookseller. =head1 FUNCTIONS -=head2 GetBookSeller - -@results = GetBookSeller($searchstring); - -Looks up a book seller. C<$searchstring> is a string to look for in the -book seller's name. - -C<@results> is an array of hash_refs whose keys are the fields of of the -aqbooksellers table in the Koha database. - -=cut - -sub GetBookSeller { - my $searchstring = shift; - $searchstring = q{%} . $searchstring . q{%}; - my $query = " - SELECT aqbooksellers.*, count(*) AS basketcount - FROM aqbooksellers - LEFT JOIN aqbasket ON aqbasket.booksellerid = aqbooksellers.id - WHERE name LIKE ? GROUP BY aqbooksellers.id ORDER BY name - "; - - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare($query); - $sth->execute($searchstring); - my $resultset_ref = $sth->fetchall_arrayref( {} ); - return @{$resultset_ref}; -} - -sub GetBookSellerFromId { - my $id = shift or return; - my $dbh = C4::Context->dbh; - my $vendor = - $dbh->selectrow_hashref( 'SELECT * FROM aqbooksellers WHERE id = ?', - {}, $id ); - if ($vendor) { - ( $vendor->{basketcount} ) = $dbh->selectrow_array( - 'SELECT count(*) FROM aqbasket where booksellerid = ?', - {}, $id ); - ( $vendor->{subscriptioncount} ) = $dbh->selectrow_array( - 'SELECT count(*) FROM subscription WHERE aqbooksellerid = ?', - {}, $id ); - $vendor->{'contacts'} = C4::Bookseller::Contact->get_from_bookseller($id); - } - return $vendor; -} - -#-----------------------------------------------------------------# - =head2 GetBooksellersWithLateOrders %results = GetBooksellersWithLateOrders( $delay, $estimateddeliverydatefrom, $estimateddeliverydateto ); @@ -231,7 +182,7 @@ in the Koha database. It must contain entries for all of the fields. The entry to modify is determined by C<$bookseller-E{id}>. The easiest way to get all of the necessary fields is to look up a -book seller with C<&GetBookseller>, modify what's necessary, then call +book seller with C, modify what's necessary, then call C<&ModBookseller> with the result. =cut diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm new file mode 100644 index 0000000..79b1510 --- /dev/null +++ b/Koha/Acquisition/Bookseller.pm @@ -0,0 +1,124 @@ +package Koha::Acquisition::Bookseller; + +use Modern::Perl; + +use Koha::Database; +use Koha::DateUtils qw( dt_from_string output_pref ); + +use Carp qw( croak ); + +use base qw( Class::Accessor ); + +use C4::Bookseller::Contact; + +sub fetch { + my ( $class, $params ) = @_; + my $id = $params->{id}; + return unless $id; + my $schema = Koha::Database->new->schema; + + my $bookseller = + $schema->resultset('Aqbookseller')->find( { id => $id }, + { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ); + + return unless $bookseller; + + my $self = $class->new( $bookseller ); + $self->contacts; # TODO: This should be generated on demand. + return $self; +} + +sub search { + my ( $class, $params ) = @_; + + croak "Cannot search on other fields than aqbooksellers.name" if $params and grep { $_ !~ /^name$/ } keys %$params; + + my $schema = Koha::Database->new->schema; + + my $search_params; + while ( my ( $field, $value ) = each %$params ) { + if ( $field eq 'name' ) { + # Use "like" if search on name + $search_params->{name} = { -like => "%$value%" }; + } else { + $search_params->{$field} = $value; + } + } + my $rs = $schema->resultset('Aqbookseller')->search( + $search_params, + { order_by => 'name' } + ); + + my @booksellers; + while ( my $b = $rs->next ) { + my $t = Koha::Acquisition::Bookseller->fetch({ id => $b->id }); + push @booksellers, $t; + } + return @booksellers; +} + +sub basket_count { + my ( $self ) = @_; + my $schema = Koha::Database->new->schema; + + return $schema->resultset('Aqbasket')->count( { booksellerid => $self->{id} }); +} + +sub subscription_count { + my ( $self ) = @_; + + my $schema = Koha::Database->new->schema; + + return $schema->resultset('Subscription')->count( { aqbooksellerid => $self->{id} }); +} + +sub contacts { + my ( $self ) = @_; + + return $self->{contacts} if $self->{contacts}; + $self->{contacts} = C4::Bookseller::Contact->get_from_bookseller($self->{id}); + return $self->{contacts}; +} + +sub insert { + my ($self) = @_; + + # if these parameters are missing, we can't continue + for my $key (qw( id )) { + croak "Cannot insert bookseller: Mandatory parameter $key is missing" + unless $self->{$key}; + } + + $self->{quantityreceived} ||= 0; + $self->{entrydate} ||= + output_pref( { dt => dt_from_string, dateformat => 'iso' } ); + + my $schema = Koha::Database->new->schema; + my @columns = $schema->source('Aqorder')->columns; + my $rs = $schema->resultset('Aqorder')->create( + { + map { + exists $self->{$_} ? ( $_ => $self->{$_} ) : () + } @columns + } + ); + $self->{ordernumber} = $rs->id; + + unless ( $self->{parent_ordernumber} ) { + $rs->update( { parent_ordernumber => $self->{ordernumber} } ); + } + + return $self; +} + +# TODO Move code from ModBookseller +sub update { + die "not implemented yet"; +} + +# TODO Move code from DelBookseller +sub delete { + die "not implemented yet"; +} + +1; diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 395cf0f..a013945 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -40,12 +40,12 @@ use C4::Items; use C4::Koha; use C4::Budgets; use C4::Acquisition; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Suggestions; # GetSuggestion use C4::Branch; # GetBranches use C4::Members; use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; my $input = new CGI; my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ @@ -60,7 +60,7 @@ my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ my $cgiparams = $input->Vars; my $op = $cgiparams->{'op'} || ''; my $booksellerid = $input->param('booksellerid'); -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $data; $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", diff --git a/acqui/basket.pl b/acqui/basket.pl index 0ca8e3a..e04024a 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -29,7 +29,6 @@ use CGI; use C4::Acquisition; use C4::Budgets; use C4::Branch; -use C4::Bookseller qw( GetBookSellerFromId); use C4::Contract; use C4::Debug; use C4::Biblio; @@ -83,7 +82,7 @@ my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( my $basket = GetBasket($basketno); $booksellerid = $basket->{booksellerid} unless $booksellerid; -my ($bookseller) = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { $template->param( @@ -519,7 +518,7 @@ sub get_order_infos { if ($line{$key}) { my $order = GetOrder($line{$key}); my $basket = GetBasket($order->{basketno}); - my $bookseller = GetBookSellerFromId($basket->{booksellerid}); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); $line{$key} = { order => $order, basket => $basket, diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index c226ea3..ef62921 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -52,13 +52,13 @@ use C4::Auth; use C4::Output; use CGI; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Budgets qw/ConvertCurrency/; use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Branch qw/GetBranches/; use C4::Members qw/GetMember/; +use Koha::Acquisition::Bookseller; + our $input=new CGI; our ($template, $loggedinuser, $cookie) @@ -144,7 +144,7 @@ sub printbasketgrouppdf{ } my $basketgroup = GetBasketgroup($basketgroupid); - my $bookseller = GetBookSellerFromId($basketgroup->{'booksellerid'}); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basketgroup->{booksellerid} }); my $baskets = GetBasketsByBasketgroup($basketgroupid); my %orders; @@ -255,7 +255,7 @@ if ( $op eq "add" ) { # else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid # the template will know if basketgroup must be displayed or edited, depending on the value of closed key # - my $bookseller = &GetBookSellerFromId($booksellerid); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $basketgroupid = $input->param('basketgroupid'); my $billingplace; my $deliveryplace; @@ -402,7 +402,7 @@ if ( $op eq "add" ) { }else{ # no param : display the list of all basketgroups for a given vendor my $basketgroups = &GetBasketgroups($booksellerid); - my $bookseller = &GetBookSellerFromId($booksellerid); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $baskets = &GetBasketsByBookseller($booksellerid); displaybasketgroups($basketgroups, $bookseller, $baskets); diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index b0ea2e7..eefa450 100755 --- a/acqui/basketheader.pl +++ b/acqui/basketheader.pl @@ -53,9 +53,9 @@ use C4::Auth; use C4::Branch; use C4::Output; use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/; -use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/; use C4::Contract qw/GetContracts/; +use Koha::Acquisition::Bookseller; my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -106,13 +106,13 @@ if ( $op eq 'add_form' ) { }); push(@contractloop, @$contracts); } - my $bookseller = GetBookSellerFromId($booksellerid); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $count = scalar @contractloop; if ( $count > 0) { $template->param(contractloop => \@contractloop, basketcontractnumber => $basket->{'contractnumber'}); } - my @booksellers = C4::Bookseller::GetBookSeller(); + my @booksellers = Koha::Acquisition::Bookseller->search; $template->param( add_form => 1, basketname => $basket->{'basketname'}, basketnote => $basket->{'note'}, diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index c8d70b9..9a2bb25 100755 --- a/acqui/booksellers.pl +++ b/acqui/booksellers.pl @@ -60,10 +60,11 @@ use C4::Output; use CGI; use C4::Acquisition qw/ GetBasketsInfosByBookseller CanUserManageBasket /; -use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /; use C4::Members qw/GetMember/; use C4::Context; +use Koha::Acquisition::Bookseller; + my $query = CGI->new; my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( { template_name => 'acqui/booksellers.tt', @@ -82,9 +83,9 @@ my $allbaskets= $query->param('allbaskets')||0; my @suppliers; if ($booksellerid) { - push @suppliers, GetBookSellerFromId($booksellerid); + push @suppliers, Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); } else { - @suppliers = GetBookSeller($supplier); + @suppliers = Koha::Acquisition::Bookseller->search({ name => $supplier }); } my $supplier_count = @suppliers; diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index 7f6ba88..6642561 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -31,6 +31,9 @@ use C4::Biblio; use C4::Bookseller; use C4::Items; use C4::Search; + +use Koha::Acquisition::Bookseller; + use List::MoreUtils qw/any/; my $input=new CGI; @@ -83,7 +86,7 @@ if ($quantityrec > $origquantityrec ) { $order->{rrp} = $rrp; $order->{ecost} = $ecost; $order->{unitprice} = $unitprice; - my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); if ( $bookseller->{listincgst} ) { if ( not $bookseller->{invoiceincgst} ) { $order->{rrp} = $order->{rrp} * ( 1 + $order->{gstrate} ); diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 33e5592..d7e40b6 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -33,8 +33,9 @@ use CGI; use C4::Auth; use C4::Output; use C4::Acquisition; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Budgets; + +use Koha::Acquisition::Bookseller; use Koha::Misc::Files; my $input = new CGI; @@ -109,7 +110,7 @@ elsif ( $op && $op eq 'delete' ) { my $details = GetInvoiceDetails($invoiceid); -my $bookseller = GetBookSellerFromId($details->{booksellerid}); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $details->{booksellerid} }); my @orders_loop = (); my $orders = $details->{'orders'}; my $qty_total; diff --git a/acqui/invoices.pl b/acqui/invoices.pl index 23cd2ac..4c72d64 100755 --- a/acqui/invoices.pl +++ b/acqui/invoices.pl @@ -34,7 +34,6 @@ use C4::Auth; use C4::Output; use C4::Acquisition qw/GetInvoices/; -use C4::Bookseller qw/GetBookSeller/; use C4::Branch qw/GetBranches/; use C4::Budgets; @@ -87,7 +86,7 @@ if ( $op and $op eq 'do_search' ) { } # Build suppliers list -my @suppliers = GetBookSeller(undef); +my @suppliers = Koha::Acquisition::Bookseller->search; my $suppliers_loop = []; my $suppliername; foreach (@suppliers) { diff --git a/acqui/modordernotes.pl b/acqui/modordernotes.pl index fc9fde3..02bd77b 100755 --- a/acqui/modordernotes.pl +++ b/acqui/modordernotes.pl @@ -32,7 +32,8 @@ use CGI; use C4::Auth; use C4::Output; use C4::Acquisition; -use C4::Bookseller qw( GetBookSellerFromId); + +use Koha::Acquisition::Bookseller; my $input = new CGI; my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { @@ -50,7 +51,7 @@ my $referrer = $input->param('referrer') || $input->referer(); my $type = $input->param('type'); my $order = GetOrder($ordernumber); my $basket = GetBasket($order->{basketno}); -my ($bookseller) = GetBookSellerFromId($basket->{booksellerid}); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); if($op and $op eq 'save') { diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index cfa2e82..8d13915 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -60,7 +60,6 @@ use strict; use C4::Search; use CGI; -use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Biblio; use C4::Auth; use C4::Output; @@ -68,6 +67,8 @@ use C4::Koha; use C4::Members qw/ GetMember /; use C4::Budgets qw/ GetBudgetHierarchy /; +use Koha::Acquisition::Bookseller; + my $input = new CGI; #getting all CGI params into a hash. @@ -79,7 +80,7 @@ my $results_per_page = $params->{'num'} || 20; my $booksellerid = $params->{'booksellerid'}; my $basketno = $params->{'basketno'}; my $sub = $params->{'sub'}; -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); # getting the template my ( $template, $loggedinuser, $cookie ) = get_template_and_user( diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 256175a..ce64f2d 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -76,7 +76,6 @@ use C4::Auth; use C4::Budgets; use C4::Input; -use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Acquisition; use C4::Contract; use C4::Suggestions; # GetSuggestion @@ -92,6 +91,8 @@ use C4::Search qw/FindDuplicate/; #needed for z3950 import: use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; +use Koha::Acquisition::Bookseller; + our $input = new CGI; my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! my $budget_id = $input->param('budget_id') || 0; @@ -131,7 +132,7 @@ if(!$basketno) { our $basket = GetBasket($basketno); $booksellerid = $basket->{booksellerid} unless $booksellerid; -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $contract = GetContract({ contractnumber => $basket->{contractnumber} diff --git a/acqui/newordersubscription.pl b/acqui/newordersubscription.pl index 7004853..04173db 100755 --- a/acqui/newordersubscription.pl +++ b/acqui/newordersubscription.pl @@ -21,12 +21,13 @@ use Modern::Perl; use CGI; use C4::Acquisition; use C4::Auth; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Branch; use C4::Context; use C4::Output; use C4::Serials; +use Koha::Acquisition::Bookseller; + my $query = new CGI; my $title = $query->param('title_filter'); my $ISSN = $query->param('ISSN_filter'); @@ -52,7 +53,7 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( my $basket = GetBasket($basketno); $booksellerid = $basket->{booksellerid} unless $booksellerid; -my ($bookseller) = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my @subscriptions; if ($searched) { diff --git a/acqui/newordersuggestion.pl b/acqui/newordersuggestion.pl index 21ac988..850370b 100755 --- a/acqui/newordersuggestion.pl +++ b/acqui/newordersuggestion.pl @@ -95,9 +95,10 @@ use CGI; use C4::Auth; # get_template_and_user use C4::Output; use C4::Suggestions; -use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Biblio; +use Koha::Acquisition::Bookseller; + my $input = new CGI; # getting the CGI params @@ -135,7 +136,7 @@ my $suggestions_loop = title => $title, publishercode => $publishercode, STATUS => 'ACCEPTED'}); -my $vendor = GetBookSellerFromId($booksellerid); +my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); $template->param( suggestions_loop => $suggestions_loop, basketno => $basketno, diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index ca6de52..878d77a 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -68,7 +68,6 @@ use C4::Acquisition; use C4::Auth; use C4::Output; use C4::Dates qw/format_date/; -use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Budgets qw/ GetBudget GetBudgetHierarchy CanUserUseBudget GetBudgetPeriods /; use C4::Members; use C4::Branch; # GetBranches @@ -76,6 +75,8 @@ use C4::Items; use C4::Biblio; use C4::Suggestions; +use Koha::Acquisition::Bookseller; + my $input = new CGI; @@ -89,7 +90,7 @@ my $ordernumber = $input->param('ordernumber'); $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new(); -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $results; $results = SearchOrders({ ordernumber => $ordernumber diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 00e6499..65675e2 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -60,7 +60,6 @@ use warnings; use C4::Auth; use C4::Acquisition; use C4::Budgets; -use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Biblio; use C4::Items; use CGI; @@ -68,6 +67,9 @@ use C4::Output; use C4::Dates qw/format_date format_date_in_iso/; use C4::Suggestions; use C4::Reserves qw/GetReservesFromBiblionumber/; + +use Koha::Acquisition::Bookseller; + use JSON; my $input=new CGI; @@ -145,7 +147,7 @@ unless( $invoiceid and $invoice->{invoiceid} ) { } my $booksellerid = $invoice->{booksellerid}; -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; my $datereceived = C4::Dates->new(); diff --git a/acqui/parcels.pl b/acqui/parcels.pl index acf2edf..e3b8f5f 100755 --- a/acqui/parcels.pl +++ b/acqui/parcels.pl @@ -74,9 +74,10 @@ use C4::Output; use C4::Dates qw/format_date/; use C4::Acquisition; -use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Budgets; +use Koha::Acquisition::Bookseller; + my $input = CGI->new; my $booksellerid = $input->param('booksellerid'); my $order = $input->param('orderby') || 'shipmentdate desc'; @@ -140,7 +141,7 @@ if ($op and $op eq 'confirm') { } } -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my @parcels = GetInvoices( supplierid => $booksellerid, invoicenumber => $code, diff --git a/acqui/supplier.pl b/acqui/supplier.pl index 0f27991..ba1ee53 100755 --- a/acqui/supplier.pl +++ b/acqui/supplier.pl @@ -48,10 +48,12 @@ use C4::Biblio; use C4::Output; use CGI; -use C4::Bookseller qw( GetBookSellerFromId DelBookseller ); +use C4::Bookseller qw( DelBookseller ); use C4::Bookseller::Contact; use C4::Budgets; +use Koha::Acquisition::Bookseller; + my $query = CGI->new; my $op = $query->param('op') || 'display'; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -66,7 +68,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $booksellerid = $query->param('booksellerid'); my $supplier = {}; if ($booksellerid) { - $supplier = GetBookSellerFromId($booksellerid); + $supplier = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); foreach ( keys %{$supplier} ) { $template->{'VARS'}->{$_} = $supplier->{$_}; } diff --git a/acqui/transferorder.pl b/acqui/transferorder.pl index d82ce20..76d4f24 100755 --- a/acqui/transferorder.pl +++ b/acqui/transferorder.pl @@ -26,7 +26,6 @@ use C4::Auth; use C4::Output; use C4::Context; use C4::Acquisition; -use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/; use C4::Members; use C4::Dates qw/format_date_in_iso/; use Date::Calc qw/Today/; @@ -55,12 +54,12 @@ if($order) { $bookselleridfrom = $basket->{booksellerid} if $basket; } -my $booksellerfrom = GetBookSellerFromId($bookselleridfrom); +my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridfrom }); my $booksellerfromname; if($booksellerfrom){ $booksellerfromname = $booksellerfrom->{name}; } -my $booksellerto = GetBookSellerFromId($bookselleridto); +my $booksellerto = Koha::Acquisition::Bookseller->fetch({ id => $bookselleridto }); my $booksellertoname; if($booksellerto){ $booksellertoname = $booksellerto->{name}; @@ -70,7 +69,7 @@ if( $basketno && $ordernumber) { # Transfer order and exit my $order = GetOrder( $ordernumber ); my $basket = GetBasket($order->{basketno}); - my $booksellerfrom = GetBookSellerFromId($basket->{booksellerid}); + my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); my $bookselleridfrom = $booksellerfrom->{id}; TransferOrder($ordernumber, $basketno); @@ -80,7 +79,7 @@ if( $basketno && $ordernumber) { # Show open baskets for this bookseller my $order = GetOrder( $ordernumber ); my $basketfrom = GetBasket( $order->{basketno} ); - my $booksellerfrom = GetBookSellerFromId( $basketfrom->{booksellerid} ); + my $booksellerfrom = Koha::Acquisition::Bookseller->fetch({ id => $basketfrom->{booksellerid} }); $booksellerfromname = $booksellerfrom->{name}; my $baskets = GetBasketsByBookseller( $bookselleridto ); my $basketscount = scalar @$baskets; @@ -117,7 +116,7 @@ if( $basketno && $ordernumber) { # Search for booksellers to transfer from/to $op = '' unless $op; if( $op eq "do_search" ) { - my @booksellers = GetBookSeller($query); + my @booksellers = Koha::Acquisition::Bookseller->search({ name => $query }); $template->param( query => $query, do_search => 1, diff --git a/acqui/uncertainprice.pl b/acqui/uncertainprice.pl index 0b680d8..8caff1c 100755 --- a/acqui/uncertainprice.pl +++ b/acqui/uncertainprice.pl @@ -51,11 +51,12 @@ use C4::Auth; use C4::Output; use CGI; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Bookseller::Contact; use C4::Acquisition qw/SearchOrders GetOrder ModOrder/; use C4::Biblio qw/GetBiblioData/; +use Koha::Acquisition::Bookseller; + my $input=new CGI; my ($template, $loggedinuser, $cookie) @@ -71,7 +72,7 @@ my $booksellerid = $input->param('booksellerid'); my $basketno = $input->param('basketno'); my $op = $input->param('op'); my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or everyone orders -my $bookseller = &GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); #show all orders that have uncertain price for the bookseller my $pendingorders = SearchOrders({ diff --git a/acqui/z3950_search.pl b/acqui/z3950_search.pl index f87354f..e30901a 100755 --- a/acqui/z3950_search.pl +++ b/acqui/z3950_search.pl @@ -28,7 +28,8 @@ use C4::Output; use C4::Context; use C4::Breeding; use C4::Koha; -use C4::Bookseller qw/ GetBookSellerFromId /; + +use Koha::Acquisition::Bookseller; my $input = new CGI; my $biblionumber = $input->param('biblionumber')||0; @@ -62,7 +63,7 @@ foreach my $thisframeworkcode ( keys %$frameworks ) { push @frameworkcodeloop, \%row; } -my $vendor = GetBookSellerFromId($booksellerid); +my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { diff --git a/admin/aqcontract.pl b/admin/aqcontract.pl index a286716..8997c31 100755 --- a/admin/aqcontract.pl +++ b/admin/aqcontract.pl @@ -27,15 +27,16 @@ use C4::Context; use C4::Auth; use C4::Output; use C4::Dates qw/format_date format_date_in_iso/; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Contract; +use Koha::Acquisition::Bookseller; + my $input = new CGI; my $contractnumber = $input->param('contractnumber'); my $booksellerid = $input->param('booksellerid'); my $op = $input->param('op') || 'list'; -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "admin/aqcontract.tt", diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index eed1f68..1893a33 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -27,7 +27,6 @@ use C4::Biblio; use C4::Items; use C4::Branch; use C4::Acquisition; -use C4::Bookseller qw(GetBookSellerFromId); use C4::Output; use C4::Auth; use C4::Serials; @@ -36,6 +35,8 @@ use C4::Members; # to use GetMember use C4::Search; # enabled_staff_search_views use C4::Members qw/GetHideLostItemsPreference/; use C4::Reserves qw(GetReservesFromBiblionumber); + +use Koha::Acquisition::Bookseller; use Koha::DateUtils; my $query=new CGI; @@ -161,7 +162,7 @@ foreach my $item (@items){ $item->{'orderdate'} = $order->{'entrydate'}; if ($item->{'basketno'}){ my $basket = GetBasket($item->{'basketno'}); - my $bookseller = GetBookSellerFromId($basket->{'booksellerid'}); + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); $item->{'vendor'} = $bookseller->{'name'}; } $item->{'invoiceid'} = $order->{'invoiceid'}; diff --git a/serials/acqui-search-result.pl b/serials/acqui-search-result.pl index c956439..319b852 100755 --- a/serials/acqui-search-result.pl +++ b/serials/acqui-search-result.pl @@ -48,7 +48,8 @@ use C4::Output; use CGI; use C4::Acquisition qw( SearchOrders ); use C4::Dates qw/format_date/; -use C4::Bookseller qw( GetBookSeller ); + +use Koha::Acquisition::Bookseller; my $query=new CGI; my ($template, $loggedinuser, $cookie) @@ -61,7 +62,7 @@ my ($template, $loggedinuser, $cookie) }); my $supplier=$query->param('supplier'); -my @suppliers = GetBookSeller($supplier); +my @suppliers = Koha::Acquisition::Bookseller->search({ name => $supplier }); #my $count = scalar @suppliers; #build result page diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index 0cceb34..1a4a14d 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -19,7 +19,6 @@ use Modern::Perl; use CGI; use C4::Acquisition; use C4::Auth; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Budgets; use C4::Koha; use C4::Dates qw/format_date/; @@ -27,6 +26,9 @@ use C4::Serials; use C4::Output; use C4::Context; use C4::Search qw/enabled_staff_search_views/; + +use Koha::Acquisition::Bookseller; + use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/; use Carp; @@ -117,7 +119,7 @@ if ( defined $subscriptionid ) { my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid; if ( defined $lastOrderNotReceived ) { my $basket = GetBasket $lastOrderNotReceived->{basketno}; - my $bookseller = GetBookSellerFromId $basket->{booksellerid}; + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); ( $tmpl_infos->{valuegsti_ordered}, $tmpl_infos->{valuegste_ordered} ) = get_value_with_gst_params ( $lastOrderNotReceived->{ecost}, $lastOrderNotReceived->{gstrate}, $bookseller ); $tmpl_infos->{valuegsti_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegsti_ordered} ); $tmpl_infos->{valuegste_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegste_ordered} ); @@ -127,7 +129,7 @@ if ( defined $subscriptionid ) { } if ( defined $lastOrderReceived ) { my $basket = GetBasket $lastOrderReceived->{basketno}; - my $bookseller = GetBookSellerFromId $basket->{booksellerid}; + my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} }); ( $tmpl_infos->{valuegsti_spent}, $tmpl_infos->{valuegste_spent} ) = get_value_with_gst_params ( $lastOrderReceived->{unitprice}, $lastOrderReceived->{gstrate}, $bookseller ); $tmpl_infos->{valuegsti_spent} = sprintf( "%.2f", $tmpl_infos->{valuegsti_spent} ); $tmpl_infos->{valuegste_spent} = sprintf( "%.2f", $tmpl_infos->{valuegste_spent} ); diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 8c7b287..42da409 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -6,9 +6,7 @@ use Modern::Perl; use POSIX qw(strftime); -use C4::Bookseller qw( GetBookSellerFromId ); - -use Test::More tests => 75; +use Test::More tests => 76; BEGIN { use_ok('C4::Acquisition'); @@ -17,6 +15,7 @@ BEGIN { use_ok('C4::Budgets'); use_ok('C4::Bookseller'); use_ok('Koha::Acquisition::Order'); + use_ok('Koha::Acquisition::Bookseller'); } # Sub used for testing C4::Acquisition subs returning order(s): @@ -119,7 +118,7 @@ my $booksellerid = C4::Bookseller::AddBookseller( } ); -my $booksellerinfo = C4::Bookseller::GetBookSellerFromId($booksellerid); +my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); is( $booksellerinfo->{deliverytime}, 5, 'set deliverytime when creating vendor (Bug 10556)' ); diff --git a/t/db_dependent/Acquisition/Invoices.t b/t/db_dependent/Acquisition/Invoices.t index eac6a23..a1ea6b5 100644 --- a/t/db_dependent/Acquisition/Invoices.t +++ b/t/db_dependent/Acquisition/Invoices.t @@ -3,13 +3,13 @@ # This Koha test module is a stub! # Add more tests here!!! -use strict; -use warnings; +use Modern::Perl; -use C4::Bookseller qw( GetBookSellerFromId ); use C4::Biblio qw( AddBiblio ); +use C4::Bookseller qw( AddBookseller ); use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; use Test::More tests => 22; @@ -32,7 +32,7 @@ my $booksellerid = C4::Bookseller::AddBookseller( } ); -my $booksellerinfo = GetBookSellerFromId( $booksellerid ); +my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $basketno = NewBasket($booksellerid, 1); my $basket = GetBasket($basketno); diff --git a/t/db_dependent/Acquisition/OrderFromSubscription.t b/t/db_dependent/Acquisition/OrderFromSubscription.t index 438c3fd..e7600ca 100644 --- a/t/db_dependent/Acquisition/OrderFromSubscription.t +++ b/t/db_dependent/Acquisition/OrderFromSubscription.t @@ -1,10 +1,10 @@ use Modern::Perl; -use Test::More tests => 12; -use Data::Dumper; +use Test::More tests => 13; use_ok('C4::Acquisition'); use_ok('C4::Biblio'); +use_ok('C4::Bookseller'); use_ok('C4::Budgets'); use_ok('C4::Serials'); diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index 023ad45..b7860df 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 86; +use Test::More tests => 88; use Test::MockModule; use Test::Warn; @@ -18,6 +18,7 @@ use Koha::Acquisition::Order; BEGIN { use_ok('C4::Bookseller'); + use_ok('Koha::Acquisition::Bookseller'); } can_ok( @@ -25,8 +26,6 @@ can_ok( 'C4::Bookseller', qw( AddBookseller DelBookseller - GetBookSeller - GetBookSellerFromId GetBooksellersWithLateOrders ModBookseller ) ); @@ -43,7 +42,7 @@ $dbh->do(q|DELETE FROM aqbooksellers|); $dbh->do(q|DELETE FROM subscription|); #Test AddBookseller -my $count = scalar( C4::Bookseller::GetBookSeller('') ); +my $count = scalar( Koha::Acquisition::Bookseller->search() ); my $sample_supplier1 = { name => 'Name1', address1 => 'address1_1', @@ -92,31 +91,30 @@ my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2); like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" ); like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" ); -is( scalar( C4::Bookseller::GetBookSeller('') ), +my @b = Koha::Acquisition::Bookseller->search(); +is ( scalar(@b), $count + 2, "Supplier1 and Supplier2 have been added" ); #Test DelBookseller my $del = C4::Bookseller::DelBookseller($id_supplier1); is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " ); -is( C4::Bookseller::GetBookSellerFromId($id_supplier1), - undef, "Supplier1 has been deleted - id_supplier1 doesnt exist anymore" ); +my $b = Koha::Acquisition::Bookseller->fetch({id => $id_supplier1}); +is( $b, + undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" ); #Test GetBookSeller -my @bookseller2 = C4::Bookseller::GetBookSeller( $sample_supplier2->{name} ); +my @bookseller2 = Koha::Acquisition::Bookseller->search({name => $sample_supplier2->{name} }); is( scalar(@bookseller2), 1, "Get only Supplier2" ); $bookseller2[0] = field_filter( $bookseller2[0] ); -delete $bookseller2[0]->{basketcount}; $sample_supplier2->{id} = $id_supplier2; is_deeply( $bookseller2[0], $sample_supplier2, - "GetBookSeller returns the right informations about $sample_supplier2" ); + "Koha::Acquisition::Bookseller->search returns the right informations about $sample_supplier2" ); $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); -my @booksellers = C4::Bookseller::GetBookSeller('') - ; #NOTE :without params, it returns all the booksellers +my @booksellers = Koha::Acquisition::Bookseller->search(); #NOTE :without params, it returns all the booksellers for my $i ( 0 .. scalar(@booksellers) - 1 ) { $booksellers[$i] = field_filter( $booksellers[$i] ); - delete $booksellers[$i]->{basketcount}; } $sample_supplier1->{id} = $id_supplier1; @@ -125,33 +123,30 @@ my @tab = ( $sample_supplier1, $sample_supplier2 ); is_deeply( \@booksellers, \@tab, "Returns right fields of Supplier1 and Supplier2" ); -#Test basketcount -my @bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} ); -#FIXME : if there is 0 basket, GetBookSeller returns 1 as basketcount -#is( $bookseller1[0]->{basketcount}, 0, 'Supplier1 has 0 basket' ); +#Test basket_count +my @bookseller1 = Koha::Acquisition::Bookseller->search({name => $sample_supplier1->{name} }); +is( $bookseller1[0]->basket_count, 0, 'Supplier1 has 0 basket' ); my $basketno1 = C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' ); my $basketno2 = C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' ); -@bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} ); -is( $bookseller1[0]->{basketcount}, 2, 'Supplier1 has 2 baskets' ); +@bookseller1 = Koha::Acquisition::Bookseller::search({ name => $sample_supplier1->{name} }); +is( $bookseller1[0]->basket_count, 2, 'Supplier1 has 2 baskets' ); -#Test GetBookSellerFromId -my $bookseller1fromid = C4::Bookseller::GetBookSellerFromId(); +#Test Koha::Acquisition::Bookseller->new using id +my $bookseller1fromid = Koha::Acquisition::Bookseller->fetch; is( $bookseller1fromid, undef, - "GetBookSellerFromId returns undef if no id given" ); -$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); + "fetch returns undef if no id given" ); +$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); $bookseller1fromid = field_filter($bookseller1fromid); -delete $bookseller1fromid->{basketcount}; -delete $bookseller1fromid->{subscriptioncount}; is_deeply( $bookseller1fromid, $sample_supplier1, "Get Supplier1 (GetBookSellerFromId)" ); -#Test basketcount -$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); -is( $bookseller1fromid->{basketcount}, 2, 'Supplier1 has 2 baskets' ); +#Test basket_count +$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); +is( $bookseller1fromid->basket_count, 2, 'Supplier1 has 2 baskets' ); -#Test subscriptioncount +#Test subscription_count my $dt_today = dt_from_string; my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 }); @@ -178,8 +173,8 @@ $bib->append_fields( MARC::Field->new('500', ' ', ' ', a => 'bib notes'), ); my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, ''); -$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); -is( $bookseller1fromid->{subscriptioncount}, +$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); +is( $bookseller1fromid->subscription_count, 0, 'Supplier1 has 0 subscription' ); my $id_subscription1 = NewSubscription( @@ -203,8 +198,8 @@ my $id_subscription2 = NewSubscription( undef, undef, 0, undef, '2013-07-31', 0 ); -$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); -is( $bookseller1fromid->{subscriptioncount}, +$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); +is( $bookseller1fromid->subscription_count, 2, 'Supplier1 has 2 subscriptions' ); #Test ModBookseller @@ -235,7 +230,7 @@ is( $modif1, undef, "ModBookseller returns undef if no params given - Nothing happened" ); $modif1 = C4::Bookseller::ModBookseller($sample_supplier2); is( $modif1, 1, "ModBookseller modifies only the supplier2" ); -is( scalar( C4::Bookseller::GetBookSeller('') ), +is( scalar( Koha::Acquisition::Bookseller->search ), $count + 2, "Supplier2 has been modified - Nothing added" ); $modif1 = C4::Bookseller::ModBookseller( @@ -695,17 +690,18 @@ my $booksellerid = C4::Bookseller::AddBookseller( ] ); -@booksellers = C4::Bookseller::GetBookSeller('my vendor'); +@booksellers = Koha::Acquisition::Bookseller->search({ name => 'my vendor' }); ok( ( grep { $_->{'id'} == $booksellerid } @booksellers ), - 'GetBookSeller returns correct record when passed a name' + 'Koha::Acquisition::Bookseller->search returns correct record when passed a name' ); -my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' ); is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' ); -is( ref $bookseller->{'contacts'}, - 'ARRAY', 'GetBookSellerFromId returns arrayref of contacts' ); +my $contacts = $bookseller->contacts; +is( ref $bookseller->contacts, + 'ARRAY', 'Koha::Acquisition::Bookseller->fetch returns arrayref of contacts' ); is( ref $bookseller->{'contacts'}->[0], 'C4::Bookseller::Contact', @@ -720,27 +716,29 @@ $bookseller->{'name'} = 'your vendor'; $bookseller->{'contacts'}->[0]->phone('654321'); C4::Bookseller::ModBookseller($bookseller); -$bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); +$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +$contacts = $bookseller->contacts; is( $bookseller->{'name'}, 'your vendor', 'Successfully changed name of vendor' ); -is( $bookseller->{'contacts'}->[0]->phone, +is( $contacts->[0]->phone, '654321', 'Successfully changed contact phone number by modifying bookseller hash' ); -is( scalar @{ $bookseller->{'contacts'} }, +is( scalar @$contacts, 1, 'Only one contact after modification' ); C4::Bookseller::ModBookseller( $bookseller, [ { name => 'John Jacob Jingleheimer Schmidt' } ] ); -$bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); +$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +$contacts = $bookseller->contacts; is( - $bookseller->{'contacts'}->[0]->name, + $contacts->[0]->name, 'John Jacob Jingleheimer Schmidt', 'Changed name of contact' ); -is( $bookseller->{'contacts'}->[0]->phone, +is( $contacts->[0]->phone, undef, 'Removed phone number from contact' ); -is( scalar @{ $bookseller->{'contacts'} }, +is( scalar @$contacts, 1, 'Only one contact after modification' ); #End transaction diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 8d7991e..0bf199d 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -44,6 +44,7 @@ use_ok('C4::Letters'); use t::lib::Mocks; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Order; +use Koha::Acquisition::Bookseller; my $dbh = C4::Context->dbh; @@ -326,10 +327,10 @@ warning_like { "SendAlerts prints a warning"; is($err->{'error'}, 'no_email', "Trying to send an alert when there's no e-mail results in an error"); -my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); -$bookseller->{'contacts'}->[0]->email('testemail@mydomain.com'); +my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); +$bookseller->contacts->[0]->email('testemail@mydomain.com'); C4::Bookseller::ModBookseller($bookseller); -$bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); +$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); warning_is { $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) } -- 1.7.10.4