Bug 22390: (bug 15184 follow-up) Use aqorders.subscriptionid instead of biblio.serial
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Feb 2019 17:48:24 +0000 (14:48 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 10 Apr 2019 20:05:15 +0000 (20:05 +0000)
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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Acquisition/Order.pm
t/db_dependent/Koha/Acquisition/Order.t

index da1e5ac..2b62760 100644 (file)
@@ -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;
index 75d369a..9968c8b 100644 (file)
@@ -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;
+};