From 9a011c58e7efa3afa674a6376e75e4a6697083f8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 2 Oct 2018 13:31:20 -0300 Subject: [PATCH] Bug 21467: Do not erase the internal note of the first order MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For the subscription we would like to keep the original internal note (from the first order), to display it unmodified each time we receive issues. Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Séverine QUEUNE Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- C4/Acquisition.pm | 7 ++++-- acqui/orderreceive.pl | 15 ++++++++++--- t/db_dependent/Acquisition.t | 41 +++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 2a043a77a7..b1f7588455 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1443,16 +1443,19 @@ sub ModReceiveOrder { UPDATE aqorders SET quantity = ?, orderstatus = 'partial'|; - $query .= q|, order_internalnote = ?| if defined $order->{order_internalnote}; $query .= q| WHERE ordernumber = ?|; my $sth = $dbh->prepare($query); $sth->execute( ( $is_standing ? 1 : ($order->{quantity} - $quantrec) ), - ( defined $order->{order_internalnote} ? $order->{order_internalnote} : () ), $order->{ordernumber} ); + if ( not $order->{subscriptionid} && defined $order->{order_internalnote} ) { + $dbh->do(q|UPDATE aqorders + SET order_internalnote = ?|, {}, $order->{order_internalnote}); + } + # Recalculate tax_value $dbh->do(q| UPDATE aqorders diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index ebf29f703e..e57e2a6966 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -197,6 +197,8 @@ my @gst_values = map { option => $_ + 0.0 }, split( '\|', C4::Context->preference("gist") ); +my $order_internalnote = $order->{order_internalnote}; +my $order_vendornote = $order->{order_vendornote}; if ( $order->{subscriptionid} ) { # Order from a subscription, we will display an history of what has been received my $orders = Koha::Acquisition::Orders->search( @@ -206,7 +208,14 @@ if ( $order->{subscriptionid} ) { ordernumber => { '!=' => $order->{ordernumber} } } ); - $template->param( orders => $orders ); + if ( $order->{parent_ordernumber} != $order->{ordernumber} ) { + my $parent_order = Koha::Acquisition::Orders->find($order->{parent_ordernumber}); + $order_internalnote = $parent_order->{order_internalnote}; + $order_vendornote = $parent_order->{order_vendornote}; + } + $template->param( + orders => $orders, + ); } $template->param( @@ -240,8 +249,8 @@ $template->param( invoiceid => $invoice->{invoiceid}, invoice => $invoice->{invoicenumber}, datereceived => $datereceived, - order_internalnote => $order->{order_internalnote}, - order_vendornote => $order->{order_vendornote}, + order_internalnote => $order_internalnote, + order_vendornote => $order_vendornote, suggestionid => $suggestion->{suggestionid}, surnamesuggestedby => $suggestion->{surnamesuggestedby}, firstnamesuggestedby => $suggestion->{firstnamesuggestedby}, diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 28ee67c5b8..7fbc71abca 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -19,7 +19,7 @@ use Modern::Perl; use POSIX qw(strftime); -use Test::More tests => 72; +use Test::More tests => 73; use t::lib::Mocks; use Koha::Database; @@ -713,4 +713,43 @@ subtest 'ModReceiveOrder replacementprice tests' => sub { is ($received_order->{replacementprice},'16.120000',"Replacement price set if none passed in"); }; +subtest 'ModReceiveOrder and subscription' => sub { + plan tests => 2; + + my $builder = t::lib::TestBuilder->new; + my $first_note = 'first note'; + my $second_note = 'second note'; + my $subscription = $builder->build_object( { class => 'Koha::Subscriptions' } ); + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + subscriptionid => $subscription->subscriptionid, + order_internalnote => $first_note, + quantity => 5, + quantityreceived => 0, + } + } + ); + my $order_info = $order->unblessed; + # We do not want the note from the original note to be modified + # Keeping it will permit to display it for future receptions + $order_info->{order_internalnote} = $second_note; + my ( undef, my $received_ordernumber ) = ModReceiveOrder( + { + biblionumber => $order->biblionumber, + order => $order_info, + invoice => $order->{invoiceid}, + quantityreceived => 1, + budget_id => $order->budget_id, + } + ); + my $received_order = Koha::Acquisition::Orders->find($received_ordernumber); + is( $received_order->order_internalnote, + $second_note, "No price set if none passed in" ); + + $order->get_from_storage; + is( $order->get_from_storage->order_internalnote, $first_note ); +}; + $schema->storage->txn_rollback(); -- 2.39.5