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 138-157 sub orders { Link Here
138
    return Koha::Acquisition::Orders->_new_from_dbic($orders);
138
    return Koha::Acquisition::Orders->_new_from_dbic($orders);
139
}
139
}
140
140
141
=head3 active_orders
141
=head3 uncancelled_orders
142
142
143
my $active_orders = $biblio->active_orders();
143
my $uncancelled_orders = $biblio->uncancelled_orders;
144
144
145
Returns the active acquisition orders related to this biblio.
145
Returns acquisition orders related to this biblio that are not cancelled.
146
An order is considered active when it is not cancelled (i.e. when datecancellation
147
is not undef).
148
146
149
=cut
147
=cut
150
148
151
sub active_orders {
149
sub uncancelled_orders {
152
    my ( $self ) = @_;
150
    my ( $self ) = @_;
153
151
154
    return $self->orders->search({ datecancellationprinted => undef });
152
    return $self->orders->filter_out_cancelled;
155
}
153
}
156
154
157
=head3 tickets
155
=head3 tickets
(-)a/acqui/basket.pl (-2 / +2 lines)
Lines 144-150 if ( $op eq '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 | html %];
6
    var count = [% count | html %];
7
    var holdcount = [% holdcount | html %];
7
    var holdcount = [% holdcount | 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 392-398 Link Here
392
                },
392
                },
393
                "embed": [
393
                "embed": [
394
                    "basket.basket_group",
394
                    "basket.basket_group",
395
                    "biblio.active_orders+count",
395
                    "biblio.uncancelled_orders+count",
396
                    "biblio.holds+count",
396
                    "biblio.holds+count",
397
                    "biblio.items+count",
397
                    "biblio.items+count",
398
                    "biblio.suggestions.suggester",
398
                    "biblio.suggestions.suggester",
Lines 606-612 Link Here
606
606
607
                            if ( row.biblio != null ) {
607
                            if ( row.biblio != null ) {
608
                                if ( row.biblio.items_count - row.items.length > 0 ||
608
                                if ( row.biblio.items_count - row.items.length > 0 ||
609
                                    row.biblio.active_orders_count > 1 ||
609
                                    row.biblio.uncancelled_orders_count > 1 ||
610
                                    row.biblio.subscriptions_count > 0 ||
610
                                    row.biblio.subscriptions_count > 0 ||
611
                                    row.biblio.holds_count > 0 ) { // biblio can be deleted
611
                                    row.biblio.holds_count > 0 ) { // biblio can be deleted
612
                                    result += '<span class="button" title="'
612
                                    result += '<span class="button" title="'
Lines 626-635 Link Here
626
                                            +'">' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '</strong><br/>';
626
                                            +'">' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '</strong><br/>';
627
                                }
627
                                }
628
628
629
                                if ( row.biblio.active_orders_count > 1 ) {
629
                                if ( row.biblio.uncancelled_orders_count > 1 ) {
630
                                    result += '<strong title="'
630
                                    result += '<strong title="'
631
                                            + _("Can't delete catalog record, delete other orders linked to it first") + '">'
631
                                            + _("Can't delete catalog record, delete other orders linked to it first") + '">'
632
                                            + (row.biblio.active_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
632
                                            + (row.biblio.uncancelled_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
633
                                }
633
                                }
634
634
635
                                if ( row.biblio.subscriptions_count > 0 ) {
635
                                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 660-666 subtest 'get_volumes_query' => sub { Link Here
660
    );
660
    );
661
};
661
};
662
662
663
subtest 'orders() and active_orders() tests' => sub {
663
subtest 'orders() and uncancelled_orders() tests' => sub {
664
664
665
    plan tests => 5;
665
    plan tests => 5;
666
666
Lines 668-678 subtest 'orders() and active_orders() tests' => sub { Link Here
668
668
669
    my $biblio = $builder->build_sample_biblio();
669
    my $biblio = $builder->build_sample_biblio();
670
670
671
    my $orders        = $biblio->orders;
671
    my $orders             = $biblio->orders;
672
    my $active_orders = $biblio->active_orders;
672
    my $uncancelled_orders = $biblio->uncancelled_orders;
673
673
674
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
674
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
675
    is( $biblio->orders->count, $biblio->active_orders->count, '->orders->count returns the count for the resultset' );
675
    is(
676
        $biblio->orders->count, $biblio->uncancelled_orders->count,
677
        '->orders->count returns the count for the resultset'
678
    );
676
679
677
    # Add a couple orders
680
    # Add a couple orders
678
    foreach (1..2) {
681
    foreach (1..2) {
Lines 697-708 subtest 'orders() and active_orders() tests' => sub { Link Here
697
        }
700
        }
698
    );
701
    );
699
702
700
    $orders = $biblio->orders;
703
    $orders             = $biblio->orders;
701
    $active_orders = $biblio->active_orders;
704
    $uncancelled_orders = $biblio->uncancelled_orders;
702
705
703
    is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
706
    is( ref($orders),             'Koha::Acquisition::Orders', 'Result type is correct' );
704
    is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
707
    is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
705
    is( $orders->count, $active_orders->count + 2, '->active_orders->count returns the rigt count' );
708
    is( $orders->count, $uncancelled_orders->count + 2,        '->uncancelled_orders->count returns the right count' );
706
709
707
    $schema->storage->txn_rollback;
710
    $schema->storage->txn_rollback;
708
};
711
};
709
- 

Return to bug 36018