From a9714d5714042a02e8cc3a826447dcff142d76db Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 23 Jan 2023 22:27:56 +0100 Subject: [PATCH] Bug 25655: Add tests And fix a bug they caught. We need to undef if a modification is made and invoice_currency is removed. Sponsored-by: The Research University in the Helmholtz Association (KIT) Signed-off-by: Michaela Sieber Signed-off-by: Katrin Fischer --- C4/Acquisition.pm | 14 +- acqui/finishreceive.pl | 7 +- .../prog/en/modules/acqui/orderreceive.tt | 8 +- t/db_dependent/Acquisition.t | 175 +++++++++++++++++- 4 files changed, 190 insertions(+), 14 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 844dc63171..f4e837db9a 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1429,10 +1429,10 @@ sub ModReceiveOrder { $query .= q|, order_internalnote = ?|; push @params, $order->{order_internalnote}; } - if ( defined $order->{invoice_unitprice} ) { - $query .= q|, invoice_unitprice = ?, invoice_currency = ?|; - push @params, $order->{invoice_unitprice}, $order->{invoice_currency}; - } + + $query .= q|, invoice_unitprice = ?, invoice_currency = ?|; + push @params, $order->{invoice_unitprice}, $order->{invoice_currency}; + $query .= q| WHERE ordernumber = ? |; @@ -1491,7 +1491,7 @@ sub ModReceiveOrder { $query .= q| , invoice_unitprice = ?, invoice_currency = ? - | if defined $order->{invoice_unitprice}; + |; $query .= q| where biblionumber=? and ordernumber=?|; @@ -1518,9 +1518,7 @@ sub ModReceiveOrder { push @params, $order->{order_internalnote}; } - if ( defined $order->{invoice_unitprice} ) { - push @params, $order->{invoice_unitprice}, $order->{invoice_currency}; - } + push @params, $order->{invoice_unitprice}, $order->{invoice_currency}; push @params, ( $biblionumber, $order->{ordernumber} ); diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index 3c9e87ca78..7b294a9fc8 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -107,12 +107,15 @@ if ($quantityrec > $origquantityrec ) { replacementprice => $replacementprice, unitprice => $unitprice, ( - defined $invoice_unitprice && $invoice_unitprice ne '' + $invoice_unitprice && $invoice_unitprice ne '' ? ( invoice_unitprice => $invoice_unitprice, invoice_currency => $invoice_currency, ) - : () + : ( + invoice_unitprice => undef, + invoice_currency => undef, + ) ), } ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index dd2151ba29..5315d99ead 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -611,12 +611,16 @@ $("#unitprice").prop("readonly", "true"); } else { $("#select_currency").hide(); + $("#invoice_unitprice").val(""); // Empty to not store the values + $("#invoice_currency").val(""); $("#unitprice").prop("readonly", ""); } - }).change(); + }); [% IF order.invoice_unitprice %] - $("input[name='change_currency']").click().trigger('change'); + $("input[name='change_currency']").click(); + [% ELSE %] + $("input[name='change_currency']").trigger('change'); [% END %] function update_unitprice() { diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index fb2e44b5b5..1560cf930f 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -19,7 +19,7 @@ use Modern::Perl; use POSIX qw(strftime); -use Test::More tests => 71; +use Test::More tests => 72; use t::lib::Mocks; use Koha::Database; use Koha::DateUtils qw(dt_from_string output_pref); @@ -783,10 +783,181 @@ subtest 'ModReceiveOrder and subscription' => sub { is( $received_order->order_internalnote, $second_note, "No price set if none passed in" ); - $order->get_from_storage; is( $order->get_from_storage->order_internalnote, $first_note ); }; +subtest 'ModReceiveOrder invoice_unitprice and invoice_currency' => sub { + plan tests => 2; + + my $builder = t::lib::TestBuilder->new; + subtest 'partial order' => sub { + plan tests => 2; + + subtest 'no invoice_unitprice' => sub { + plan tests => 4; + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + quantity => 5, + quantityreceived => 0, + ecost_tax_excluded => 42, + unitprice_tax_excluded => 42, + } + } + ); + my $order_info = { + %{ $order->unblessed }, + invoice_unitprice => undef, + invoice_currency => undef, + }; + my ( undef, $received_ordernumber ) = ModReceiveOrder( + { + biblionumber => $order->biblionumber, + order => $order_info, + quantityreceived => 1, # We receive only 1 + budget_id => $order->budget_id, + } + ); + my $received_order = + Koha::Acquisition::Orders->find($received_ordernumber); + is( $received_order->invoice_unitprice, + undef, 'no price should be stored if none passed' ); + is( $received_order->invoice_currency, + undef, 'no currency should be stored if none passed' ); + $order = $order->get_from_storage; + is( $order->invoice_unitprice, undef, + 'no price should be stored if none passed' ); + is( $order->invoice_currency, undef, + 'no currency should be stored if none passed' ); + }; + subtest 'with invoice_unitprice' => sub { + plan tests => 4; + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + quantity => 5, + quantityreceived => 0, + ecost_tax_excluded => 42, + unitprice_tax_excluded => 42, + } + } + ); + my $order_info = { + %{ $order->unblessed }, + invoice_unitprice => 37, + invoice_currency => 'GBP', + }; + my ( undef, $received_ordernumber ) = ModReceiveOrder( + { + biblionumber => $order->biblionumber, + order => $order_info, + quantityreceived => 1, + budget_id => $order->budget_id, + } + ); + my $received_order = + Koha::Acquisition::Orders->find($received_ordernumber); + is( $received_order->invoice_unitprice + 0, + 37, 'price should be stored in new order' ); + is( $received_order->invoice_currency, + 'GBP', 'currency should be stored in new order' ); + $order = $order->get_from_storage; + is( $order->invoice_unitprice + 0, + 37, 'price should be stored in existing order' ); + is( $order->invoice_currency, 'GBP', + 'currency should be stored in existing order' ); + + }; + }; + + subtest 'full received order' => sub { + plan tests => 2; + + subtest 'no invoice_unitprice' => sub { + plan tests => 4; + my $builder = t::lib::TestBuilder->new; + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + quantity => 5, + quantityreceived => 0, + ecost_tax_excluded => 42, + unitprice_tax_excluded => 42, + } + } + ); + my $order_info = { + %{ $order->unblessed }, + invoice_unitprice => undef, + invoice_currency => undef, + }; + my ( undef, $received_ordernumber ) = ModReceiveOrder( + { + biblionumber => $order->biblionumber, + order => $order_info, + quantityreceived => 5, # We receive them all! + budget_id => $order->budget_id, + } + ); + my $received_order = + Koha::Acquisition::Orders->find($received_ordernumber); + is( $received_order->invoice_unitprice, + undef, 'no price should be stored if none passed' ); + is( $received_order->invoice_currency, + undef, 'no currency should be stored if none passed' ); + $order = $order->get_from_storage; + is( $order->invoice_unitprice, undef, + 'no price should be stored if none passed' ); + is( $order->invoice_currency, undef, + 'no currency should be stored if none passed' ); + }; + + subtest 'with invoice_unitprice' => sub { + plan tests => 4; + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + quantity => 5, + quantityreceived => 0, + ecost_tax_excluded => 42, + unitprice_tax_excluded => 42, + } + } + ); + my $order_info = { + %{ $order->unblessed }, + invoice_unitprice => 37, + invoice_currency => 'GBP', + }; + my ( undef, $received_ordernumber ) = ModReceiveOrder( + { + biblionumber => $order->biblionumber, + order => $order_info, + quantityreceived => 1, + budget_id => $order->budget_id, + } + ); + my $received_order = + Koha::Acquisition::Orders->find($received_ordernumber); + is( $received_order->invoice_unitprice + 0, + 37, 'price should be stored in new order' ); + is( $received_order->invoice_currency, + 'GBP', 'currency should be stored in new order' ); + $order = $order->get_from_storage; + is( $order->invoice_unitprice + 0, + 37, 'price should be stored in existing order' ); + is( $order->invoice_currency, 'GBP', + 'currency should be stored in existing order' ); + + }; + }; + +}; + subtest 'GetHistory with additional fields' => sub { plan tests => 3; my $builder = t::lib::TestBuilder->new; -- 2.30.2