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

(-)a/t/db_dependent/Koha/EDI.t (-3 / +95 lines)
Lines 38-44 my $builder = t::lib::TestBuilder->new; Link Here
38
my $logger  = t::lib::Mocks::Logger->new();
38
my $logger  = t::lib::Mocks::Logger->new();
39
39
40
subtest 'process_quote' => sub {
40
subtest 'process_quote' => sub {
41
    plan tests => 5;
41
    plan tests => 6;
42
42
43
    $schema->storage->txn_begin;
43
    $schema->storage->txn_begin;
44
44
Lines 223-229 subtest 'process_quote' => sub { Link Here
223
        $schema->storage->txn_rollback;
223
        $schema->storage->txn_rollback;
224
    };
224
    };
225
225
226
    # Test 2: Auto Orders Processing
226
    # Test 2: Multiple Message EAN Handling
227
    subtest 'multiple_message_ean_handling' => sub {
228
        plan tests => 4;
229
230
        $schema->storage->txn_begin;
231
232
        my $account = $builder->build(
233
            {
234
                source => 'VendorEdiAccount',
235
                value  => {
236
                    description    => 'multi-message test vendor',
237
                    transport      => 'FILE',
238
                    plugin         => '',
239
                    san            => $test_san,
240
                    orders_enabled => 1,
241
                    auto_orders    => 1,
242
                }
243
            }
244
        );
245
246
        # Create EANs that match the QUOTES_BIG.CEQ file
247
        my $ean1 = $builder->build(
248
            {
249
                source => 'EdifactEan',
250
                value  => {
251
                    description => 'library 1 ean',
252
                    branchcode  => undef,
253
                    ean         => '5013546098818'    # First EAN from QUOTES_BIG.CEQ
254
                }
255
            }
256
        );
257
        my $ean2 = $builder->build(
258
            {
259
                source => 'EdifactEan',
260
                value  => {
261
                    description => 'library 2 ean',
262
                    branchcode  => undef,
263
                    ean         => '5412345000013'    # Second EAN from QUOTES_BIG.CEQ
264
                }
265
            }
266
        );
267
268
        # Setup fund
269
        my $fund = $builder->build(
270
            {
271
                source => 'Aqbudget',
272
                value  => {
273
                    budget_code      => 'REF',
274
                    budget_period_id => $active_period->{budget_period_id}
275
                }
276
            }
277
        );
278
279
        # Use the existing multi-message test file
280
        my $filename = 'QUOTES_BIG.CEQ';
281
        ok( -e $dirname . $filename, 'File QUOTES_BIG.CEQ found' );
282
283
        my $trans = Koha::Edifact::Transport->new( $account->{id} );
284
        $trans->working_directory($dirname);
285
286
        my $mhash = $trans->message_hash();
287
        $mhash->{message_type} = 'QUOTE';
288
        $trans->ingest( $mhash, $filename );
289
290
        my $quote = $schema->resultset('EdifactMessage')->find( { filename => $filename } );
291
292
        # Process quote and check results
293
        process_quote($quote);
294
295
        # QUOTES_BIG.CEQ contains 2 separate transport messages with different buyer EANs
296
        # Our fix should create 2 baskets and use the correct EAN for each auto-order
297
        my $baskets = Koha::Acquisition::Baskets->search(
298
            { booksellerid => $account->{vendor_id} },
299
            { order_by     => 'basketno' }
300
        );
301
        is( $baskets->count, 2, "Two baskets created for multi-transport quote file" );
302
303
        # Check that EDI orders were created (since auto_orders = 1)
304
        my $edi_orders = $schema->resultset('EdifactMessage')->search(
305
            {
306
                message_type => 'ORDERS',
307
                vendor_id    => $account->{vendor_id}
308
            }
309
        );
310
        is( $edi_orders->count, 2, 'Two EDI orders created with auto_orders enabled' );
311
312
        # Verify that both baskets were closed
313
        my $closed_baskets = $baskets->search( { closedate => { '!=' => undef } } );
314
        is( $closed_baskets->count, 2, 'Both baskets closed by auto_orders' );
315
316
        $schema->storage->txn_rollback;
317
    };
318
319
    # Test 3: Auto Orders Processing
227
    subtest 'auto_orders_processing' => sub {
320
    subtest 'auto_orders_processing' => sub {
228
        plan tests => 7;
321
        plan tests => 7;
229
322
230
- 

Return to bug 40587