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 144-150 if ( $op eq 'cud-delete_confirm' ) { Link Here
144
                biblionumber  => $biblio->id,
144
                biblionumber  => $biblio->id,
145
                title         => $biblio->title // '',
145
                title         => $biblio->title // '',
146
                author        => $biblio->author // '',
146
                author        => $biblio->author // '',
147
                countbiblio   => $biblio->active_orders->count,
147
                countbiblio   => $biblio->uncancelled_orders->count,
148
                itemcount     => $biblio->items->count,
148
                itemcount     => $biblio->items->count,
149
                subscriptions => $biblio->subscriptions->count,
149
                subscriptions => $biblio->subscriptions->count,
150
            };
150
            };
Lines 473-479 sub get_order_infos { Link Here
473
    my $biblionumber = $order->{'biblionumber'};
473
    my $biblionumber = $order->{'biblionumber'};
474
    if ( $biblionumber ) { # The biblio still exists
474
    if ( $biblionumber ) { # The biblio still exists
475
        my $biblio = Koha::Biblios->find( $biblionumber );
475
        my $biblio = Koha::Biblios->find( $biblionumber );
476
        my $countbiblio = $biblio->active_orders->count;
476
        my $countbiblio = $biblio->uncancelled_orders->count;
477
477
478
        my $ordernumber       = $order->{'ordernumber'};
478
        my $ordernumber       = $order->{'ordernumber'};
479
        my $cnt_subscriptions = $biblio->subscriptions->count;
479
        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 896-902 subtest 'get_volumes_query' => sub { Link Here
896
    );
896
    );
897
};
897
};
898
898
899
subtest 'orders() and active_orders() tests' => sub {
899
subtest 'orders() and uncancelled_orders() tests' => sub {
900
900
901
    plan tests => 5;
901
    plan tests => 5;
902
902
Lines 904-914 subtest 'orders() and active_orders() tests' => sub { Link Here
904
904
905
    my $biblio = $builder->build_sample_biblio();
905
    my $biblio = $builder->build_sample_biblio();
906
906
907
    my $orders        = $biblio->orders;
907
    my $orders             = $biblio->orders;
908
    my $active_orders = $biblio->active_orders;
908
    my $uncancelled_orders = $biblio->uncancelled_orders;
909
909
910
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
910
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
911
    is( $biblio->orders->count, $biblio->active_orders->count, '->orders->count returns the count for the resultset' );
911
    is(
912
        $biblio->orders->count, $biblio->uncancelled_orders->count,
913
        '->orders->count returns the count for the resultset'
914
    );
912
915
913
    # Add a couple orders
916
    # Add a couple orders
914
    foreach (1..2) {
917
    foreach (1..2) {
Lines 933-944 subtest 'orders() and active_orders() tests' => sub { Link Here
933
        }
936
        }
934
    );
937
    );
935
938
936
    $orders = $biblio->orders;
939
    $orders             = $biblio->orders;
937
    $active_orders = $biblio->active_orders;
940
    $uncancelled_orders = $biblio->uncancelled_orders;
938
941
939
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
942
    is( ref($orders),             'Koha::Acquisition::Orders', 'Result type is correct' );
940
    is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
943
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
941
    is( $orders->count, $active_orders->count + 2, '->active_orders->count returns the rigt count' );
944
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
942
945
943
    $schema->storage->txn_rollback;
946
    $schema->storage->txn_rollback;
944
};
947
};
945
- 

Return to bug 36018