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

(-)a/Koha/Acquisition/Order.pm (-3 / +3 lines)
Lines 161-167 sub cancel { Link Here
161
    if ( $biblio and $delete_biblio ) {
161
    if ( $biblio and $delete_biblio ) {
162
162
163
        if (
163
        if (
164
            $biblio->active_orders->search(
164
            $biblio->uncancelled_orders->search(
165
                { ordernumber => { '!=' => $self->ordernumber } }
165
                { ordernumber => { '!=' => $self->ordernumber } }
166
            )->count == 0
166
            )->count == 0
167
            and $biblio->subscriptions->count == 0
167
            and $biblio->subscriptions->count == 0
Lines 182-191 sub cancel { Link Here
182
182
183
            my $message;
183
            my $message;
184
184
185
            if ( $biblio->active_orders->search(
185
            if ( $biblio->uncancelled_orders->search(
186
                { ordernumber => { '!=' => $self->ordernumber } }
186
                { ordernumber => { '!=' => $self->ordernumber } }
187
            )->count > 0 ) {
187
            )->count > 0 ) {
188
                $message = 'error_delbiblio_active_orders';
188
                $message = 'error_delbiblio_uncancelled_orders';
189
            }
189
            }
190
            elsif ( $biblio->subscriptions->count > 0 ) {
190
            elsif ( $biblio->subscriptions->count > 0 ) {
191
                $message = 'error_delbiblio_subscriptions';
191
                $message = 'error_delbiblio_subscriptions';
(-)a/Koha/Biblio.pm (-7 / +5 lines)
Lines 144-163 sub orders { Link Here
144
    return Koha::Acquisition::Orders->_new_from_dbic($orders);
144
    return Koha::Acquisition::Orders->_new_from_dbic($orders);
145
}
145
}
146
146
147
=head3 active_orders
147
=head3 uncancelled_orders
148
148
149
my $active_orders = $biblio->active_orders();
149
my $uncancelled_orders = $biblio->uncancelled_orders;
150
150
151
Returns the active acquisition orders related to this biblio.
151
Returns acquisition orders related to this biblio that are not cancelled.
152
An order is considered active when it is not cancelled (i.e. when datecancellation
153
is not undef).
154
152
155
=cut
153
=cut
156
154
157
sub active_orders {
155
sub uncancelled_orders {
158
    my ( $self ) = @_;
156
    my ( $self ) = @_;
159
157
160
    return $self->orders->search({ datecancellationprinted => undef });
158
    return $self->orders->filter_out_cancelled;
161
}
159
}
162
160
163
=head3 tickets
161
=head3 tickets
(-)a/acqui/basket.pl (-2 / +2 lines)
Lines 160-166 if ( $op eq 'cud-delete-order' ) { Link Here
160
                biblionumber  => $biblio->id,
160
                biblionumber  => $biblio->id,
161
                title         => $biblio->title // '',
161
                title         => $biblio->title // '',
162
                author        => $biblio->author // '',
162
                author        => $biblio->author // '',
163
                countbiblio   => $biblio->active_orders->count,
163
                countbiblio   => $biblio->uncancelled_orders->count,
164
                itemcount     => $biblio->items->count,
164
                itemcount     => $biblio->items->count,
165
                subscriptions => $biblio->subscriptions->count,
165
                subscriptions => $biblio->subscriptions->count,
166
            };
166
            };
Lines 489-495 sub get_order_infos { Link Here
489
    my $biblionumber = $order->{'biblionumber'};
489
    my $biblionumber = $order->{'biblionumber'};
490
    if ( $biblionumber ) { # The biblio still exists
490
    if ( $biblionumber ) { # The biblio still exists
491
        my $biblio = Koha::Biblios->find( $biblionumber );
491
        my $biblio = Koha::Biblios->find( $biblionumber );
492
        my $countbiblio = $biblio->active_orders->count;
492
        my $countbiblio = $biblio->uncancelled_orders->count;
493
493
494
        my $ordernumber       = $order->{'ordernumber'};
494
        my $ordernumber       = $order->{'ordernumber'};
495
        my $cnt_subscriptions = $biblio->subscriptions->count;
495
        my $cnt_subscriptions = $biblio->subscriptions->count;
(-)a/api/v1/swagger/paths/acquisitions_orders.yaml (-2 / +2 lines)
Lines 54-60 Link Here
54
            - basket.basket_group
54
            - basket.basket_group
55
            - basket.creator
55
            - basket.creator
56
            - biblio
56
            - biblio
57
            - biblio.active_orders+count
57
            - biblio.uncancelled_orders+count
58
            - biblio.holds+count
58
            - biblio.holds+count
59
            - biblio.items+count
59
            - biblio.items+count
60
            - biblio.suggestions.suggester
60
            - biblio.suggestions.suggester
Lines 174-180 Link Here
174
            - basket.basket_group
174
            - basket.basket_group
175
            - basket.creator
175
            - basket.creator
176
            - biblio
176
            - biblio
177
            - biblio.active_orders+count
177
            - biblio.uncancelled_orders+count
178
            - biblio.holds+count
178
            - biblio.holds+count
179
            - biblio.items+count
179
            - biblio.items+count
180
            - biblio.suggestions.suggester
180
            - biblio.suggestions.suggester
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-strings.inc (-1 / +1 lines)
Lines 6-12 Link Here
6
    var count = [% count || 0 | html %];
6
    var count = [% count || 0 | html %];
7
    var holdcount = [% holdcount || 0 | html %];
7
    var holdcount = [% holdcount || 0 | html %];
8
    [% SET orders = biblio.orders %]
8
    [% SET orders = biblio.orders %]
9
    [% SET current   = Context.Scalar(orders, "filter_by_current") %]
9
    [% SET current   = Context.Scalar(orders, "filter_out_cancelled") %]
10
    [% SET cancelled = Context.Scalar(orders, "filter_by_cancelled") %]
10
    [% SET cancelled = Context.Scalar(orders, "filter_by_cancelled") %]
11
    var countorders = [% current.count || 0 | html %];
11
    var countorders = [% current.count || 0 | html %];
12
    var countdeletedorders = [% cancelled.count || 0 | html %];
12
    var countdeletedorders = [% cancelled.count || 0 | html %];
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt (-4 / +4 lines)
Lines 404-410 Link Here
404
                },
404
                },
405
                "embed": [
405
                "embed": [
406
                    "basket.basket_group",
406
                    "basket.basket_group",
407
                    "biblio.active_orders+count",
407
                    "biblio.uncancelled_orders+count",
408
                    "biblio.holds+count",
408
                    "biblio.holds+count",
409
                    "biblio.items+count",
409
                    "biblio.items+count",
410
                    "biblio.suggestions.suggester",
410
                    "biblio.suggestions.suggester",
Lines 618-624 Link Here
618
618
619
                            if ( row.biblio != null ) {
619
                            if ( row.biblio != null ) {
620
                                if ( row.biblio.items_count - row.items.length > 0 ||
620
                                if ( row.biblio.items_count - row.items.length > 0 ||
621
                                    row.biblio.active_orders_count > 1 ||
621
                                    row.biblio.uncancelled_orders_count > 1 ||
622
                                    row.biblio.subscriptions_count > 0 ||
622
                                    row.biblio.subscriptions_count > 0 ||
623
                                    row.biblio.holds_count > 0 ) { // biblio can be deleted
623
                                    row.biblio.holds_count > 0 ) { // biblio can be deleted
624
                                    result += '<span class="button" title="'
624
                                    result += '<span class="button" title="'
Lines 638-647 Link Here
638
                                            +'">' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '</strong><br/>';
638
                                            +'">' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '</strong><br/>';
639
                                }
639
                                }
640
640
641
                                if ( row.biblio.active_orders_count > 1 ) {
641
                                if ( row.biblio.uncancelled_orders_count > 1 ) {
642
                                    result += '<strong title="'
642
                                    result += '<strong title="'
643
                                            + _("Can't delete catalog record, delete other orders linked to it first") + '">'
643
                                            + _("Can't delete catalog record, delete other orders linked to it first") + '">'
644
                                            + (row.biblio.active_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
644
                                            + (row.biblio.uncancelled_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
645
                                }
645
                                }
646
646
647
                                if ( row.biblio.subscriptions_count > 0 ) {
647
                                if ( row.biblio.subscriptions_count > 0 ) {
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-1 / +1 lines)
Lines 816-822 subtest 'cancel() tests' => sub { Link Here
816
    is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
816
    is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
817
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
817
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
818
    @messages = @{ $order->object_messages };
818
    @messages = @{ $order->object_messages };
819
    is( $messages[0]->message, 'error_delbiblio_active_orders', 'Cannot delete biblio and it gets notified' );
819
    is( $messages[0]->message, 'error_delbiblio_uncancelled_orders', 'Cannot delete biblio and it gets notified' );
820
820
821
    # Scenario:
821
    # Scenario:
822
    # * order with one item attached
822
    # * order with one item attached
(-)a/t/db_dependent/Koha/Biblio.t (-10 / +12 lines)
Lines 942-948 subtest 'get_volumes_query' => sub { Link Here
942
    );
942
    );
943
};
943
};
944
944
945
subtest 'orders() and active_orders() tests' => sub {
945
subtest 'orders() and uncancelled_orders() tests' => sub {
946
946
947
    plan tests => 5;
947
    plan tests => 5;
948
948
Lines 950-960 subtest 'orders() and active_orders() tests' => sub { Link Here
950
950
951
    my $biblio = $builder->build_sample_biblio();
951
    my $biblio = $builder->build_sample_biblio();
952
952
953
    my $orders        = $biblio->orders;
953
    my $orders             = $biblio->orders;
954
    my $active_orders = $biblio->active_orders;
954
    my $uncancelled_orders = $biblio->uncancelled_orders;
955
955
956
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
956
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
957
    is( $biblio->orders->count, $biblio->active_orders->count, '->orders->count returns the count for the resultset' );
957
    is(
958
        $biblio->orders->count, $biblio->uncancelled_orders->count,
959
        '->orders->count returns the count for the resultset'
960
    );
958
961
959
    # Add a couple orders
962
    # Add a couple orders
960
    foreach (1..2) {
963
    foreach (1..2) {
Lines 979-990 subtest 'orders() and active_orders() tests' => sub { Link Here
979
        }
982
        }
980
    );
983
    );
981
984
982
    $orders = $biblio->orders;
985
    $orders             = $biblio->orders;
983
    $active_orders = $biblio->active_orders;
986
    $uncancelled_orders = $biblio->uncancelled_orders;
984
987
985
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
988
    is( ref($orders),             'Koha::Acquisition::Orders', 'Result type is correct' );
986
    is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
989
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
987
    is( $orders->count, $active_orders->count + 2, '->active_orders->count returns the rigt count' );
990
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
988
991
989
    $schema->storage->txn_rollback;
992
    $schema->storage->txn_rollback;
990
};
993
};
991
- 

Return to bug 36018