|
Lines 20-37
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
use FindBin qw( $Bin ); |
21 |
use FindBin qw( $Bin ); |
| 22 |
|
22 |
|
| 23 |
use Test::More tests => 2; |
23 |
use Test::More tests => 3; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
| 26 |
|
26 |
|
| 27 |
use t::lib::Mocks; |
27 |
use t::lib::Mocks; |
|
|
28 |
use t::lib::Mocks::Logger; |
| 28 |
use t::lib::TestBuilder; |
29 |
use t::lib::TestBuilder; |
| 29 |
|
30 |
|
| 30 |
use Koha::EDI qw(process_quote); |
31 |
use Koha::EDI qw(process_quote process_invoice); |
| 31 |
use Koha::Edifact::Transport; |
32 |
use Koha::Edifact::Transport; |
| 32 |
|
33 |
|
| 33 |
my $schema = Koha::Database->new->schema; |
34 |
my $schema = Koha::Database->new->schema; |
| 34 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $builder = t::lib::TestBuilder->new; |
|
|
36 |
my $logger = t::lib::Mocks::Logger->new(); |
| 35 |
|
37 |
|
| 36 |
subtest 'process_quote' => sub { |
38 |
subtest 'process_quote' => sub { |
| 37 |
plan tests => 7; |
39 |
plan tests => 7; |
|
Lines 287-291
subtest '_handle_008_field' => sub {
Link Here
|
| 287 |
|
289 |
|
| 288 |
is( $record_field->{_data}, undef, 'Field has not been added' ); |
290 |
is( $record_field->{_data}, undef, 'Field has not been added' ); |
| 289 |
|
291 |
|
|
|
292 |
$logger->clear(); |
| 290 |
$schema->storage->txn_rollback; |
293 |
$schema->storage->txn_rollback; |
| 291 |
} |
294 |
}; |
|
|
295 |
|
| 296 |
subtest 'process_invoice' => sub { |
| 297 |
plan tests => 11; |
| 298 |
|
| 299 |
$schema->storage->txn_begin; |
| 300 |
|
| 301 |
# Add test EDI matching ean of test invoice file and ensure no plugins so we trigger core functions |
| 302 |
my $account = $builder->build( |
| 303 |
{ |
| 304 |
source => 'VendorEdiAccount', |
| 305 |
value => { |
| 306 |
description => 'test vendor', |
| 307 |
transport => 'FILE', |
| 308 |
plugin => '', |
| 309 |
san => '5013546027173' |
| 310 |
} |
| 311 |
} |
| 312 |
); |
| 313 |
|
| 314 |
# Create a test basket and orders matching the invoice message |
| 315 |
my $basket = $builder->build_object( |
| 316 |
{ |
| 317 |
class => 'Koha::Acquisition::Baskets', |
| 318 |
value => { |
| 319 |
booksellerid => $account->{vendor_id}, |
| 320 |
basketname => 'Test Basket', |
| 321 |
} |
| 322 |
} |
| 323 |
); |
| 324 |
my $order1 = $builder->build_object( |
| 325 |
{ |
| 326 |
class => 'Koha::Acquisition::Orders', |
| 327 |
value => { |
| 328 |
basketno => $basket->id, |
| 329 |
orderstatus => 'new', |
| 330 |
biblionumber => undef, |
| 331 |
} |
| 332 |
} |
| 333 |
); |
| 334 |
my $ordernumber1 = $order1->ordernumber; |
| 335 |
|
| 336 |
my $order2 = $builder->build_object( |
| 337 |
{ |
| 338 |
class => 'Koha::Acquisition::Orders', |
| 339 |
value => { |
| 340 |
basketno => $basket->id, |
| 341 |
orderstatus => 'new', |
| 342 |
} |
| 343 |
} |
| 344 |
); |
| 345 |
my $ordernumber2 = $order2->ordernumber; |
| 346 |
|
| 347 |
# Add test invoice file to the database for testing |
| 348 |
my $dirname = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} ); |
| 349 |
my $filename = 'INVOICE_S.CEI'; |
| 350 |
ok( -e $dirname . $filename, 'File INVOICE.CEI found' ); |
| 351 |
|
| 352 |
my $trans = Koha::Edifact::Transport->new( $account->{id} ); |
| 353 |
$trans->working_directory($dirname); |
| 354 |
|
| 355 |
my $mhash = $trans->message_hash(); |
| 356 |
$mhash->{message_type} = 'INVOICE'; |
| 357 |
$trans->ingest( $mhash, $filename ); |
| 358 |
|
| 359 |
my $invoice_message = $schema->resultset('EdifactMessage')->find( { filename => $filename } ); |
| 360 |
my $raw_msg = $invoice_message->raw_msg; |
| 361 |
$raw_msg =~ s/P12345/$ordernumber1/g; |
| 362 |
$raw_msg =~ s/P54321/$ordernumber2/g; |
| 363 |
$invoice_message->update( { raw_msg => $raw_msg } ); |
| 364 |
|
| 365 |
# Process the test invoice file |
| 366 |
warnings_exist { process_invoice($invoice_message) } |
| 367 |
[ |
| 368 |
{ carped => qr/Cannot find vendor with ean.*/i }, |
| 369 |
], |
| 370 |
'Invoice processed, with warnings, without dieing'; |
| 371 |
|
| 372 |
$logger->trace_like( qr/Adding invoice:.*/, "Trace recorded adding invoice" ) |
| 373 |
->trace_like( qr/Added as invoiceno.*/, "Trace recorded invoice added" )->error_is( |
| 374 |
'Skipping invoice line, no associated ordernumber', |
| 375 |
"Received expected log line for missing ordernumber line" |
| 376 |
)->error_like( |
| 377 |
qr/Skipping invoice line, no order found for.*/, |
| 378 |
'Received expected log line for unmatched ordernumber line' |
| 379 |
)->error_like( |
| 380 |
qr/Skipping invoice line, no bibliographic.*/, |
| 381 |
'Received expected log line for unmatched biblionumber line' |
| 382 |
)->trace_like( |
| 383 |
qr/Receipting order:.*/, |
| 384 |
'Trace recorded invoice receipted' |
| 385 |
)->trace_like( |
| 386 |
qr/Updating bib:.*/, |
| 387 |
'Trace recorded bib updated' |
| 388 |
)->clear(); |
| 389 |
|
| 390 |
my $invoice3 = Koha::Acquisition::Invoices->search( { invoicenumber => 'INV00003' }, { rows => 1 } )->single; |
| 391 |
ok( $invoice3, "Invoice added to database" ); |
| 392 |
is( $invoice3->booksellerid, $account->{vendor_id}, 'Invoice has test booksellerid' ); |
| 393 |
|
| 394 |
$schema->storage->txn_rollback; |
| 395 |
}; |
| 292 |
- |
|
|