Bug 36018: $orders->filter_by_active should check quantityreceived

An active order that has no items to receive any more is actually
not very active anymore :)

Test plan:
Run t/db_dependent/Koha/Acquisition/Orders.t
Enable OPACAcquisitionDetails.
Add order on basket for new biblio. Check that opac-detail does not
yet count the item as on order (since status is still new).
Close basket. Check opac-detail again. Should count it now.
Reopen basket. Cancel line. Check opac-detail again.

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 15:20:23 +00:00 committed by Katrin Fischer
parent 21c87aeb15
commit d563baa853
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 19 additions and 9 deletions

View file

@ -152,7 +152,8 @@ sub filter_by_lates {
Returns a new resultset containing active orders only.
Note: An active order (line) has status ordered or partial, or it has status new
and the basket is marked as standing order.
and the basket is marked as standing order. Additionally, we still expect items
on this order (checking quantity and quantityreceived).
=cut
@ -164,7 +165,8 @@ sub filter_by_active {
{ 'basket.is_standing' => 1,
'orderstatus' => [ 'new', 'ordered', 'partial' ] },
{ 'orderstatus' => [ 'ordered', 'partial' ] }
]
],
quantityreceived => { '<', \['COALESCE(quantity,0)'] },
},
{ join => 'basket' }
);

View file

@ -32,7 +32,7 @@ my $builder = t::lib::TestBuilder->new;
subtest 'filter_by_active() tests' => sub {
plan tests => 4;
plan tests => 5;
$schema->storage->txn_begin;
@ -66,29 +66,33 @@ subtest 'filter_by_active() tests' => sub {
{
class => 'Koha::Acquisition::Orders',
value => {
basketno => $basket_1->basketno,
orderstatus => 'new'
basketno => $basket_1->basketno,
orderstatus => 'new',
quantity => 1,
quantityreceived => 0,
}
}
);
my $order_4 = $builder->build_object(
{
class => 'Koha::Acquisition::Orders',
value => { orderstatus => 'ordered' }
value => { orderstatus => 'ordered', quantity => 1, quantityreceived => 0 }
}
);
my $order_5 = $builder->build_object(
{
class => 'Koha::Acquisition::Orders',
value => { orderstatus => 'partial' }
value => { orderstatus => 'partial', quantity => 2, quantityreceived => 1 }
}
);
my $order_6 = $builder->build_object(
{
class => 'Koha::Acquisition::Orders',
value => {
basketno => $basket_2->basketno,
orderstatus => 'new'
basketno => $basket_2->basketno,
orderstatus => 'new',
quantity => 1,
quantityreceived => 0,
}
}
);
@ -116,6 +120,10 @@ subtest 'filter_by_active() tests' => sub {
is( $rs->next->ordernumber, $order_4->ordernumber , 'Expected order in resultset' );
is( $rs->next->ordernumber, $order_5->ordernumber , 'Expected order in resultset' );
# If we change quantities on order_5 (partial), we should no longer see it
$order_5->quantityreceived(2)->store;
is( $this_orders_rs->filter_by_active->count, 2, 'Dropped one order as expected' );
$schema->storage->txn_rollback;
};