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

(-)a/Koha/Biblio.pm (+26 lines)
Lines 152-157 sub uncancelled_orders { Link Here
152
    return $self->orders->filter_out_cancelled;
152
    return $self->orders->filter_out_cancelled;
153
}
153
}
154
154
155
=head3 acq_status
156
157
    print $biblio->acq_status;
158
159
    This status can be:
160
    - unlinked:   not any linked order found in the system
161
    - acquired:   some lines are complete, rest is cancelled
162
    - cancelled:  all lines are cancelled
163
    - processing: some lines are active or new
164
165
=cut
166
167
sub acq_status {
168
    my ($self) = @_;
169
    my $orders = $self->orders;
170
    unless ( $orders->count ) {
171
        return 'unlinked';
172
    } elsif ( !$self->uncancelled_orders->count ) {
173
        return 'cancelled';
174
    } elsif ( $orders->search( { orderstatus => [ 'new', 'ordered', 'partial' ] } )->count ) {
175
        return 'processing';
176
    } else {
177
        return 'acquired';    # some lines must be complete here
178
    }
179
}
180
155
=head3 tickets
181
=head3 tickets
156
182
157
  my $tickets = $biblio->tickets();
183
  my $tickets = $biblio->tickets();
(-)a/t/db_dependent/Koha/Biblio.t (-7 / +19 lines)
Lines 660-668 subtest 'get_volumes_query' => sub { Link Here
660
    );
660
    );
661
};
661
};
662
662
663
subtest 'orders() and uncancelled_orders() tests' => sub {
663
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub {
664
664
665
    plan tests => 5;
665
    plan tests => 9;
666
666
667
    $schema->storage->txn_begin;
667
    $schema->storage->txn_begin;
668
668
Lines 683-690 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
683
            {
683
            {
684
                class => 'Koha::Acquisition::Orders',
684
                class => 'Koha::Acquisition::Orders',
685
                value => {
685
                value => {
686
                    biblionumber => $biblio->biblionumber,
686
                    biblionumber            => $biblio->biblionumber,
687
                    datecancellationprinted => '2019-12-31'
687
                    datecancellationprinted => '2019-12-31',
688
                    orderstatus             => 'cancelled',
688
                }
689
                }
689
            }
690
            }
690
        );
691
        );
Lines 694-701 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
694
        {
695
        {
695
            class => 'Koha::Acquisition::Orders',
696
            class => 'Koha::Acquisition::Orders',
696
            value => {
697
            value => {
697
                biblionumber => $biblio->biblionumber,
698
                biblionumber            => $biblio->biblionumber,
698
                datecancellationprinted => undef
699
                datecancellationprinted => undef,
700
                orderstatus             => 'ordered',
701
                quantity                => 1,
702
                quantityreceived        => 0,
699
            }
703
            }
700
        }
704
        }
701
    );
705
    );
Lines 707-712 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
707
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
711
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
708
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
712
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
709
713
714
    # Check acq status
715
    is( $biblio->acq_status, 'processing', 'Processing for presence of ordered lines' );
716
    $orders->filter_by_active->update( { orderstatus => 'new' } );
717
    is( $biblio->acq_status, 'processing', 'Still processing for presence of new lines' );
718
    $orders->filter_out_cancelled->update( { orderstatus => 'complete' } );
719
    is( $biblio->acq_status, 'acquired', 'Acquired: some complete, rest cancelled' );
720
    $orders->cancel;
721
    is( $biblio->acq_status, 'cancelled', 'Cancelled for only cancelled lines' );
722
710
    $schema->storage->txn_rollback;
723
    $schema->storage->txn_rollback;
711
};
724
};
712
725
713
- 

Return to bug 35994