From 3bbf6384492834055d38ac844521be6c02d503ab Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sun, 14 Jun 2020 22:41:03 +0000 Subject: [PATCH] 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=; [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 prove t/Prices.t Sponsored-by: Horowhenua District Council, NZ Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart (cherry picked from commit 7b66b90fe707e8ac650a1c85d87560fc2f4a223d) --- C4/Acquisition.pm | 1 + acqui/basket.pl | 2 ++ t/Prices.t | 52 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index d0af10f0f9..3aff14d667 100644 --- a/C4/Acquisition.pm +++ b/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}; diff --git a/acqui/basket.pl b/acqui/basket.pl index 5f292d3624..bfe06ea158 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -455,6 +455,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}; diff --git a/t/Prices.t b/t/Prices.t index 6a74135211..b7e2aa0d20 100644 --- a/t/Prices.t +++ b/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 { -- 2.20.1