View | Details | Raw Unified | Return to bug 38423
Collapse All | Expand All

(-)a/Koha/EDI.pm (-1 / +1 lines)
Lines 290-296 sub process_invoice { Link Here
290
                )->single;
290
                )->single;
291
            }
291
            }
292
            if ( !$vendor_acct ) {
292
            if ( !$vendor_acct ) {
293
                carp "Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in $invoice_message->filename";
293
                carp "Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in ".$invoice_message->filename;
294
                next;
294
                next;
295
            }
295
            }
296
            $invoice_message->edi_acct( $vendor_acct->id );
296
            $invoice_message->edi_acct( $vendor_acct->id );
(-)a/t/db_dependent/Koha/EDI.t (-3 / +107 lines)
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.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
};
(-)a/t/edi_testfiles/INVOICE.CEI (-1 / +2 lines)
Line 0 Link Here
0
- 
1
UNA:+.? 'UNB+UNOC:3+5013546027173+5013546098818+230101:0000+0000000002'UNH+00003+INVOIC:D:96A:UN'BGM+380+INV00003+9'DTM+137:20231210:102'NAD+BY+12345::9'NAD+SU+5013546027173::9'LIN+1++987654321:EN'QTY+47:5'PRI+AAA:9.99'MOA+203:49.95'LIN+2++987654321:EN'QTY+47:5'PRI+AAA:9.99'MOA+203:49.95'RFF+LI:P28837'LIN+3++999999999:EN'QTY+47:10'PRI+AAA:15.00'MOA+203:150.00'RFF+LI:P12345'LIN+4++123456789:EN'QTY+47:1'PRI+AAA:30.00'MOA+203:600.00'RFF+LI:P54321'LIN+5++987654123:EN'QTY+47:1'PRI+AAA:5.00'MOA+203:5.00'RFF+LI:P54321'UNS+S'CNT+4:4'UNT+15+00003'UNZ+1+0000000002'
2
UNA:+.? 'UNB+UNOC:3+9999999999999+5013546098818+230101:0000+0000000001'UNH+00002+INVOIC:D:96A:UN'BGM+380+INV00002+9'DTM+137:20231210:102'NAD+BY+54321::9'NAD+SU+9999999999999::9'UNS+S'CNT+1:1'UNT+11+00002'

Return to bug 38423