From 6e2d139be166703180ed858256154a11117c2323 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 11 Jul 2013 10:43:05 +0200 Subject: [PATCH] Bug 5336: Change numbers with understandable codes for orderstatus This patch uses understandable codes instead of magical numbers for the aqorders.orderstatus field. + execute sql queries in unit tests into a transaction. --- C4/Acquisition.pm | 20 ++++++------ installer/data/mysql/kohastructure.sql | 2 +- installer/data/mysql/updatedatabase.pl | 10 +++--- .../prog/en/modules/acqui/histsearch.tt | 21 ++++++------- t/db_dependent/Acquisition/OrderFromSubscription.t | 2 +- t/db_dependent/Acquisition/close_reopen_basket.t | 33 ++++++++++---------- 6 files changed, 43 insertions(+), 45 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index b55786b..78c214c 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -234,7 +234,7 @@ sub CloseBasket { foreach my $order (@orders) { $query = qq{ UPDATE aqorders - SET orderstatus = 1 + SET orderstatus = 'ordered' WHERE ordernumber = ?; }; $sth = $dbh->prepare($query); @@ -265,7 +265,7 @@ sub ReopenBasket { foreach my $order (@orders) { $query = qq{ UPDATE aqorders - SET orderstatus = 0 + SET orderstatus = 'new' WHERE ordernumber = ?; }; $sth = $dbh->prepare($query); @@ -1471,7 +1471,7 @@ sub ModReceiveOrder { $sth=$dbh->prepare(" UPDATE aqorders SET quantity = ?, - orderstatus = 2 + orderstatus = 'partial' WHERE ordernumber = ? "); @@ -1487,7 +1487,7 @@ sub ModReceiveOrder { $order->{'unitprice'} = $cost; $order->{'rrp'} = $rrp; $order->{ecost} = $ecost; - $order->{'orderstatus'} = 3; # totally received + $order->{'orderstatus'} = 'complete'; $new_ordernumber = NewOrder($order); if ($received_items) { @@ -1498,7 +1498,7 @@ sub ModReceiveOrder { } else { $sth=$dbh->prepare("update aqorders set quantityreceived=?,datereceived=?,invoiceid=?, - unitprice=?,rrp=?,ecost=?,orderstatus=3 + unitprice=?,rrp=?,ecost=?,orderstatus='complete' where biblionumber=? and ordernumber=?"); $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber); $sth->finish; @@ -1549,7 +1549,7 @@ sub CancelReceipt { SET quantityreceived = ?, datereceived = ?, invoiceid = ?, - orderstatus = 1 + orderstatus = 'ordered' WHERE ordernumber = ? }; $sth = $dbh->prepare($query); @@ -1577,7 +1577,7 @@ sub CancelReceipt { $query = qq{ UPDATE aqorders SET quantity = ?, - orderstatus = 1 + orderstatus = 'ordered' WHERE ordernumber = ? }; $sth = $dbh->prepare($query); @@ -1717,7 +1717,7 @@ sub DelOrder { my $dbh = C4::Context->dbh; my $query = " UPDATE aqorders - SET datecancellationprinted=now(), orderstatus=4 + SET datecancellationprinted=now(), orderstatus='cancelled' WHERE biblionumber=? AND ordernumber=? "; my $sth = $dbh->prepare($query); @@ -2010,7 +2010,7 @@ sub GetLateOrders { $from .= ' AND borrowers.branchcode LIKE ? '; push @query_params, C4::Context->userenv->{branch}; } - $from .= " AND orderstatus <> 4 "; + $from .= " AND orderstatus <> 'cancelled' "; my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier"; $debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params); my $sth = $dbh->prepare($query); @@ -2133,7 +2133,7 @@ sub GetHistory { $query .= " WHERE 1 "; - $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') " if $orderstatus ne '4'; + $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') " if $orderstatus ne 'cancelled'; my @query_params = (); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 6a55222..7f53c07 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2932,7 +2932,7 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items `claimed_date` date default NULL, -- last date a claim was generated `subscriptionid` int(11) default NULL, -- links this order line to a subscription (subscription.subscriptionid) parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent - `orderstatus` tinyint(2) default 0, -- the current status for this line item + `orderstatus` varchar(16) default 'new', -- the current status for this line item. Can be 'new', 'ordered', 'partial', 'complete' or 'cancelled' PRIMARY KEY (`ordernumber`), KEY `basketno` (`basketno`), KEY `biblionumber` (`biblionumber`), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 8cca550..6812c8c 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7017,11 +7017,11 @@ CREATE TABLE IF NOT EXISTS borrower_files ( $DBversion = "3.13.00.XXX"; if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { my $return_count; - $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus tinyint(2) DEFAULT 0 AFTER parent_ordernumber"); - $dbh->do("UPDATE aqorders SET orderstatus=1 WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)"); - $dbh->do("UPDATE aqorders SET orderstatus=2 WHERE quantity > quantityreceived AND quantityreceived > 0"); - $dbh->do("UPDATE aqorders SET orderstatus=3 WHERE quantity=quantityreceived"); - $dbh->do("UPDATE aqorders SET orderstatus=4 WHERE datecancellationprinted IS NOT NULL"); + $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus varchar(16) DEFAULT 'new' AFTER parent_ordernumber"); + $dbh->do("UPDATE aqorders SET orderstatus='ordered' WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)"); + $dbh->do("UPDATE aqorders SET orderstatus='partial' WHERE quantity > quantityreceived AND quantityreceived > 0"); + $dbh->do("UPDATE aqorders SET orderstatus='complete' WHERE quantity=quantityreceived"); + $dbh->do("UPDATE aqorders SET orderstatus='cancelled' WHERE datecancellationprinted IS NOT NULL"); print "Upgrade to $DBversion done (Bug 5336: Add the new column aqorders.orderstatus)\n"; SetVersion($DBversion); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt index 811d88a..8bdea9d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt @@ -54,14 +54,13 @@ -