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

(-)a/Koha/Biblio.pm (+26 lines)
Lines 158-163 sub uncancelled_orders { Link Here
158
    return $self->orders->filter_out_cancelled;
158
    return $self->orders->filter_out_cancelled;
159
}
159
}
160
160
161
=head3 acq_status
162
163
    print $biblio->acq_status;
164
165
    This status can be:
166
    - unlinked:   not any linked order found in the system
167
    - acquired:   some lines are complete, rest is cancelled
168
    - cancelled:  all lines are cancelled
169
    - processing: some lines are active or new
170
171
=cut
172
173
sub acq_status {
174
    my ($self) = @_;
175
    my $orders = $self->orders;
176
    unless ( $orders->count ) {
177
        return 'unlinked';
178
    } elsif ( !$self->uncancelled_orders->count ) {
179
        return 'cancelled';
180
    } elsif ( $orders->search( { orderstatus => [ 'new', 'ordered', 'partial' ] } )->count ) {
181
        return 'processing';
182
    } else {
183
        return 'acquired';    # some lines must be complete here
184
    }
185
}
186
161
=head3 tickets
187
=head3 tickets
162
188
163
  my $tickets = $biblio->tickets();
189
  my $tickets = $biblio->tickets();
(-)a/t/db_dependent/Koha/Biblio.t (-7 / +19 lines)
Lines 896-904 subtest 'get_volumes_query' => sub { Link Here
896
    );
896
    );
897
};
897
};
898
898
899
subtest 'orders() and uncancelled_orders() tests' => sub {
899
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub {
900
900
901
    plan tests => 5;
901
    plan tests => 9;
902
902
903
    $schema->storage->txn_begin;
903
    $schema->storage->txn_begin;
904
904
Lines 919-926 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
919
            {
919
            {
920
                class => 'Koha::Acquisition::Orders',
920
                class => 'Koha::Acquisition::Orders',
921
                value => {
921
                value => {
922
                    biblionumber => $biblio->biblionumber,
922
                    biblionumber            => $biblio->biblionumber,
923
                    datecancellationprinted => '2019-12-31'
923
                    datecancellationprinted => '2019-12-31',
924
                    orderstatus             => 'cancelled',
924
                }
925
                }
925
            }
926
            }
926
        );
927
        );
Lines 930-937 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
930
        {
931
        {
931
            class => 'Koha::Acquisition::Orders',
932
            class => 'Koha::Acquisition::Orders',
932
            value => {
933
            value => {
933
                biblionumber => $biblio->biblionumber,
934
                biblionumber            => $biblio->biblionumber,
934
                datecancellationprinted => undef
935
                datecancellationprinted => undef,
936
                orderstatus             => 'ordered',
937
                quantity                => 1,
938
                quantityreceived        => 0,
935
            }
939
            }
936
        }
940
        }
937
    );
941
    );
Lines 943-948 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
943
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
947
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
944
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
948
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
945
949
950
    # Check acq status
951
    is( $biblio->acq_status, 'processing', 'Processing for presence of ordered lines' );
952
    $orders->filter_by_active->update( { orderstatus => 'new' } );
953
    is( $biblio->acq_status, 'processing', 'Still processing for presence of new lines' );
954
    $orders->filter_out_cancelled->update( { orderstatus => 'complete' } );
955
    is( $biblio->acq_status, 'acquired', 'Acquired: some complete, rest cancelled' );
956
    $orders->cancel;
957
    is( $biblio->acq_status, 'cancelled', 'Cancelled for only cancelled lines' );
958
946
    $schema->storage->txn_rollback;
959
    $schema->storage->txn_rollback;
947
};
960
};
948
961
949
- 

Return to bug 35994