Bugzilla – Attachment 161918 Details for
Bug 36049
Rounding prices sometimes leads to incorrect results
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36049: Fix price rounding and add a unit test
Bug-36049-Fix-price-rounding-and-add-a-unit-test.patch (text/plain), 2.32 KB, created by
Raphael Straub
on 2024-02-08 14:32:28 UTC
(
hide
)
Description:
Bug 36049: Fix price rounding and add a unit test
Filename:
MIME Type:
Creator:
Raphael Straub
Created:
2024-02-08 14:32:28 UTC
Size:
2.32 KB
patch
obsolete
>From 27eeaebf9e36cb125c9df0521729aa5e24f1f92f Mon Sep 17 00:00:00 2001 >From: Raphael Straub <raphael.straub@kit.edu> >Date: Thu, 8 Feb 2024 14:17:56 +0000 >Subject: [PATCH] Bug 36049: Fix price rounding and add a unit test > >This patch only fixes price rounding by using Math::BigFloat. > >To test: >1) Create an order line in acquisitions with vendor price 18.90 and a > discount of 5 %. >2) Verify that the total (tax excl.) in the order table on the basket > page is 17.95. >3) Apply the patch. >4) Reload the basket page. >5) Verify that the total (tax excl.) in the order table on the basket > page now is 17.96, which is correct. >6) Run: prove t/Number/Price.t > >Sponsored-by: Karlsruhe Institute of Technology (KIT) >--- > Koha/Number/Price.pm | 8 ++------ > t/Number/Price.t | 5 ++++- > 2 files changed, 6 insertions(+), 7 deletions(-) > >diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm >index e9a6aa748e..a0f847d495 100644 >--- a/Koha/Number/Price.pm >+++ b/Koha/Number/Price.pm >@@ -19,6 +19,7 @@ package Koha::Number::Price; > > use Modern::Perl; > >+use Math::BigFloat; > use Number::Format; > use C4::Context; > use Koha::Acquisition::Currencies; >@@ -83,12 +84,7 @@ sub round { > > my $format_params = $self->_format_params; > >- # To avoid the system to crash, we will not format big number >- # We divide per 100 because we want to keep the default DECIMAL_DIGITS (2) >- # error - round() overflow. Try smaller precision or use Math::BigFloat >- return $self->value if $self->value > Number::Format::MAX_INT/100; >- >- return Number::Format->new(%$format_params)->round($self->value); >+ return Number::Format->new(%$format_params)->round( Math::BigFloat->new( $self->value ) )->bdstr(); > } > > sub _format_params { >diff --git a/t/Number/Price.t b/t/Number/Price.t >index ce607a83a1..9017fe793e 100755 >--- a/t/Number/Price.t >+++ b/t/Number/Price.t >@@ -1,6 +1,6 @@ > use Modern::Perl; > >-use Test::More tests => 35; >+use Test::More tests => 36; > > use Test::MockModule; > use t::lib::Mocks; >@@ -136,6 +136,9 @@ is( Koha::Number::Price->new(3)->unformat, '3', 'CHF: unformat 3' ); > is( Koha::Number::Price->new(1234567890)->unformat, > '1234567890', 'CHF: unformat 1234567890' ); > >+# Rounding >+is( Koha::Number::Price->new(17.955)->round, '17.96', 'Round 17.955' ); >+ > subtest 'Changes for format' => sub { # See also bug 18736 > plan tests => 3; > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36049
:
161918
|
161951
|
162699
|
162700
|
162701
|
171598
|
171599