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