From 4980428f6e55e8aaf898a3d1158347eadc8fa574 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 28 Mar 2014 10:55:11 +0100 Subject: [PATCH 3/3] Bug 7290: Use basket branch instead of order line branch and remove aqorders.branch from updatedatabase.pl and kohastructure.sql Signed-off-by: Paola Rossi --- C4/Acquisition.pm | 13 +++---- acqui/addorder.pl | 1 - installer/data/mysql/kohastructure.sql | 3 -- installer/data/mysql/updatedatabase.pl | 6 --- .../prog/en/modules/acqui/neworderempty.tt | 19 --------- t/Acquisition/CanUserReceiveBasket.t | 41 +------------------- 6 files changed, 7 insertions(+), 76 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index b865623..3ad3485 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -824,7 +824,7 @@ sub CanUserManageBasket { my $bool = CanUserReceiveOrder($borrowernumber, $orderno[, $userflags]); Check if a borrower can receive a order, according to user permissions, current -working branch and order and basket branches. +working branch and basket branches. First parameter can be either a borrowernumber or a hashref as returned by C4::Members::GetMember. @@ -871,18 +871,15 @@ sub CanUserReceiveOrder { if (!ref $userflags->{acquisition} && !$userflags->{acquisition}) { return 0; } + if (ref $userflags->{acquisition} && !$userflags->{acquisition}->{order_receive}) { return 0; } - if (defined $order->{branch} && $order->{branch} ne $branch) { + + my $basket = GetBasket($order->{basketno}); + if (!$basket || (defined $basket->{branch} && $basket->{branch} ne $branch)) { return 0; } - if (!defined $order->{branch}) { - my $basket = GetBasket($order->{basketno}); - if (!$basket || (defined $basket->{branch} && $basket->{branch} ne $branch)) { - return 0; - } - } } return 1; diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 69d9fdb..1b05f07 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -226,7 +226,6 @@ my $orderinfo = $input->Vars; $orderinfo->{'list_price'} ||= 0; $orderinfo->{'uncertainprice'} ||= 0; $orderinfo->{subscriptionid} ||= undef; -$orderinfo->{branch} = undef if (defined $orderinfo->{branch} and $orderinfo->{branch} eq ''); my $user = $input->remote_user; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 4ad0325..92ab713 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3024,18 +3024,15 @@ 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 - branch varchar(10) default NULL, -- order line branch `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`), KEY `budget_id` (`budget_id`), - KEY branch (branch), CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE - CONSTRAINT aqorders_branch FOREIGN KEY (branch) REFERENCES branches (branchcode) ON UPDATE CASCADE ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e780039..12f8bbb 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8474,12 +8474,6 @@ if ( CheckVersion($DBversion) ) { $DBversion = "XXX"; if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { $dbh->do(" - ALTER TABLE aqorders - ADD COLUMN branch VARCHAR(10) DEFAULT NULL, - ADD CONSTRAINT aqorders_branch FOREIGN KEY (branch) - REFERENCES branches (branchcode) ON UPDATE CASCADE ON DELETE SET NULL - "); - $dbh->do(" INSERT INTO permissions (module_bit, code, description) VALUES (11, 'order_receive_all', 'Receive all orders') "); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index bf60a3d..9bb2b8c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -228,25 +228,6 @@ $(document).ready(function()
- Order details -
    -
  1. - Branch: - -
  2. -
-
- -
Catalog details [% IF ( biblionumber ) %] diff --git a/t/Acquisition/CanUserReceiveBasket.t b/t/Acquisition/CanUserReceiveBasket.t index a0c4633..f0a7453 100644 --- a/t/Acquisition/CanUserReceiveBasket.t +++ b/t/Acquisition/CanUserReceiveBasket.t @@ -2,7 +2,7 @@ use Modern::Perl; use Test::MockModule; -use Test::More tests => 30; +use Test::More tests => 18; use C4::Acquisition; @@ -29,35 +29,11 @@ my $order1 = { basketno => 1 }; my $order2 = { - basketno => 1, - branch => 'B1' -}; -my $order3 = { - basketno => 1, - branch => 'B2' -}; -my $order4 = { basketno => 2 }; -my $order5 = { - basketno => 2, - branch => 'B1' -}; -my $order6 = { - basketno => 2, - branch => 'B2' -}; -my $order7 = { +my $order3 = { basketno => 3 }; -my $order8 = { - basketno => 3, - branch => 'B1' -}; -my $order9 = { - basketno => 3, - branch => 'B2' -}; $userenv->{branch} = 'B1'; @@ -72,13 +48,6 @@ ok( not CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive ok( CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive => 1 }}) ); ok( CanUserReceiveOrder($borrower, $order2, {acquisition => { order_receive => 1 }}) ); ok( not CanUserReceiveOrder($borrower, $order3, {acquisition => { order_receive => 1 }}) ); -ok( CanUserReceiveOrder($borrower, $order4, {acquisition => { order_receive => 1 }}) ); -ok( CanUserReceiveOrder($borrower, $order5, {acquisition => { order_receive => 1 }}) ); -ok( not CanUserReceiveOrder($borrower, $order6, {acquisition => { order_receive => 1 }}) ); -ok( not CanUserReceiveOrder($borrower, $order7, {acquisition => { order_receive => 1 }}) ); -ok( CanUserReceiveOrder($borrower, $order8, {acquisition => { order_receive => 1 }}) ); -ok( not CanUserReceiveOrder($borrower, $order9, {acquisition => { order_receive => 1 }}) ); - $userenv->{branch} = 'B2'; @@ -93,12 +62,6 @@ ok( not CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive ok( CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive => 1 }}) ); ok( not CanUserReceiveOrder($borrower, $order2, {acquisition => { order_receive => 1 }}) ); ok( CanUserReceiveOrder($borrower, $order3, {acquisition => { order_receive => 1 }}) ); -ok( not CanUserReceiveOrder($borrower, $order4, {acquisition => { order_receive => 1 }}) ); -ok( not CanUserReceiveOrder($borrower, $order5, {acquisition => { order_receive => 1 }}) ); -ok( CanUserReceiveOrder($borrower, $order6, {acquisition => { order_receive => 1 }}) ); -ok( CanUserReceiveOrder($borrower, $order7, {acquisition => { order_receive => 1 }}) ); -ok( not CanUserReceiveOrder($borrower, $order8, {acquisition => { order_receive => 1 }}) ); -ok( CanUserReceiveOrder($borrower, $order9, {acquisition => { order_receive => 1 }}) ); sub Mock_GetBasket { my ($basketno) = @_; -- 1.7.10.4