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

(-)a/C4/Circulation.pm (-13 / +10 lines)
Lines 1951-1969 sub AddIssue { Link Here
1951
1951
1952
            # Log the checkout
1952
            # Log the checkout
1953
            if ( C4::Context->preference('IssueLog') ) {
1953
            if ( C4::Context->preference('IssueLog') ) {
1954
                my $info = $item_object->itemnumber;
1954
                my $info = to_json(
1955
                if ( defined($confirmations) || defined($forced) ) {
1955
                    {
1956
                    $info = to_json(
1956
                        issue         => $issue->issue_id,
1957
                        {
1957
                        branchcode    => $issue->branchcode,
1958
                            issue         => $issue->issue_id,
1958
                        itemnumber    => $item_object->itemnumber,
1959
                            branchcode    => $issue->branchcode,
1959
                        confirmations => $confirmations || [],
1960
                            itemnumber    => $item_object->itemnumber,
1960
                        forced        => $forced        || []
1961
                            confirmations => $confirmations,
1961
                    },
1962
                            forced        => $forced
1962
                    { pretty => 1, canonical => 1 }
1963
                        },
1963
                );
1964
                        { pretty => 1, canonical => 1 }
1965
                    );
1966
                }
1967
                logaction(
1964
                logaction(
1968
                    "CIRCULATION", "ISSUE",
1965
                    "CIRCULATION", "ISSUE",
1969
                    $patron->borrowernumber,
1966
                    $patron->borrowernumber,
(-)a/t/db_dependent/Circulation.t (-7 / +10 lines)
Lines 7871-7877 subtest 'ChildNeedsGuarantor' => sub { Link Here
7871
};
7871
};
7872
7872
7873
subtest 'Bug 9762: AddIssue override JSON logging' => sub {
7873
subtest 'Bug 9762: AddIssue override JSON logging' => sub {
7874
    plan tests => 8;
7874
    plan tests => 11;
7875
7875
7876
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
7876
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
7877
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
7877
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
Lines 7883-7889 subtest 'Bug 9762: AddIssue override JSON logging' => sub { Link Here
7883
    # Clear any existing logs
7883
    # Clear any existing logs
7884
    Koha::ActionLogs->search( { module => 'CIRCULATION', action => 'ISSUE' } )->delete;
7884
    Koha::ActionLogs->search( { module => 'CIRCULATION', action => 'ISSUE' } )->delete;
7885
7885
7886
    # Test 1: Normal checkout without overrides - should log item number only
7886
    # Test 1: Normal checkout without overrides - should log JSON with empty arrays
7887
    my $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
7887
    my $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
7888
    ok( $issue, 'Item checked out successfully' );
7888
    ok( $issue, 'Item checked out successfully' );
7889
7889
Lines 7896-7903 subtest 'Bug 9762: AddIssue override JSON logging' => sub { Link Here
7896
        { order_by => { -desc => 'timestamp' } }
7896
        { order_by => { -desc => 'timestamp' } }
7897
    );
7897
    );
7898
    is( $logs->count, 1, 'One log entry created for normal checkout' );
7898
    is( $logs->count, 1, 'One log entry created for normal checkout' );
7899
    my $log = $logs->next;
7899
    my $log      = $logs->next;
7900
    is( $log->info, $item->itemnumber, 'Normal checkout logs item number only' );
7900
    my $log_data = eval { from_json( $log->info ) };
7901
    ok( !$@, 'Normal checkout log info is valid JSON' );
7902
    is( $log_data->{itemnumber}, $item->itemnumber, 'JSON contains correct itemnumber' );
7903
    is_deeply( $log_data->{confirmations}, [], 'Confirmations is empty array for normal checkout' );
7904
    is_deeply( $log_data->{forced},        [], 'Forced is empty array for normal checkout' );
7901
7905
7902
    # Return the item for next test
7906
    # Return the item for next test
7903
    C4::Circulation::AddReturn( $item->barcode, $library->branchcode );
7907
    C4::Circulation::AddReturn( $item->barcode, $library->branchcode );
Lines 7921-7934 subtest 'Bug 9762: AddIssue override JSON logging' => sub { Link Here
7921
            module => 'CIRCULATION',
7925
            module => 'CIRCULATION',
7922
            action => 'ISSUE',
7926
            action => 'ISSUE',
7923
            object => $patron->borrowernumber,
7927
            object => $patron->borrowernumber,
7924
            info   => { '!=', $item->itemnumber }    # Exclude the first test log
7928
            info   => { 'LIKE', '%' . $item2->itemnumber . '%' }    # Find the second test log by itemnumber
7925
        },
7929
        },
7926
        { order_by => { -desc => 'timestamp' } }
7930
        { order_by => { -desc => 'timestamp' } }
7927
    );
7931
    );
7928
    is( $logs->count, 1, 'One log entry created for override checkout' );
7932
    is( $logs->count, 1, 'One log entry created for override checkout' );
7929
    $log = $logs->next;
7933
    $log = $logs->next;
7930
7934
7931
    my $log_data = eval { from_json( $log->info ) };
7935
    $log_data = eval { from_json( $log->info ) };
7932
    ok( !$@,                               'Log info is valid JSON' );
7936
    ok( !$@,                               'Log info is valid JSON' );
7933
    ok( exists $log_data->{confirmations}, 'JSON contains confirmations array' );
7937
    ok( exists $log_data->{confirmations}, 'JSON contains confirmations array' );
7934
    is_deeply( $log_data->{confirmations}, [ 'DEBT', 'AGE_RESTRICTION' ], 'Confirmations logged correctly' );
7938
    is_deeply( $log_data->{confirmations}, [ 'DEBT', 'AGE_RESTRICTION' ], 'Confirmations logged correctly' );
7935
- 

Return to bug 41358