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 <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-01-23 22:27:56 +01:00 committed by Tomas Cohen Arazi
parent a5d214bd78
commit f4b74f6c1f
4 changed files with 190 additions and 14 deletions

View File

@ -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} );

View File

@ -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,
)
),
}
);

View File

@ -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() {

View File

@ -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;