From 1d60e23262c6c412f281dec845ef66d0a4b61432 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 30 Sep 2020 18:03:50 +0000 Subject: [PATCH] Bug 26583: Remove unneccessary code in AddIssue The lines to calc due date are doubled ModDateLastSeen is not needed as we set the item not lost and we can set the date as we do for date last borrowed and save a DB store We should not have an existing issue, either we did and the borrower was the same so we renewed, or we did and the borrower didn't match, so we returned it Largely this si reading the code and confirming the changes make sense To test: 1 - Apply patch 2 - Check out items, confirm it works as before 3 - prove -v t/db_dependent/Circulation.t --- C4/Circulation.pm | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0603862e8e..4050d1f8f5 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1470,14 +1470,7 @@ sub AddIssue { $auto_renew = $rule->rule_value if $rule; } - # Record in the database the fact that the book was issued. - unless ($datedue) { - my $itype = $item_object->effective_itemtype; - $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower ); - - } - $datedue->truncate( to => 'minute' ); - + # Create the issue in the database my $issue_attributes = { borrowernumber => $borrower->{'borrowernumber'}, issuedate => $issuedate->strftime('%Y-%m-%d %H:%M:%S'), @@ -1486,19 +1479,13 @@ sub AddIssue { onsite_checkout => $onsite_checkout, auto_renew => $auto_renew ? 1 : 0, }; + $issue = Koha::Checkout->new( + { + itemnumber => $item_object->itemnumber, + %$issue_attributes, + } + )->store; - $issue = Koha::Checkouts->find( { itemnumber => $item_object->itemnumber } ); - if ($issue) { - $issue->set($issue_attributes)->store; - } - else { - $issue = Koha::Checkout->new( - { - itemnumber => $item_object->itemnumber, - %$issue_attributes, - } - )->store; - } if ( $item_object->location && $item_object->location eq 'CART' && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) { ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart. @@ -1514,8 +1501,8 @@ sub AddIssue { $item_object->itemlost(0); $item_object->onloan($datedue->ymd()); $item_object->datelastborrowed( dt_from_string()->ymd() ); + $item_object->datelastseen( dt_from_string()->ymd() ); $item_object->store({log_action => 0}); - ModDateLastSeen( $item_object->itemnumber ); # If it costs to borrow this book, charge it to the patron's account. my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} ); -- 2.11.0