Lines 275-281
subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub {
Link Here
|
275 |
}; |
275 |
}; |
276 |
|
276 |
|
277 |
subtest 'Handle ids duplication' => sub { |
277 |
subtest 'Handle ids duplication' => sub { |
278 |
plan tests => 4; |
278 |
plan tests => 6; |
279 |
|
279 |
|
280 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); |
280 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); |
281 |
t::lib::Mocks::mock_preference( 'CalculateFinesOnReturn', 1 ); |
281 |
t::lib::Mocks::mock_preference( 'CalculateFinesOnReturn', 1 ); |
Lines 300-320
subtest 'Handle ids duplication' => sub {
Link Here
|
300 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
300 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
301 |
|
301 |
|
302 |
my $original_checkout = AddIssue( $patron->unblessed, $item->{barcode}, dt_from_string->subtract( days => 50 ) ); |
302 |
my $original_checkout = AddIssue( $patron->unblessed, $item->{barcode}, dt_from_string->subtract( days => 50 ) ); |
303 |
$builder->build({ source => 'OldIssue', value => { issue_id => $original_checkout->issue_id } }); |
|
|
304 |
my $old_checkout = Koha::Old::Checkouts->find( $original_checkout->issue_id ); |
305 |
|
303 |
|
306 |
AddRenewal( $patron->borrowernumber, $item->{itemnumber} ); |
304 |
my $issue_id = $original_checkout->issue_id; |
|
|
305 |
# Create an existing entry in old_issue |
306 |
$builder->build({ source => 'OldIssue', value => { issue_id => $issue_id } }); |
307 |
|
308 |
my $old_checkout = Koha::Old::Checkouts->find( $issue_id ); |
307 |
|
309 |
|
308 |
my ($doreturn, $messages, $new_checkout, $borrower) = AddReturn( $item->{barcode}, undef, undef, undef, dt_from_string ); |
310 |
my ($doreturn, $messages, $new_checkout, $borrower); |
|
|
311 |
warning_like { |
312 |
( $doreturn, $messages, $new_checkout, $borrower ) = |
313 |
AddReturn( $item->{barcode}, undef, undef, undef, dt_from_string ); |
314 |
} |
315 |
[ |
316 |
qr{.*DBD::mysql::st execute failed: Duplicate entry.*}, |
317 |
{ carped => qr{The checkin for the following issue failed.*DBIx::Class::Storage::DBI::_dbh_execute.*} } |
318 |
], |
319 |
'DBD should have raised an error about dup primary key'; |
309 |
|
320 |
|
310 |
my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $original_checkout->issue_id }); |
321 |
is( $doreturn, 0, 'Return should not have been done' ); |
311 |
is( $account_lines->count, 0, 'No account lines should exist on old issue_id' ); |
322 |
is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' ); |
|
|
323 |
is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' ); |
312 |
|
324 |
|
313 |
$account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $new_checkout->{issue_id} }); |
325 |
my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id }); |
314 |
is( $account_lines->count, 2, 'Two account lines should exist on new issue_id' ); |
326 |
is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' ); |
315 |
|
327 |
|
316 |
isnt( $original_checkout->issue_id, $new_checkout->{issue_id}, 'AddReturn should return the issue with the new issue_id' ); |
328 |
is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' ); |
317 |
isnt( $old_checkout->itemnumber, $item->{itemnumber}, 'If an item is checked-in, it should be moved to old_issues even if the issue_id already existed in the table' ); |
|
|
318 |
}; |
329 |
}; |
319 |
|
330 |
|
320 |
1; |
331 |
1; |
321 |
- |
|
|