From 9dace4e21e33f1b92e1e2db7ef72435539895794 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Tue, 20 Oct 2015 14:19:35 +0100 Subject: [PATCH] Bug 15036: Do not overwrite complete status in basket ops MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reopening or closing a basket should preserve the completed status for receipted orders. This patch excludes orderlines with the completed status from having their status rewritten as a result of the change in basket status Made the subroutines involved more efficient by removing an unnecessary loop and by not fetching a large amount of superfluous data Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 4a4dbbf1237c93e0233eef0600015c9be3320bf0) Signed-off-by: Frédéric Demians --- C4/Acquisition.pm | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index d1d42e03c2..36c45b6b40 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -237,24 +237,11 @@ close a basket (becomes unmodifiable, except for receives) sub CloseBasket { my ($basketno) = @_; my $dbh = C4::Context->dbh; - my $query = " - UPDATE aqbasket - SET closedate=now() - WHERE basketno=? - "; - my $sth = $dbh->prepare($query); - $sth->execute($basketno); + $dbh->do('UPDATE aqbasket SET closedate=now() WHERE basketno=?', {}, $basketno ); - my @orders = GetOrders($basketno); - foreach my $order (@orders) { - $query = qq{ - UPDATE aqorders - SET orderstatus = 'ordered' - WHERE ordernumber = ?; - }; - $sth = $dbh->prepare($query); - $sth->execute($order->{'ordernumber'}); - } + $dbh->do( q{UPDATE aqorders SET orderstatus = 'ordered' WHERE basketno = ? AND orderstatus != 'complete'}, + {}, $basketno); + return; } =head3 ReopenBasket @@ -268,24 +255,15 @@ reopen a basket sub ReopenBasket { my ($basketno) = @_; my $dbh = C4::Context->dbh; - my $query = " - UPDATE aqbasket - SET closedate=NULL - WHERE basketno=? - "; - my $sth = $dbh->prepare($query); - $sth->execute($basketno); + $dbh->do( q{UPDATE aqbasket SET closedate=NULL WHERE basketno=?}, {}, $basketno ); - my @orders = GetOrders($basketno); - foreach my $order (@orders) { - $query = qq{ - UPDATE aqorders - SET orderstatus = 'new' - WHERE ordernumber = ?; - }; - $sth = $dbh->prepare($query); - $sth->execute($order->{'ordernumber'}); - } + $dbh->do( q{ + UPDATE aqorders + SET orderstatus = 'new' + WHERE basketno = ? + AND orderstatus != 'complete' + }, {}, $basketno); + return; } #------------------------------------------------------------# -- 2.39.5