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

(-)a/Koha/Checkouts/ReturnClaim.pm (-8 / +3 lines)
Lines 53-67 sub store { Link Here
53
        Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy->throw();
53
        Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy->throw();
54
    }
54
    }
55
55
56
    unless ( !$self->issue_id
56
    # is "fk" is missing, remove it from issue_id
57
    $self->issue_id(undef) unless ( !$self->issue_id
57
        || Koha::Checkouts->find( $self->issue_id )
58
        || Koha::Checkouts->find( $self->issue_id )
58
        || Koha::Old::Checkouts->find( $self->issue_id ) )
59
        || Koha::Old::Checkouts->find( $self->issue_id ) );
59
    {
60
        Koha::Exceptions::Object::FKConstraint->throw(
61
            error     => 'Broken FK constraint',
62
            broken_fk => 'issue_id'
63
        );
64
    }
65
60
66
    return $self->SUPER::store;
61
    return $self->SUPER::store;
67
}
62
}
(-)a/t/db_dependent/Koha/Checkouts/ReturnClaim.t (-31 / +38 lines)
Lines 31-37 my $builder = t::lib::TestBuilder->new; Link Here
31
31
32
subtest "store() tests" => sub {
32
subtest "store() tests" => sub {
33
33
34
    plan tests => 11;
34
    plan tests => 9;
35
35
36
    $schema->storage->txn_begin;
36
    $schema->storage->txn_begin;
37
37
Lines 109-148 subtest "store() tests" => sub { Link Here
109
    is( ref($claim), 'Koha::Checkouts::ReturnClaim', 'Object type is correct' );
109
    is( ref($claim), 'Koha::Checkouts::ReturnClaim', 'Object type is correct' );
110
    is( Koha::Checkouts::ReturnClaims->search( { issue_id => $checkout->id } )->count, 1, 'Claim stored on the DB');
110
    is( Koha::Checkouts::ReturnClaims->search( { issue_id => $checkout->id } )->count, 1, 'Claim stored on the DB');
111
111
112
    {    # hide useless warnings
113
        local *STDERR;
114
        open STDERR, '>', '/dev/null';
115
116
        my $another_checkout = $builder->build_object({ class => 'Koha::Checkouts' });
117
        my $checkout_id = $another_checkout->id;
118
        $another_checkout->delete;
119
120
        my $THE_claim;
121
122
        throws_ok {
123
            $THE_claim = Koha::Checkouts::ReturnClaim->new(
124
                {
125
                    issue_id       => $checkout_id,
126
                    itemnumber     => $checkout->itemnumber,
127
                    borrowernumber => $checkout->borrowernumber,
128
                    notes          => 'Some notes',
129
                    created_by     => $librarian->borrowernumber
130
                }
131
            )->store;
132
        }
133
        'Koha::Exceptions::Object::FKConstraint',
134
          'An exception is thrown on invalid issue_id';
135
        close STDERR;
136
137
        is( $@->broken_fk, 'issue_id', 'Exception field is correct' );
138
    }
139
140
    $schema->storage->txn_rollback;
112
    $schema->storage->txn_rollback;
141
};
113
};
142
114
143
subtest "resolve() tests" => sub {
115
subtest "resolve() tests" => sub {
144
116
145
    plan tests => 9;
117
    plan tests => 10;
146
118
147
    $schema->storage->txn_begin;
119
    $schema->storage->txn_begin;
148
120
Lines 257-262 subtest "resolve() tests" => sub { Link Here
257
    $item->discard_changes;
229
    $item->discard_changes;
258
    is( $item->itemlost, $new_lost_status, 'Item lost status is updated' );
230
    is( $item->itemlost, $new_lost_status, 'Item lost status is updated' );
259
231
232
    # Resolve claim for checkout that has been cleaned from the database
233
    $checkout->delete;
234
    $checkout = $builder->build_object(
235
        {
236
            class => 'Koha::Checkouts',
237
            value => {
238
                borrowernumber => $patron->borrowernumber,
239
                itemnumber     => $item->itemnumber,
240
                branchcode     => $patron->branchcode
241
            }
242
        }
243
    );
244
245
    $claim = Koha::Checkouts::ReturnClaim->new(
246
        {
247
            issue_id       => $checkout->id,
248
            itemnumber     => $checkout->itemnumber,
249
            borrowernumber => $checkout->borrowernumber,
250
            notes          => 'Some notes',
251
            created_by     => $librarian->borrowernumber
252
        }
253
    )->store;
254
255
    $checkout->delete;
256
257
    $claim->resolve(
258
        {
259
            resolution      => "X",
260
            resolved_by     => $librarian->id,
261
            resolved_on     => $tomorrow,
262
            new_lost_status => $new_lost_status,
263
        }
264
    )->discard_changes;
265
266
    is( $claim->issue_id, undef, "Resolved claim cleaned checkout is updated correctly" );
267
260
    $schema->storage->txn_rollback;
268
    $schema->storage->txn_rollback;
261
};
269
};
262
270
263
- 

Return to bug 33362