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 942-950 subtest 'get_volumes_query' => sub { Link Here
942
    );
942
    );
943
};
943
};
944
944
945
subtest 'orders() and uncancelled_orders() tests' => sub {
945
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub {
946
946
947
    plan tests => 5;
947
    plan tests => 9;
948
948
949
    $schema->storage->txn_begin;
949
    $schema->storage->txn_begin;
950
950
Lines 965-972 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
965
            {
965
            {
966
                class => 'Koha::Acquisition::Orders',
966
                class => 'Koha::Acquisition::Orders',
967
                value => {
967
                value => {
968
                    biblionumber => $biblio->biblionumber,
968
                    biblionumber            => $biblio->biblionumber,
969
                    datecancellationprinted => '2019-12-31'
969
                    datecancellationprinted => '2019-12-31',
970
                    orderstatus             => 'cancelled',
970
                }
971
                }
971
            }
972
            }
972
        );
973
        );
Lines 976-983 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
976
        {
977
        {
977
            class => 'Koha::Acquisition::Orders',
978
            class => 'Koha::Acquisition::Orders',
978
            value => {
979
            value => {
979
                biblionumber => $biblio->biblionumber,
980
                biblionumber            => $biblio->biblionumber,
980
                datecancellationprinted => undef
981
                datecancellationprinted => undef,
982
                orderstatus             => 'ordered',
983
                quantity                => 1,
984
                quantityreceived        => 0,
981
            }
985
            }
982
        }
986
        }
983
    );
987
    );
Lines 989-994 subtest 'orders() and uncancelled_orders() tests' => sub { Link Here
989
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
993
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
990
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
994
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
991
995
996
    # Check acq status
997
    is( $biblio->acq_status, 'processing', 'Processing for presence of ordered lines' );
998
    $orders->filter_by_active->update( { orderstatus => 'new' } );
999
    is( $biblio->acq_status, 'processing', 'Still processing for presence of new lines' );
1000
    $orders->filter_out_cancelled->update( { orderstatus => 'complete' } );
1001
    is( $biblio->acq_status, 'acquired', 'Acquired: some complete, rest cancelled' );
1002
    $orders->cancel;
1003
    is( $biblio->acq_status, 'cancelled', 'Cancelled for only cancelled lines' );
1004
992
    $schema->storage->txn_rollback;
1005
    $schema->storage->txn_rollback;
993
};
1006
};
994
1007
995
- 

Return to bug 35994