Koha/t/db_dependent/Acquisition/GetBasketAsCSV.t
Jonathan Druart 3aeb1fc7e8 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 <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-09-07 15:03:04 -03:00

83 lines
2.5 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use CGI;
use Test::More tests => 3;
use C4::Acquisition;
use C4::Biblio;
use Koha::Database;
use Koha::CsvProfile;
use Koha::Acquisition::Orders;
my $schema = Koha::Database->new()->schema();
$schema->storage->txn_begin();
my $query = CGI->new();
my $vendor = Koha::Acquisition::Bookseller->new({
name => 'my vendor',
address1 => 'vendor address',
active => 1,
deliverytime => 5,
})->store;
my $budget_id = C4::Budgets::AddBudget({
budget_code => 'my_budget_code',
budget_name => 'My budget name',
});
my $budget = C4::Budgets::GetBudget( $budget_id );
my $csv_profile = Koha::CsvProfile->new({
profile => 'my user profile',
type => 'export_basket',
csv_separator => ',',
content => 'autor=biblio.author|title=biblio.title|quantity=aqorders.quantity',
})->store;
my $csv_profile2 = Koha::CsvProfile->new({
profile => 'my user profile',
type => 'export_basket',
csv_separator => ',',
content => 'biblio.author | title = biblio.title|quantity=aqorders.quantity',
})->store;
my $basketno;
$basketno = NewBasket($vendor->id, 1);
my $biblio = MARC::Record->new();
$biblio->append_fields(
MARC::Field->new( '100', ' ', ' ', a => 'King, Stephen' ),
MARC::Field->new( '245', ' ', ' ', a => 'Test Record' ),
);
my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
my $order = Koha::Acquisition::Order->new({
basketno => $basketno,
quantity => 3,
biblionumber => $biblionumber,
budget_id => $budget_id,
entrydate => '2016-01-02',
})->store;
# Use user CSV profile
my $basket_csv1 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile->export_format_id);
is($basket_csv1, 'autor,title,quantity
"King, Stephen","Test Record",3
', 'CSV should be generated with user profile');
# 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,,"",""
', 'CSV should be generated with default template');
my $basket_csv3 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile2->export_format_id);
is($basket_csv3, 'biblio.author,title,quantity
"King, Stephen","Test Record",3
', 'CSV should be generated with user profile which does not have all headers defined');
$schema->storage->txn_rollback();