Browse Source

Bug 25750: fix fallback to ecost_tax_included/ecost_tax_excluded

If 'Actual cost' has not been set then it has the value of 0.00 which
Perl evaluates to true so this patchset resets it to 0, so the fallback
to ecost_tax_included/ecost_tax_excluded happens.

Test plan:
1. Add item to acquisition basket (make sure the vendor has: tax rate: 15%, 'List prices: Include tax', 'Invoice prices: Include tax')
2. Set 'Vendor price' = 10 and do not set 'Actual cost'
3. Save order
4. Observe basket.pl shows 'Total tax exc.' has a value of 0.00 and GST
column has value of -8.70

5. Jump into the database:
select tax_value_on_ordering from aqorders where
ordernumber=<ordernumber>;
[You can get the ordernumber from clicking on the 'Modify' line the item
is listed in]
6. Observe a negative value: -8.70

7. Apply patch and restart plack
8. Add a second item to the basket
9. Set 'Vendor price' = 10 and don't set 'Actual cost'
10. Save order
11. Observe basket.pl shows 'Total tax exc' has value of 8.70 and GST
has value of 1.30
12. Repeat step 5 and observe tax_value_on_ordering = 1.30
13. Run t/Prices.t unit test:
sudo koha-shell <instancename>
prove t/Prices.t

Sponsored-by: Horowhenua District Council, NZ

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Alex Buckley 1 year ago
committed by Jonathan Druart
parent
commit
7b66b90fe7
  1. 1
      C4/Acquisition.pm
  2. 2
      acqui/basket.pl
  3. 52
      t/Prices.t

1
C4/Acquisition.pm

@ -2882,6 +2882,7 @@ sub populate_order_with_prices {
if ( $bookseller->listincgst ) {
# The user entered the prices tax included
$order->{unitprice} += 0;
$order->{unitprice_tax_included} = $order->{unitprice};
$order->{rrp_tax_included} = $order->{rrp};

2
acqui/basket.pl

@ -459,6 +459,8 @@ sub get_order_infos {
$line{budget_name} = $budget->{budget_name};
# If we have an actual cost that should be the total, otherwise use the ecost
$line{unitprice_tax_included} += 0;
$line{unitprice_tax_excluded} += 0;
my $cost_tax_included = $line{unitprice_tax_included} || $line{ecost_tax_included};
my $cost_tax_excluded = $line{unitprice_tax_excluded} || $line{ecost_tax_excluded};
$line{total_tax_included} = get_rounded_price($cost_tax_included) * $line{quantity};

52
t/Prices.t

@ -151,7 +151,7 @@ for my $currency_format ( qw( US FR ) ) {
};
subtest 'Configuration 1: 1 1 (Vendor List prices do include tax / Invoice prices include tax)' => sub {
plan tests => 8;
plan tests => 11;
my $biblionumber_1_1 = 43;
my $order_1_1 = {
@ -250,6 +250,55 @@ for my $currency_format ( qw( US FR ) ) {
field => 'tax_value'
}
);
# When unitprice is 0.00 C4::Acquisition->populate_order_with_prices() falls back to using ecost_tax_included and ecost_tax_excluded
$order_1_1 = {
biblionumber => $biblionumber_1_1,
quantity => 1,
listprice => 10,
unitprice => '0.00',
quantityreceived => 1,
basketno => $basketno_1_1,
invoiceid => $invoiceid_1_1,
rrp => 10.00,
ecost => 10.00,
tax_rate => 0.1500,
discount => 0,
datereceived => $today
};
$order_1_1 = C4::Acquisition::populate_order_with_prices(
{
order => $order_1_1,
booksellerid => 4,
ordering => 1,
}
);
compare(
{
got => $order_1_1->{ecost_tax_included},
expected => 10.00,
conf => '1 1',
field => 'ecost_tax_included'
}
);
compare(
{
got => $order_1_1->{ecost_tax_excluded},
expected => 8.70,
conf => '1 1',
field => 'ecost_tax_excluded'
}
);
compare(
{
got => $order_1_1->{tax_value_on_ordering},
expected => 1.30,
conf => '1 1',
field => 'tax_value'
}
);
};
subtest 'Configuration 1: 1 0 (Vendor List prices include tax / Invoice prices do not include tax)' => sub {
@ -492,6 +541,7 @@ for my $currency_format ( qw( US FR ) ) {
}
);
};
}
sub compare {

Loading…
Cancel
Save