|
Lines 25-31
use Test::MockModule;
Link Here
|
| 25 |
|
25 |
|
| 26 |
use DateTime; |
26 |
use DateTime; |
| 27 |
|
27 |
|
| 28 |
use C4::Circulation qw( AddRenewal CanBookBeRenewed LostItem AddIssue AddReturn ); |
28 |
use C4::Circulation qw( AddRenewal CanBookBeRenewed LostItem AddIssue AddReturn MarkIssueReturned ); |
| 29 |
use Koha::Account; |
29 |
use Koha::Account; |
| 30 |
use Koha::Account::Lines; |
30 |
use Koha::Account::Lines; |
| 31 |
use Koha::Account::Offsets; |
31 |
use Koha::Account::Offsets; |
|
Lines 448-456
subtest 'apply() tests' => sub {
Link Here
|
| 448 |
$schema->storage->txn_rollback; |
448 |
$schema->storage->txn_rollback; |
| 449 |
}; |
449 |
}; |
| 450 |
|
450 |
|
| 451 |
subtest 'Keep account info when related patron, staff, item or cash_register is deleted' => sub { |
451 |
subtest 'Keep account info when related patron, staff, item, issue or cash_register is deleted' => sub { |
| 452 |
|
452 |
|
| 453 |
plan tests => 4; |
453 |
plan tests => 7; |
| 454 |
|
454 |
|
| 455 |
$schema->storage->txn_begin; |
455 |
$schema->storage->txn_begin; |
| 456 |
|
456 |
|
|
Lines 460-483
subtest 'Keep account info when related patron, staff, item or cash_register is
Link Here
|
| 460 |
my $issue = $builder->build_object( |
460 |
my $issue = $builder->build_object( |
| 461 |
{ |
461 |
{ |
| 462 |
class => 'Koha::Checkouts', |
462 |
class => 'Koha::Checkouts', |
| 463 |
value => { itemnumber => $item->itemnumber } |
463 |
value => { itemnumber => $item->itemnumber, borrowernumber => $patron->borrowernumber } |
| 464 |
} |
464 |
} |
| 465 |
); |
465 |
); |
| 466 |
my $register = $builder->build_object({ class => 'Koha::Cash::Registers' }); |
466 |
my $register = $builder->build_object({ class => 'Koha::Cash::Registers' }); |
| 467 |
|
467 |
|
| 468 |
my $line = Koha::Account::Line->new( |
468 |
my $line = Koha::Account::Line->new( |
| 469 |
{ |
469 |
{ |
| 470 |
borrowernumber => $patron->borrowernumber, |
470 |
borrowernumber => $patron->borrowernumber, |
| 471 |
manager_id => $staff->borrowernumber, |
471 |
manager_id => $staff->borrowernumber, |
| 472 |
itemnumber => $item->itemnumber, |
472 |
itemnumber => $item->itemnumber, |
| 473 |
debit_type_code => "OVERDUE", |
473 |
debit_type_code => "OVERDUE", |
| 474 |
status => "RETURNED", |
474 |
issue_id => $issue->id, |
| 475 |
amount => 10, |
475 |
old_issue_id => undef, |
| 476 |
interface => 'commandline', |
476 |
status => "RETURNED", |
| 477 |
register_id => $register->id |
477 |
amount => 10, |
| 478 |
})->store; |
478 |
interface => 'commandline', |
|
|
479 |
register_id => $register->id |
| 480 |
} |
| 481 |
)->store; |
| 482 |
|
| 483 |
MarkIssueReturned($patron->borrowernumber, $item->itemnumber, undef, 0 ); |
| 484 |
$line = $line->get_from_storage; |
| 485 |
is( $line->issue_id, undef, "The account line should not be deleted when the related issue is archived"); |
| 486 |
is( $line->old_issue_id, $issue->id, "The account line link to the archived issue"); |
| 487 |
|
| 488 |
my $old_issue = Koha::Old::Checkouts->find($issue->id); |
| 489 |
$old_issue->delete; |
| 490 |
$line = $line->get_from_storage; |
| 491 |
is( $line->old_issue_id, undef, "The account line should not be deleted when the related old_issue is delete"); |
| 479 |
|
492 |
|
| 480 |
$issue->delete; |
|
|
| 481 |
$item->delete; |
493 |
$item->delete; |
| 482 |
$line = $line->get_from_storage; |
494 |
$line = $line->get_from_storage; |
| 483 |
is( $line->itemnumber, undef, "The account line should not be deleted when the related item is delete"); |
495 |
is( $line->itemnumber, undef, "The account line should not be deleted when the related item is delete"); |