From 944525b161cf3055d273ff84189fd38af53b89b6 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Tue, 16 Jan 2024 16:02:11 +0100 Subject: [PATCH] Bug 35114: Fix calculation around basketgroup and basket details Currently calculation on basketgroup is performed on ecost (tax_included and tax_excluded) while in basket detail it's on ecost only if unitprice is not defined. So I keep the same logic in basketgroup and I took the opportunity to remove a call to get_rounded_price on quantity (not logic). Test plan: 1) To test it you must have some items with differents values on ecost_tax_* and unitprice_tax_*. Both have 6 decimal places, but problems arise when the value (calculated for ecost_tax_*) has a 3rd decimal greater than or equal to 5. So I you have already this case in your datas create a basket with this item otherwise you can modify your database to reproduce the bad behavior. e.g set a ecost_tax_included to '18.655000' and '18.650000' for unitprice. 2) After the basket has been created, and in a basketgroup, go to basketgroup and check the amount. Click to see the details of the linked basket, the total will be different because the rounded total displayed previously (basketgroup) is based on the ecost_tax_* and so 18.655000 will become 18.66. In the detail based on the unitprice, which is 18.650000, the difference will be one cent on the total. Not much, but it's only a record... it's not precise (in accounting terms). 3) Apply this patch and repeat step 2) --- acqui/basket.pl | 6 +++--- acqui/basketgroup.pl | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/acqui/basket.pl b/acqui/basket.pl index 33253aad47..3d9b34fb38 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -343,7 +343,7 @@ if ( $op eq 'list' ) { $foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate}; $foot{$$line{tax_rate}}{tax_value} += get_rounded_price($$line{tax_value}); $total_tax_value += $$line{tax_value}; - $foot{$$line{tax_rate}}{quantity} += get_rounded_price($$line{quantity}); + $foot{$$line{tax_rate}}{quantity} += $$line{quantity}; $total_quantity += $$line{quantity}; $foot{$$line{tax_rate}}{total_tax_excluded} += $$line{total_tax_excluded}; $total_tax_excluded += $$line{total_tax_excluded}; @@ -458,8 +458,8 @@ sub get_order_infos { $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}; - $line{total_tax_excluded} = get_rounded_price($cost_tax_excluded) * $line{quantity}; + $line{total_tax_included} = get_rounded_price($cost_tax_included * $line{quantity}); + $line{total_tax_excluded} = get_rounded_price($cost_tax_excluded * $line{quantity}); $line{tax_value} = $line{tax_value_on_ordering}; $line{tax_rate} = $line{tax_rate_on_ordering}; diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 38f7b6b44c..be1039f9a5 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -75,14 +75,16 @@ sub BasketTotal { my $total = 0; my @orders = GetOrders($basketno); for my $order (@orders){ - # FIXME The following is wrong + # FIXME The following is wrong <- still true ? remove if patch 35114 fixed it + my $based_price_tax_included = $order->{unitprice_tax_included} || $order->{ecost_tax_included}; + my $based_price_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded}; if ( $bookseller->listincgst ) { - $total = $total + ( get_rounded_price($order->{ecost_tax_included}) * $order->{quantity} ); + $total = $total + ( $based_price_tax_included * $order->{quantity} ); } else { - $total = $total + ( get_rounded_price($order->{ecost_tax_excluded}) * $order->{quantity} ); + $total = $total + ( $based_price_tax_excluded * $order->{quantity} ); } } - return $total; + return get_rounded_price($total); } #displays all basketgroups and all closed baskets (in their respective groups) -- 2.30.2