From 965ec07a492ae330798c53e9e9c601e1d5a2af97 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Feb 2023 08:54:36 +0100 Subject: [PATCH] Bug 25655: Store invoice price and currency even if no currency change We could need these info to be stored even if the currency is the same as the active one, for statistic purpose for instance. --- C4/Acquisition.pm | 3 +++ t/db_dependent/Acquisition.t | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index f4e837db9a5..6873a67e854 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1383,6 +1383,9 @@ sub ModReceiveOrder { $datereceived = $datereceived ? dt_from_string( $datereceived ) : dt_from_string; $datereceived = $datereceived->ymd; + $order->{invoice_unitprice} ||= $order->{unitprice}; + $order->{invoice_currency} ||= Koha::Acquisition::Currencies->get_active->currency; + my $suggestionid = GetSuggestionFromBiblionumber( $biblionumber ); if ($suggestionid) { ModSuggestion( {suggestionid=>$suggestionid, diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 1560cf930f2..67e405d07dc 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -803,6 +803,7 @@ subtest 'ModReceiveOrder invoice_unitprice and invoice_currency' => sub { quantityreceived => 0, ecost_tax_excluded => 42, unitprice_tax_excluded => 42, + unitprice => 42, } } ); @@ -819,16 +820,17 @@ subtest 'ModReceiveOrder invoice_unitprice and invoice_currency' => sub { budget_id => $order->budget_id, } ); + my $active_currency = Koha::Acquisition::Currencies->get_active; my $received_order = Koha::Acquisition::Orders->find($received_ordernumber); is( $received_order->invoice_unitprice, - undef, 'no price should be stored if none passed' ); + $order->unitprice, 'no price should be stored if none passed' ); is( $received_order->invoice_currency, - undef, 'no currency should be stored if none passed' ); + $active_currency->currency, 'no currency should be stored if none passed' ); $order = $order->get_from_storage; - is( $order->invoice_unitprice, undef, + is( $order->invoice_unitprice, $order->unitprice, 'no price should be stored if none passed' ); - is( $order->invoice_currency, undef, + is( $order->invoice_currency, $active_currency->currency, 'no currency should be stored if none passed' ); }; subtest 'with invoice_unitprice' => sub { @@ -841,6 +843,7 @@ subtest 'ModReceiveOrder invoice_unitprice and invoice_currency' => sub { quantityreceived => 0, ecost_tax_excluded => 42, unitprice_tax_excluded => 42, + unitprice => 42, } } ); @@ -886,6 +889,7 @@ subtest 'ModReceiveOrder invoice_unitprice and invoice_currency' => sub { quantityreceived => 0, ecost_tax_excluded => 42, unitprice_tax_excluded => 42, + unitprice => 42, } } ); @@ -902,17 +906,19 @@ subtest 'ModReceiveOrder invoice_unitprice and invoice_currency' => sub { budget_id => $order->budget_id, } ); + my $active_currency = Koha::Acquisition::Currencies->get_active; my $received_order = Koha::Acquisition::Orders->find($received_ordernumber); is( $received_order->invoice_unitprice, - undef, 'no price should be stored if none passed' ); + $order->unitprice, 'no price should be stored if none passed' ); is( $received_order->invoice_currency, - undef, 'no currency should be stored if none passed' ); + $active_currency->currency, 'no currency should be stored if none passed' ); $order = $order->get_from_storage; - is( $order->invoice_unitprice, undef, + is( $order->invoice_unitprice, $order->unitprice, 'no price should be stored if none passed' ); - is( $order->invoice_currency, undef, + is( $order->invoice_currency, $active_currency->currency, 'no currency should be stored if none passed' ); + }; subtest 'with invoice_unitprice' => sub { @@ -925,6 +931,7 @@ subtest 'ModReceiveOrder invoice_unitprice and invoice_currency' => sub { quantityreceived => 0, ecost_tax_excluded => 42, unitprice_tax_excluded => 42, + unitprice => 42, } } ); -- 2.25.1