From c1b61d26b390cfa1556f51fd9043945ca1bc8ab4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Feb 2019 14:48:24 -0300 Subject: [PATCH] Bug 22390: (bug 15184 follow-up) Use aqorders.subscriptionid instead of biblio.serial It seems that we made a wrong assumption on bug 15184, see commit d658cb6f7ecb18845a78d4708ee63ad1126f220f Bug 15184: Do copy items for not a serial OR if items are created on ordering To know if an order has been created from a subscription we should check $order->subscriptionid instead of the $biblio->serial flag Signed-off-by: Martin Renvoize --- Koha/Acquisition/Order.pm | 2 +- t/db_dependent/Koha/Acquisition/Order.t | 73 ++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index da1e5ac7bd..2b62760415 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -248,7 +248,7 @@ sub duplicate_to { $new_order = Koha::Acquisition::Order->new($order_info)->store; - if ( not $self->biblio->serial || $self->basket->effective_create_items eq 'ordering') { # Do copy items if not a serial OR if items are created on ordering + if ( ! $self->subscriptionid || $self->basket->effective_create_items eq 'ordering') { # Do copy items if not a serial OR if items are created on ordering my $items = $self->items; while ( my ($item) = $items->next ) { my $item_info = $item->unblessed; diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index 75d369aae3..9968c8bed3 100644 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; use t::lib::TestBuilder; use t::lib::Mocks; @@ -172,3 +172,74 @@ subtest 'subscription' => sub { $schema->storage->txn_rollback; }; + +subtest 'duplicate_to | add_item' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my $item = $builder->build_sample_item; + my $order_no_sub = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => + { + biblionumber => $item->biblionumber, + subscriptionid => undef, # not linked to a subscription + } + } + ); + $order_no_sub->basket->create_items(undef)->store; # use syspref + $order_no_sub->add_item( $item->itemnumber ); + + $item = $builder->build_sample_item; + my $order_from_sub = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => + { + biblionumber => $item->biblionumber, + # Will be linked to a subscription by TestBuilder + } + } + ); + $order_from_sub->basket->create_items(undef)->store; # use syspref + $order_from_sub->add_item( $item->itemnumber ); + + my $basket_to = $builder->build_object( + { class => 'Koha::Acquisition::Baskets' }); + + subtest 'Create item on receiving' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference('AcqCreateItem', 'receiving'); + + my $duplicated_order = $order_no_sub->duplicate_to($basket_to); + is( $duplicated_order->items->count, 1, + 'Items should be copied if the original order is not created from a subscription' + ); + + $duplicated_order = $order_from_sub->duplicate_to($basket_to); + is( $duplicated_order->items->count, 0, + 'Items should not be copied if the original order is created from a subscription' + ); + }; + + subtest 'Create item on ordering' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering'); + + my $duplicated_order = $order_no_sub->duplicate_to($basket_to); + is( $duplicated_order->items->count, 1, + 'Items should be copied if items are created on ordering' + ); + + $duplicated_order = $order_from_sub->duplicate_to($basket_to); + is( $duplicated_order->items->count, 1, + 'Items should be copied if items are created on ordering, even if created from subscription' + ); + }; + + $schema->storage->txn_rollback; +}; -- 2.20.1