View | Details | Raw Unified | Return to bug 22390
Collapse All | Expand All

(-)a/Koha/Acquisition/Order.pm (-1 / +1 lines)
Lines 248-254 sub duplicate_to { Link Here
248
248
249
            $new_order = Koha::Acquisition::Order->new($order_info)->store;
249
            $new_order = Koha::Acquisition::Order->new($order_info)->store;
250
250
251
            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
251
            if ( ! $self->subscriptionid || $self->basket->effective_create_items eq 'ordering') { # Do copy items if not a serial OR if items are created on ordering
252
                my $items = $self->items;
252
                my $items = $self->items;
253
                while ( my ($item) = $items->next ) {
253
                while ( my ($item) = $items->next ) {
254
                    my $item_info = $item->unblessed;
254
                    my $item_info = $item->unblessed;
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-2 / +72 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 172-174 subtest 'subscription' => sub { Link Here
172
172
173
    $schema->storage->txn_rollback;
173
    $schema->storage->txn_rollback;
174
};
174
};
175
- 
175
176
subtest 'duplicate_to | add_item' => sub {
177
    plan tests => 2;
178
179
    $schema->storage->txn_begin;
180
181
    my $item = $builder->build_sample_item;
182
    my $order_no_sub = $builder->build_object(
183
        {
184
            class => 'Koha::Acquisition::Orders',
185
            value =>
186
              {
187
                  biblionumber => $item->biblionumber,
188
                  subscriptionid => undef, # not linked to a subscription
189
              }
190
        }
191
    );
192
    $order_no_sub->basket->create_items(undef)->store; # use syspref
193
    $order_no_sub->add_item( $item->itemnumber );
194
195
    $item = $builder->build_sample_item;
196
    my $order_from_sub = $builder->build_object(
197
        {
198
            class => 'Koha::Acquisition::Orders',
199
            value =>
200
              {
201
                  biblionumber => $item->biblionumber,
202
                  # Will be linked to a subscription by TestBuilder
203
              }
204
        }
205
    );
206
    $order_from_sub->basket->create_items(undef)->store; # use syspref
207
    $order_from_sub->add_item( $item->itemnumber );
208
209
    my $basket_to = $builder->build_object(
210
         { class => 'Koha::Acquisition::Baskets' });
211
212
    subtest 'Create item on receiving' => sub {
213
        plan tests => 2;
214
215
        t::lib::Mocks::mock_preference('AcqCreateItem', 'receiving');
216
217
        my $duplicated_order = $order_no_sub->duplicate_to($basket_to);
218
        is( $duplicated_order->items->count, 1,
219
            'Items should be copied if the original order is not created from a subscription'
220
        );
221
222
        $duplicated_order = $order_from_sub->duplicate_to($basket_to);
223
        is( $duplicated_order->items->count, 0,
224
            'Items should not be copied if the original order is created from a subscription'
225
        );
226
    };
227
228
    subtest 'Create item on ordering' => sub {
229
        plan tests => 2;
230
231
        t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering');
232
233
        my $duplicated_order = $order_no_sub->duplicate_to($basket_to);
234
        is( $duplicated_order->items->count, 1,
235
            'Items should be copied if items are created on ordering'
236
        );
237
238
        $duplicated_order = $order_from_sub->duplicate_to($basket_to);
239
        is( $duplicated_order->items->count, 1,
240
            'Items should be copied if items are created on ordering, even if created from subscription'
241
        );
242
    };
243
244
    $schema->storage->txn_rollback;
245
};

Return to bug 22390