Bug 33362: Allow return claims to be resolved even if the issue has since been delete from the database
Test Plan: 1) Check out an item 2) Claim return on it, moving it to the old_issues table 3) Delete the old_issue via koha-mysql or Use cleanup_database.pl 4) Attempt to resolve the claim 5) Note the error 6) Apply this patch set 7) Restart all the things! 8) Attempt to resolve the claim 9) No errors! Signed-off-by: Sam Lau <samalau@gmail.com> Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
33856898fd
commit
816bbbe77f
|
|
@ -53,15 +53,10 @@ sub store {
|
|||
Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy->throw();
|
||||
}
|
||||
|
||||
unless ( !$self->issue_id
|
||||
# if issue_id is not found in issues or old_issues, set to null
|
||||
$self->issue_id(undef) unless ( !$self->issue_id
|
||||
|| Koha::Checkouts->find( $self->issue_id )
|
||||
|| Koha::Old::Checkouts->find( $self->issue_id ) )
|
||||
{
|
||||
Koha::Exceptions::Object::FKConstraint->throw(
|
||||
error => 'Broken FK constraint',
|
||||
broken_fk => 'issue_id'
|
||||
);
|
||||
}
|
||||
|| Koha::Old::Checkouts->find( $self->issue_id ) );
|
||||
|
||||
return $self->SUPER::store;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ my $builder = t::lib::TestBuilder->new;
|
|||
|
||||
subtest "store() tests" => sub {
|
||||
|
||||
plan tests => 11;
|
||||
plan tests => 9;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -109,40 +109,12 @@ subtest "store() tests" => sub {
|
|||
is( ref($claim), 'Koha::Checkouts::ReturnClaim', 'Object type is correct' );
|
||||
is( Koha::Checkouts::ReturnClaims->search( { issue_id => $checkout->id } )->count, 1, 'Claim stored on the DB');
|
||||
|
||||
{ # hide useless warnings
|
||||
local *STDERR;
|
||||
open STDERR, '>', '/dev/null';
|
||||
|
||||
my $another_checkout = $builder->build_object({ class => 'Koha::Checkouts' });
|
||||
my $checkout_id = $another_checkout->id;
|
||||
$another_checkout->delete;
|
||||
|
||||
my $THE_claim;
|
||||
|
||||
throws_ok {
|
||||
$THE_claim = Koha::Checkouts::ReturnClaim->new(
|
||||
{
|
||||
issue_id => $checkout_id,
|
||||
itemnumber => $checkout->itemnumber,
|
||||
borrowernumber => $checkout->borrowernumber,
|
||||
notes => 'Some notes',
|
||||
created_by => $librarian->borrowernumber
|
||||
}
|
||||
)->store;
|
||||
}
|
||||
'Koha::Exceptions::Object::FKConstraint',
|
||||
'An exception is thrown on invalid issue_id';
|
||||
close STDERR;
|
||||
|
||||
is( $@->broken_fk, 'issue_id', 'Exception field is correct' );
|
||||
}
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest "resolve() tests" => sub {
|
||||
|
||||
plan tests => 9;
|
||||
plan tests => 10;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -257,6 +229,42 @@ subtest "resolve() tests" => sub {
|
|||
$item->discard_changes;
|
||||
is( $item->itemlost, $new_lost_status, 'Item lost status is updated' );
|
||||
|
||||
# Resolve claim for checkout that has been cleaned from the database
|
||||
$checkout->delete;
|
||||
$checkout = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Checkouts',
|
||||
value => {
|
||||
borrowernumber => $patron->borrowernumber,
|
||||
itemnumber => $item->itemnumber,
|
||||
branchcode => $patron->branchcode
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$claim = Koha::Checkouts::ReturnClaim->new(
|
||||
{
|
||||
issue_id => $checkout->id,
|
||||
itemnumber => $checkout->itemnumber,
|
||||
borrowernumber => $checkout->borrowernumber,
|
||||
notes => 'Some notes',
|
||||
created_by => $librarian->borrowernumber
|
||||
}
|
||||
)->store;
|
||||
|
||||
$checkout->delete;
|
||||
|
||||
$claim->resolve(
|
||||
{
|
||||
resolution => "X",
|
||||
resolved_by => $librarian->id,
|
||||
resolved_on => $tomorrow,
|
||||
new_lost_status => $new_lost_status,
|
||||
}
|
||||
)->discard_changes;
|
||||
|
||||
is( $claim->issue_id, undef, "Resolved claim cleaned checkout is updated correctly" );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue