Bug 36018: biblio->active_orders should be ->uncancelled_orders

Active orders are more than just not cancelled. See filter_by_active
in Koha::Acquisition::Orders. They are still in the acq process; we
still need to receive items on those orders.

When we cancel and want to delete a biblio, we should check for not
cancelled orders (broader than active orders as in Orders.pm).

Test plan:
Git grep active_orders.
Run t/db_dependent/Koha/Biblio.t
Run t/db_dependent/Koha/Acquisition/Order.t
Add two order lines in a basket referring to same biblio. Try to
cancel with delete biblio. Should not be possible.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Janusz Kaczmarek <januszop@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Marcel de Rooy 2024-02-21 14:39:00 +00:00 committed by Katrin Fischer
parent b7448dbd75
commit 21c87aeb15
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
8 changed files with 30 additions and 29 deletions

View File

@ -161,7 +161,7 @@ sub cancel {
if ( $biblio and $delete_biblio ) {
if (
$biblio->active_orders->search(
$biblio->uncancelled_orders->search(
{ ordernumber => { '!=' => $self->ordernumber } }
)->count == 0
and $biblio->subscriptions->count == 0
@ -182,10 +182,10 @@ sub cancel {
my $message;
if ( $biblio->active_orders->search(
if ( $biblio->uncancelled_orders->search(
{ ordernumber => { '!=' => $self->ordernumber } }
)->count > 0 ) {
$message = 'error_delbiblio_active_orders';
$message = 'error_delbiblio_uncancelled_orders';
}
elsif ( $biblio->subscriptions->count > 0 ) {
$message = 'error_delbiblio_subscriptions';

View File

@ -144,20 +144,18 @@ sub orders {
return Koha::Acquisition::Orders->_new_from_dbic($orders);
}
=head3 active_orders
=head3 uncancelled_orders
my $active_orders = $biblio->active_orders();
my $uncancelled_orders = $biblio->uncancelled_orders;
Returns the active acquisition orders related to this biblio.
An order is considered active when it is not cancelled (i.e. when datecancellation
is not undef).
Returns acquisition orders related to this biblio that are not cancelled.
=cut
sub active_orders {
sub uncancelled_orders {
my ( $self ) = @_;
return $self->orders->search({ datecancellationprinted => undef });
return $self->orders->filter_out_cancelled;
}
=head3 tickets

View File

@ -160,7 +160,7 @@ if ( $op eq 'cud-delete-order' ) {
biblionumber => $biblio->id,
title => $biblio->title // '',
author => $biblio->author // '',
countbiblio => $biblio->active_orders->count,
countbiblio => $biblio->uncancelled_orders->count,
itemcount => $biblio->items->count,
subscriptions => $biblio->subscriptions->count,
};
@ -489,7 +489,7 @@ sub get_order_infos {
my $biblionumber = $order->{'biblionumber'};
if ( $biblionumber ) { # The biblio still exists
my $biblio = Koha::Biblios->find( $biblionumber );
my $countbiblio = $biblio->active_orders->count;
my $countbiblio = $biblio->uncancelled_orders->count;
my $ordernumber = $order->{'ordernumber'};
my $cnt_subscriptions = $biblio->subscriptions->count;

View File

@ -54,7 +54,7 @@
- basket.basket_group
- basket.creator
- biblio
- biblio.active_orders+count
- biblio.uncancelled_orders+count
- biblio.holds+count
- biblio.items+count
- biblio.suggestions.suggester
@ -174,7 +174,7 @@
- basket.basket_group
- basket.creator
- biblio
- biblio.active_orders+count
- biblio.uncancelled_orders+count
- biblio.holds+count
- biblio.items+count
- biblio.suggestions.suggester

View File

@ -6,7 +6,7 @@
var count = [% count || 0 | html %];
var holdcount = [% holdcount || 0 | html %];
[% SET orders = biblio.orders %]
[% SET current = Context.Scalar(orders, "filter_by_current") %]
[% SET current = Context.Scalar(orders, "filter_out_cancelled") %]
[% SET cancelled = Context.Scalar(orders, "filter_by_cancelled") %]
var countorders = [% current.count || 0 | html %];
var countdeletedorders = [% cancelled.count || 0 | html %];

View File

@ -404,7 +404,7 @@
},
"embed": [
"basket.basket_group",
"biblio.active_orders+count",
"biblio.uncancelled_orders+count",
"biblio.holds+count",
"biblio.items+count",
"biblio.suggestions.suggester",
@ -618,7 +618,7 @@
if ( row.biblio != null ) {
if ( row.biblio.items_count - row.items.length > 0 ||
row.biblio.active_orders_count > 1 ||
row.biblio.uncancelled_orders_count > 1 ||
row.biblio.subscriptions_count > 0 ||
row.biblio.holds_count > 0 ) { // biblio can be deleted
result += '<span class="button" title="'
@ -638,10 +638,10 @@
+'">' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '</strong><br/>';
}
if ( row.biblio.active_orders_count > 1 ) {
if ( row.biblio.uncancelled_orders_count > 1 ) {
result += '<strong title="'
+ _("Can't delete catalog record, delete other orders linked to it first") + '">'
+ (row.biblio.active_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
+ (row.biblio.uncancelled_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
}
if ( row.biblio.subscriptions_count > 0 ) {

View File

@ -816,7 +816,7 @@ subtest 'cancel() tests' => sub {
is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
@messages = @{ $order->object_messages };
is( $messages[0]->message, 'error_delbiblio_active_orders', 'Cannot delete biblio and it gets notified' );
is( $messages[0]->message, 'error_delbiblio_uncancelled_orders', 'Cannot delete biblio and it gets notified' );
# Scenario:
# * order with one item attached

View File

@ -942,7 +942,7 @@ subtest 'get_volumes_query' => sub {
);
};
subtest 'orders() and active_orders() tests' => sub {
subtest 'orders() and uncancelled_orders() tests' => sub {
plan tests => 5;
@ -950,11 +950,14 @@ subtest 'orders() and active_orders() tests' => sub {
my $biblio = $builder->build_sample_biblio();
my $orders = $biblio->orders;
my $active_orders = $biblio->active_orders;
my $orders = $biblio->orders;
my $uncancelled_orders = $biblio->uncancelled_orders;
is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
is( $biblio->orders->count, $biblio->active_orders->count, '->orders->count returns the count for the resultset' );
is(
$biblio->orders->count, $biblio->uncancelled_orders->count,
'->orders->count returns the count for the resultset'
);
# Add a couple orders
foreach (1..2) {
@ -979,12 +982,12 @@ subtest 'orders() and active_orders() tests' => sub {
}
);
$orders = $biblio->orders;
$active_orders = $biblio->active_orders;
$orders = $biblio->orders;
$uncancelled_orders = $biblio->uncancelled_orders;
is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
is( $orders->count, $active_orders->count + 2, '->active_orders->count returns the rigt count' );
is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
is( $orders->count, $uncancelled_orders->count + 2, '->uncancelled_orders->count returns the right count' );
$schema->storage->txn_rollback;
};