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

(-)a/Koha/Biblio.pm (-34 / +4 lines)
Lines 100-117 sub orders { Link Here
100
100
101
=head3 active_orders_count
101
=head3 active_orders_count
102
102
103
my $orders_count = $biblio->active_orders_count();
103
my $active_orders = $biblio->active_orders();
104
104
105
Returns the number of active acquisition orders related to this biblio.
105
Returns the active acquisition orders related to this biblio.
106
An order is considered active when it is not cancelled (i.e. when datecancellation
106
An order is considered active when it is not cancelled (i.e. when datecancellation
107
is not undef).
107
is not undef).
108
108
109
=cut
109
=cut
110
110
111
sub active_orders_count {
111
sub active_orders {
112
    my ( $self ) = @_;
112
    my ( $self ) = @_;
113
113
114
    return $self->orders->search({ datecancellationprinted => undef })->count;
114
    return $self->orders->search({ datecancellationprinted => undef });
115
}
115
}
116
116
117
=head3 can_article_request
117
=head3 can_article_request
Lines 411-430 sub items { Link Here
411
    return Koha::Items->_new_from_dbic( $items_rs );
411
    return Koha::Items->_new_from_dbic( $items_rs );
412
}
412
}
413
413
414
=head3 items_count
415
416
my $items_count = $biblio->items();
417
418
Returns the count of the the related Koha::Items object for this biblio
419
420
=cut
421
422
sub items_count {
423
    my ($self) = @_;
424
425
    return $self->_result->items->count;
426
}
427
428
=head3 itemtype
414
=head3 itemtype
429
415
430
my $itemtype = $biblio->itemtype();
416
my $itemtype = $biblio->itemtype();
Lines 517-538 sub subscriptions { Link Here
517
    return $self->{_subscriptions};
503
    return $self->{_subscriptions};
518
}
504
}
519
505
520
=head3 subscriptions_count
521
522
my $subscriptions_count = $self->subscriptions_count
523
524
Returns the count of the the related Koha::Subscriptions object for this biblio
525
526
IMPORTANT: this method is temporary and should not be used.
527
528
=cut
529
530
sub subscriptions_count {
531
    my ($self) = @_;
532
533
    return $self->subscriptions->count;
534
}
535
536
=head3 has_items_waiting_or_intransit
506
=head3 has_items_waiting_or_intransit
537
507
538
my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit
508
my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit
(-)a/acqui/basket.pl (-2 / +2 lines)
Lines 136-142 if ( $op eq 'delete_confirm' ) { Link Here
136
        foreach my $myorder (@orders){
136
        foreach my $myorder (@orders){
137
            my $biblionumber = $myorder->{'biblionumber'};
137
            my $biblionumber = $myorder->{'biblionumber'};
138
            my $biblio = Koha::Biblios->find( $biblionumber );
138
            my $biblio = Koha::Biblios->find( $biblionumber );
139
            my $countbiblio = $biblio->active_orders_count;
139
            my $countbiblio = $biblio->active_orders->count;
140
            my $ordernumber = $myorder->{'ordernumber'};
140
            my $ordernumber = $myorder->{'ordernumber'};
141
            my $cnt_subscriptions = $biblio->subscriptions->count;
141
            my $cnt_subscriptions = $biblio->subscriptions->count;
142
            my $itemcount = $biblio->items->count;
142
            my $itemcount = $biblio->items->count;
Lines 477-483 sub get_order_infos { Link Here
477
    my $biblionumber = $order->{'biblionumber'};
477
    my $biblionumber = $order->{'biblionumber'};
478
    if ( $biblionumber ) { # The biblio still exists
478
    if ( $biblionumber ) { # The biblio still exists
479
        my $biblio = Koha::Biblios->find( $biblionumber );
479
        my $biblio = Koha::Biblios->find( $biblionumber );
480
        my $countbiblio = $biblio->active_orders_count;
480
        my $countbiblio = $biblio->active_orders->count;
481
481
482
        my $ordernumber = $order->{'ordernumber'};
482
        my $ordernumber = $order->{'ordernumber'};
483
        my $cnt_subscriptions = $biblio->subscriptions->count;
483
        my $cnt_subscriptions = $biblio->subscriptions->count;
(-)a/acqui/parcel.pl (-1 / +1 lines)
Lines 241-247 unless( defined $invoice->{closedate} ) { Link Here
241
241
242
        my $biblionumber = $line{'biblionumber'};
242
        my $biblionumber = $line{'biblionumber'};
243
        my $biblio = Koha::Biblios->find( $biblionumber );
243
        my $biblio = Koha::Biblios->find( $biblionumber );
244
        my $countbiblio = $biblio->active_orders_count;
244
        my $countbiblio = $biblio->active_orders->count;
245
        my $ordernumber = $line{'ordernumber'};
245
        my $ordernumber = $line{'ordernumber'};
246
        my $order_object = Koha::Acquisition::Orders->find($ordernumber);
246
        my $order_object = Koha::Acquisition::Orders->find($ordernumber);
247
        my $cnt_subscriptions = $biblio ? $biblio->subscriptions->count: 0;
247
        my $cnt_subscriptions = $biblio ? $biblio->subscriptions->count: 0;
(-)a/t/db_dependent/Koha/Biblio.t (-16 / +13 lines)
Lines 92-106 subtest 'hidden_in_opac() tests' => sub { Link Here
92
    $schema->storage->txn_rollback;
92
    $schema->storage->txn_rollback;
93
};
93
};
94
94
95
subtest 'items() and items_count() tests' => sub {
95
subtest 'items() tests' => sub {
96
96
97
    plan tests => 5;
97
    plan tests => 4;
98
98
99
    $schema->storage->txn_begin;
99
    $schema->storage->txn_begin;
100
100
101
    my $biblio = $builder->build_sample_biblio();
101
    my $biblio = $builder->build_sample_biblio();
102
102
103
    is( $biblio->items_count, 0, 'No items, count is 0' );
103
    is( $biblio->items->count, 0, 'No items, count is 0' );
104
104
105
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
105
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
106
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
106
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
Lines 108-114 subtest 'items() and items_count() tests' => sub { Link Here
108
    my $items = $biblio->items;
108
    my $items = $biblio->items;
109
    is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' );
109
    is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' );
110
    is( $items->count, 2, 'Two items in resultset' );
110
    is( $items->count, 2, 'Two items in resultset' );
111
    is( $biblio->items_count, $items->count, 'items_count returns the expected value' );
112
111
113
    my @items = $biblio->items->as_list;
112
    my @items = $biblio->items->as_list;
114
    is( scalar @items, 2, 'Same result, but in list context' );
113
    is( scalar @items, 2, 'Same result, but in list context' );
Lines 496-514 subtest 'suggestions() tests' => sub { Link Here
496
    $schema->storage->txn_rollback;
495
    $schema->storage->txn_rollback;
497
};
496
};
498
497
499
subtest 'orders() and active_orders_count() tests' => sub {
498
subtest 'orders() and active_orders() tests' => sub {
500
499
501
    plan tests => 4;
500
    plan tests => 5;
502
501
503
    $schema->storage->txn_begin;
502
    $schema->storage->txn_begin;
504
503
505
    my $biblio = $builder->build_sample_biblio();
504
    my $biblio = $builder->build_sample_biblio();
506
505
507
    my $orders = $biblio->orders;
506
    my $orders        = $biblio->orders;
508
    my $active_orders_count = $biblio->active_orders_count;
507
    my $active_orders = $biblio->active_orders;
509
508
510
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
509
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
511
    is( $orders->count, $active_orders_count, '->orders_count returns the count for the resultset' );
510
    is( $biblio->orders->count, $biblio->active_orders->count, '->orders_count returns the count for the resultset' );
512
511
513
    # Add a couple orders
512
    # Add a couple orders
514
    foreach (1..2) {
513
    foreach (1..2) {
Lines 534-550 subtest 'orders() and active_orders_count() tests' => sub { Link Here
534
    );
533
    );
535
534
536
    $orders = $biblio->orders;
535
    $orders = $biblio->orders;
537
    $active_orders_count = $biblio->active_orders_count;
536
    $active_orders = $biblio->active_orders;
538
537
539
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
538
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
540
    is( $orders->count, $active_orders_count + 2, '->active_orders_count returns the rigt count' );
539
    is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
540
    is( $orders->count, $active_orders->count + 2, '->active_orders_count returns the rigt count' );
541
541
542
    $schema->storage->txn_rollback;
542
    $schema->storage->txn_rollback;
543
};
543
};
544
544
545
subtest 'subscriptions() and subscriptions_count() tests' => sub {
545
subtest 'subscriptions() tests' => sub {
546
546
547
    plan tests => 6;
547
    plan tests => 4;
548
548
549
    $schema->storage->txn_begin;
549
    $schema->storage->txn_begin;
550
550
Lines 555-561 subtest 'subscriptions() and subscriptions_count() tests' => sub { Link Here
555
        'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
555
        'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
556
    );
556
    );
557
    is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
557
    is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
558
    is( $biblio->subscriptions_count, 0, 'subscriptions_count returns the correct number' );
559
558
560
    # Add two subscriptions
559
    # Add two subscriptions
561
    foreach (1..2) {
560
    foreach (1..2) {
Lines 572-578 subtest 'subscriptions() and subscriptions_count() tests' => sub { Link Here
572
        'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
571
        'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
573
    );
572
    );
574
    is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
573
    is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
575
    is( $biblio->subscriptions_count, 2, 'subscriptions_count returns the correct number' );
576
574
577
    $schema->storage->txn_rollback;
575
    $schema->storage->txn_rollback;
578
};
576
};
579
- 

Return to bug 24467