From 04aea91de0f2fe1103e4021f880d135da1fd11a9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 10 Oct 2017 12:11:14 +0000 Subject: [PATCH] Bug 15685: (QA follow-up) Address QA issues Signed-off-by: Jonathan Druart --- C4/Acquisition.pm | 4 ++-- Koha/Acquisition/Order.pm | 3 ++- Koha/EDI.pm | 4 +++- acqui/addorderiso2709.pl | 6 ++---- acqui/basket.pl | 1 - circ/reserveratios.pl | 15 +++++++++++++-- installer/data/mysql/atomicupdate/bug15685.perl | 10 ++++++---- .../prog/en/modules/acqui/basketheader.tt | 14 +++++++------- t/db_dependent/Acquisition/CancelReceipt.t | 2 +- 9 files changed, 36 insertions(+), 23 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 70dd409b4b..4d12bc7e80 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1590,7 +1590,7 @@ sub CancelReceipt { my $parent_ordernumber = $order->{'parent_ordernumber'}; my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); - my $basket = Koha::Acquisition::Order->find( $order->{ordernumber} )->basket; + my $basket = Koha::Acquisition::Orders->find({ordernumber => $ordernumber})->basket; if($parent_ordernumber == $ordernumber || not $parent_ordernumber) { # The order line has no parent, just mark it as not received @@ -1604,7 +1604,7 @@ sub CancelReceipt { }; $sth = $dbh->prepare($query); $sth->execute(0, undef, undef, $ordernumber); - _cancel_items_receipt( $ordernumber ); + _cancel_items_receipt( $basket->effective_create_items, $ordernumber ); } else { # The order line has a parent, increase parent quantity and delete # the order line. diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index bbad104117..1c52497279 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -109,7 +109,8 @@ Returns the basket associated to the order. sub basket { my ( $self ) = @_; - return Koha::Acquisition::Baskets->find( $self->basketno ); + my $basket_rs = $self->_result->basketno; + return Koha::Acquisition::Basket->_new_from_dbic( $basket_rs ); } =head2 Internal methods diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 1a15507171..bad68d1995 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -797,7 +797,9 @@ sub quote_item { ); } - if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { + my $basket = Koha::Acquisition::Basket->find( $basketno ); + + if ( $basket->effective_create_item eq 'ordering' ) { my $new_item = { notforloan => -1, cn_sort => q{}, diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 8e8929c948..cc5d222312 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -103,8 +103,7 @@ if ($op eq ""){ "allmatch" => $allmatch, ); import_biblios_list($template, $cgiparams->{'import_batch_id'}); - my $basket = GetBasket($cgiparams->{basketno}); - if ( $basket->effective_create_items eq 'ordering' && !$basket->{is_standing} ) { + if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) { # prepare empty item form my $cell = PrepareItemrecordDisplay( '', '', '', 'ACQ' ); @@ -382,8 +381,7 @@ if ($op eq ""){ # 4th, add items if applicable # parse the item sent by the form, and create an item just for the import_record_id we are dealing with # this is not optimised, but it's working ! - my $basket = GetBasket($cgiparams->{basketno}); - if ( $basket->effective_create_items eq 'ordering' && !$basket->{is_standing} ) { + if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) { my @tags = $input->multi_param('tag'); my @subfields = $input->multi_param('subfield'); my @field_values = $input->multi_param('field_value'); diff --git a/acqui/basket.pl b/acqui/basket.pl index fe9285e2b2..071961817f 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -390,7 +390,6 @@ if ( $op eq 'list' ) { } $template->param( - basket => $basket, basketno => $basketno, basket => $basket, basketname => $basket->{'basketname'}, diff --git a/circ/reserveratios.pl b/circ/reserveratios.pl index e7c28c763c..5d87cd1f20 100755 --- a/circ/reserveratios.pl +++ b/circ/reserveratios.pl @@ -31,6 +31,7 @@ use C4::Debug; use C4::Biblio qw/GetMarcBiblio GetRecordValue GetFrameworkCode/; use C4::Acquisition qw/GetOrdersByBiblionumber/; use Koha::DateUtils; +use Koha::Acquisition::Baskets; my $input = new CGI; my $startdate = $input->param('from'); @@ -55,6 +56,16 @@ if ($booksellerid && $basketno) { $template->param( booksellerid => $booksellerid, basketno => $basketno ); } +my $effective_create_items; +if ( $basketno ){ + my $basket = Koha::Acquisition::Baskets->find( $basketno ); + if ($basket){ + $effective_create_items = $basket->effective_create_items; + } else { + $effective_create_items = C4::Context->preference('AcqCreateItem'); + } +} + $startdate = eval { dt_from_string( $startdate ) } if $startdate; $enddate = eval { dt_from_string( $enddate ) } if $enddate; @@ -84,12 +95,12 @@ $sqldatewhere .= " AND reservedate <= ?"; push @query_params, output_pref({ dt => $enddate, dateformat => 'iso' }); my $include_aqorders_qty = - C4::Context->preference('AcqCreateItem') eq 'receiving' + $effective_create_items eq 'receiving' ? '+ COALESCE(aqorders.quantity, 0) - COALESCE(aqorders.quantityreceived, 0)' : q{}; my $include_aqorders_qty_join = - C4::Context->preference('AcqCreateItem') eq 'receiving' + $effective_create_items eq 'receiving' ? 'LEFT JOIN aqorders ON reserves.biblionumber=aqorders.biblionumber' : q{}; diff --git a/installer/data/mysql/atomicupdate/bug15685.perl b/installer/data/mysql/atomicupdate/bug15685.perl index 8c66878433..7721df59fa 100644 --- a/installer/data/mysql/atomicupdate/bug15685.perl +++ b/installer/data/mysql/atomicupdate/bug15685.perl @@ -1,10 +1,12 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { - $dbh->do(q{ - ALTER TABLE aqbasket - ADD COLUMN create_items ENUM('ordering', 'receiving', 'cataloguing') default NULL - }); + unless( column_exists('aqbasket','create_items') ){ + $dbh->do(q{ + ALTER TABLE aqbasket + ADD COLUMN create_items ENUM('ordering', 'receiving', 'cataloguing') default NULL + }); + } SetVersion( $DBversion ); print "Upgrade to $DBversion done (Bug 15685: Allow creation of items (AcqCreateItem) to be customizable per-basket)\n"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt index 9fc7786466..13917cfb14 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt @@ -43,7 +43,7 @@ [% IF ( basketno ) %]
  • - +
  • [% END %]
  • @@ -113,13 +113,13 @@
  • [% END %] diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index 20290da328..3b650b0982 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -49,6 +49,7 @@ my $bookseller = Koha::Acquisition::Bookseller->new( active => 1 } )->store; +t::lib::Mocks::mock_preference('AcqCreateItem', 'receiving'); my $basketno1 = C4::Acquisition::NewBasket( $bookseller->id @@ -66,7 +67,6 @@ my $budget = C4::Budgets::GetBudget( $budgetid ); my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); my $itemnumber = AddItem( { itype => $itemtype }, $biblionumber ); -t::lib::Mocks::mock_preference('AcqCreateItem', 'receiving'); my $order = Koha::Acquisition::Order->new( { basketno => $basketno1, -- 2.39.5