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

(-)a/C4/Circulation.pm (-13 / +10 lines)
Lines 1963-1981 sub AddIssue { Link Here
1963
1963
1964
            # Log the checkout
1964
            # Log the checkout
1965
            if ( C4::Context->preference('IssueLog') ) {
1965
            if ( C4::Context->preference('IssueLog') ) {
1966
                my $info = $item_object->itemnumber;
1966
                my $info = to_json(
1967
                if ( defined($confirmations) || defined($forced) ) {
1967
                    {
1968
                    $info = to_json(
1968
                        issue         => $issue->issue_id,
1969
                        {
1969
                        branchcode    => $issue->branchcode,
1970
                            issue         => $issue->issue_id,
1970
                        itemnumber    => $item_object->itemnumber,
1971
                            branchcode    => $issue->branchcode,
1971
                        confirmations => $confirmations || [],
1972
                            itemnumber    => $item_object->itemnumber,
1972
                        forced        => $forced        || []
1973
                            confirmations => $confirmations,
1973
                    },
1974
                            forced        => $forced
1974
                    { pretty => 1, canonical => 1 }
1975
                        },
1975
                );
1976
                        { pretty => 1, canonical => 1 }
1977
                    );
1978
                }
1979
                logaction(
1976
                logaction(
1980
                    "CIRCULATION", "ISSUE",
1977
                    "CIRCULATION", "ISSUE",
1981
                    $patron->borrowernumber,
1978
                    $patron->borrowernumber,
(-)a/t/db_dependent/Circulation.t (-7 / +10 lines)
Lines 8295-8301 subtest 'ChildNeedsGuarantor' => sub { Link Here
8295
};
8295
};
8296
8296
8297
subtest 'Bug 9762: AddIssue override JSON logging' => sub {
8297
subtest 'Bug 9762: AddIssue override JSON logging' => sub {
8298
    plan tests => 8;
8298
    plan tests => 11;
8299
8299
8300
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
8300
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
8301
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
8301
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
Lines 8307-8313 subtest 'Bug 9762: AddIssue override JSON logging' => sub { Link Here
8307
    # Clear any existing logs
8307
    # Clear any existing logs
8308
    Koha::ActionLogs->search( { module => 'CIRCULATION', action => 'ISSUE' } )->delete;
8308
    Koha::ActionLogs->search( { module => 'CIRCULATION', action => 'ISSUE' } )->delete;
8309
8309
8310
    # Test 1: Normal checkout without overrides - should log item number only
8310
    # Test 1: Normal checkout without overrides - should log JSON with empty arrays
8311
    my $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
8311
    my $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
8312
    ok( $issue, 'Item checked out successfully' );
8312
    ok( $issue, 'Item checked out successfully' );
8313
8313
Lines 8320-8327 subtest 'Bug 9762: AddIssue override JSON logging' => sub { Link Here
8320
        { order_by => { -desc => 'timestamp' } }
8320
        { order_by => { -desc => 'timestamp' } }
8321
    );
8321
    );
8322
    is( $logs->count, 1, 'One log entry created for normal checkout' );
8322
    is( $logs->count, 1, 'One log entry created for normal checkout' );
8323
    my $log = $logs->next;
8323
    my $log      = $logs->next;
8324
    is( $log->info, $item->itemnumber, 'Normal checkout logs item number only' );
8324
    my $log_data = eval { from_json( $log->info ) };
8325
    ok( !$@, 'Normal checkout log info is valid JSON' );
8326
    is( $log_data->{itemnumber}, $item->itemnumber, 'JSON contains correct itemnumber' );
8327
    is_deeply( $log_data->{confirmations}, [], 'Confirmations is empty array for normal checkout' );
8328
    is_deeply( $log_data->{forced},        [], 'Forced is empty array for normal checkout' );
8325
8329
8326
    # Return the item for next test
8330
    # Return the item for next test
8327
    C4::Circulation::AddReturn( $item->barcode, $library->branchcode );
8331
    C4::Circulation::AddReturn( $item->barcode, $library->branchcode );
Lines 8345-8358 subtest 'Bug 9762: AddIssue override JSON logging' => sub { Link Here
8345
            module => 'CIRCULATION',
8349
            module => 'CIRCULATION',
8346
            action => 'ISSUE',
8350
            action => 'ISSUE',
8347
            object => $patron->borrowernumber,
8351
            object => $patron->borrowernumber,
8348
            info   => { '!=', $item->itemnumber }    # Exclude the first test log
8352
            info   => { 'LIKE', '%' . $item2->itemnumber . '%' }    # Find the second test log by itemnumber
8349
        },
8353
        },
8350
        { order_by => { -desc => 'timestamp' } }
8354
        { order_by => { -desc => 'timestamp' } }
8351
    );
8355
    );
8352
    is( $logs->count, 1, 'One log entry created for override checkout' );
8356
    is( $logs->count, 1, 'One log entry created for override checkout' );
8353
    $log = $logs->next;
8357
    $log = $logs->next;
8354
8358
8355
    my $log_data = eval { from_json( $log->info ) };
8359
    $log_data = eval { from_json( $log->info ) };
8356
    ok( !$@,                               'Log info is valid JSON' );
8360
    ok( !$@,                               'Log info is valid JSON' );
8357
    ok( exists $log_data->{confirmations}, 'JSON contains confirmations array' );
8361
    ok( exists $log_data->{confirmations}, 'JSON contains confirmations array' );
8358
    is_deeply( $log_data->{confirmations}, [ 'DEBT', 'AGE_RESTRICTION' ], 'Confirmations logged correctly' );
8362
    is_deeply( $log_data->{confirmations}, [ 'DEBT', 'AGE_RESTRICTION' ], 'Confirmations logged correctly' );
8359
- 

Return to bug 41358