@@ -, +, @@ --- t/db_dependent/Koha/Account/Lines.t | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) --- a/t/db_dependent/Koha/Account/Lines.t +++ a/t/db_dependent/Koha/Account/Lines.t @@ -22,7 +22,7 @@ use Modern::Perl; use Test::More tests => 8; use Test::Exception; -use C4::Circulation qw/AddIssue AddReturn/; +use C4::Circulation qw/AddIssue AddReturn MarkIssueReturned/; use Koha::Account; use Koha::Account::Lines; use Koha::Account::Offsets; @@ -294,9 +294,9 @@ subtest 'apply() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'Keep account info when related patron, staff or item is deleted' => sub { +subtest 'Keep account info when related patron, staff, item or issue is deleted' => sub { - plan tests => 3; + plan tests => 6; $schema->storage->txn_begin; @@ -309,18 +309,30 @@ subtest 'Keep account info when related patron, staff or item is deleted' => sub value => { itemnumber => $item->itemnumber } } ); + my $issue_id = $issue->id; my $line = Koha::Account::Line->new( { borrowernumber => $patron->borrowernumber, manager_id => $staff->borrowernumber, itemnumber => $item->itemnumber, + issue_id => $issue_id, + old_issue_id => undef, accounttype => "OVERDUE", status => "RETURNED", amount => 10, interface => 'commandline', })->store; - $issue->delete; + MarkIssueReturned($patron->borrowernumber, $item->itemnumber, undef, 0 ); + $line = $line->get_from_storage; + is( $line->issue_id, undef, "The account line should not be deleted when the related issue is archived"); + is( $line->old_issue_id, $issue_id, "The account line link to the archived issue"); + + my $old_issue = Koha::Old::Checkouts->find($issue_id); + $old_issue->delete; + $line = $line->get_from_storage; + is( $line->old_issue_id, undef, "The account line should not be deleted when the related old_issue is delete"); + $item->delete; $line = $line->get_from_storage; is( $line->itemnumber, undef, "The account line should not be deleted when the related item is delete"); --