From d8da77bd8b57c1957bffe81df5679c096236e104 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 27 Oct 2016 00:51:42 +0000 Subject: [PATCH] Bug 13321 - (QA Followup) Restore standing order functionality Some lines deleted during rebase, restored and updated, tests repaired Signed-off-by: Kyle M Hall --- C4/Acquisition.pm | 10 +++++-- t/db_dependent/Acquisition/StandingOrders.t | 33 ++++++++++++++------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 355c914ea7..3ccdca1557 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1380,8 +1380,14 @@ sub ModReceiveOrder { ); } + my $result_set = $dbh->selectrow_arrayref( + q{SELECT aqbasket.is_standing + FROM aqbasket + WHERE basketno=?},{ Slice => {} }, $order->{basketno}); + my $is_standing = $result_set->[0]; # we assume we have a unique basket + my $new_ordernumber = $order->{ordernumber}; - if ( $order->{quantity} > $quantrec ) { + if ( $is_standing || $order->{quantity} > $quantrec ) { # Split order line in two parts: the first is the original order line # without received items (the quantity is decreased), # the second part is a new order line with quantity=quantityrec @@ -1395,7 +1401,7 @@ sub ModReceiveOrder { my $sth = $dbh->prepare($query); $sth->execute( - $order->{quantity} - $quantrec, + ( $is_standing ? 1 : ($order->{quantity} - $quantrec) ), ( defined $order->{order_internalnote} ? $order->{order_internalnote} : () ), $order->{ordernumber} ); diff --git a/t/db_dependent/Acquisition/StandingOrders.t b/t/db_dependent/Acquisition/StandingOrders.t index 32f1b466ec..d067747b64 100644 --- a/t/db_dependent/Acquisition/StandingOrders.t +++ b/t/db_dependent/Acquisition/StandingOrders.t @@ -56,13 +56,26 @@ is( $basket->{is_standing}, 1, 'basket correctly created as standing order baske my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( MARC::Record->new, '' ); + my $ordernumber = Koha::Acquisition::Order->new( { - basketno => $basketno, - biblionumber => $biblionumber, - budget_id => $budget->{budget_id}, - currency => 'USD', - quantity => 0, + basketno => $basketno, + biblionumber => $biblionumber, + budget_id => $budget->{budget_id}, + currency => 'USD', + quantity => 0, + rrp => 42, + rrp_tax_included => 42, + rrp_tax_excluded => 42, + ecost => 22, + ecost_tax_included => 22, + ecost_tax_excluded => 22, + unitprice => 12, + unitprice_tax_included => 12, + unitprice_tax_excluded => 12, + tax_rate => 0, + tax_rate_on_ordering => 0, + tax_rate_on_receiving => 0, } )->insert->{ordernumber}; @@ -85,21 +98,21 @@ my $invoiceid = AddInvoice( unknown => "unknown" ); +my $order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } ); + my ( $datereceived, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber, - ordernumber => $ordernumber, + order => $order, quantityreceived => 2, - cost => 12, - ecost => 22, invoiceid => $invoiceid, - rrp => 42, } ); isnt( $ordernumber, $new_ordernumber, "standing order split on receive" ); -my $order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } ); +#order has been updated, refetch +$order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } ); my $neworder = Koha::Acquisition::Order->fetch( { ordernumber => $new_ordernumber } ); is( $order->{orderstatus}, 'partial', 'original order set to partially received' ); -- 2.39.5