From 34677414d1094203a2a692d41feda1751858f890 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 14 Dec 2018 12:27:01 +0000 Subject: [PATCH] Bug 21999: Use Koha::Checkout in C4::Circulation::AddIssue Signed-off-by: Pierre-Marc Thibault Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- C4/Circulation.pm | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 971268c9f3..0afed47e11 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1356,17 +1356,33 @@ sub AddIssue { } $datedue->truncate( to => 'minute' ); - $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create( - { - borrowernumber => $borrower->{'borrowernumber'}, - itemnumber => $item->{'itemnumber'}, - issuedate => $issuedate->strftime('%Y-%m-%d %H:%M:%S'), - date_due => $datedue->strftime('%Y-%m-%d %H:%M:%S'), - branchcode => C4::Context->userenv->{'branch'}, - onsite_checkout => $onsite_checkout, - auto_renew => $auto_renew ? 1 : 0 - } - ); + $issue = + Koha::Checkouts->find( { itemnumber => $item->{'itemnumber'} } ); + if ($issue) { + $issue->set( + { + borrowernumber => $borrower->{'borrowernumber'}, + issuedate => $issuedate->strftime('%Y-%m-%d %H:%M:%S'), + date_due => $datedue->strftime('%Y-%m-%d %H:%M:%S'), + branchcode => C4::Context->userenv->{'branch'}, + onsite_checkout => $onsite_checkout, + auto_renew => $auto_renew ? 1 : 0 + } + )->store; + } + else { + $issue = Koha::Checkout->new( + { + borrowernumber => $borrower->{'borrowernumber'}, + itemnumber => $item->{'itemnumber'}, + issuedate => $issuedate->strftime('%Y-%m-%d %H:%M:%S'), + date_due => $datedue->strftime('%Y-%m-%d %H:%M:%S'), + branchcode => C4::Context->userenv->{'branch'}, + onsite_checkout => $onsite_checkout, + auto_renew => $auto_renew ? 1 : 0 + } + )->store; + } if ( C4::Context->preference('ReturnToShelvingCart') ) { # ReturnToShelvingCart is on, anything issued should be taken off the cart. -- 2.39.5