From 243371290b6ee1f45125ec1ece6dbf4fd8ac1059 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 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. --- 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 d635a49e79..67ba8f4301 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1460,16 +1460,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 41fda545fa..ae86edb28d 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -194,6 +194,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( @@ -203,7 +205,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( @@ -233,8 +242,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 04687eb7a7..568f7e613b 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 => 70; +use Test::More tests => 71; use t::lib::Mocks; use Koha::Database; @@ -708,4 +708,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.11.0