Bugzilla – Attachment 78986 Details for
Bug 18736
Problems in order calculations (rounding errors)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18736: (follow-up) Fix missing rounding and bad formatting
Bug-18736-follow-up-Fix-missing-rounding-and-bad-f.patch (text/plain), 3.69 KB, created by
Nick Clemens (kidclamp)
on 2018-09-16 18:49:50 UTC
(
hide
)
Description:
Bug 18736: (follow-up) Fix missing rounding and bad formatting
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2018-09-16 18:49:50 UTC
Size:
3.69 KB
patch
obsolete
>From 308346e7550083525f60e0a69fc40ade4bb90b2b Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 24 Aug 2018 01:22:35 +0000 >Subject: [PATCH] Bug 18736: (follow-up) Fix missing rounding and bad > formatting > >This patch: >Adds a missing use >Uses 'Koha::Number::Price->round()' instead of 'format()' to ensure numeric >returns >Ensures too big numbers don't crash round() >Uses syspref in 'GetBudgetHierarchy' > >To test: >Follow previous test plan >Check values on admin/aqbudgets.pl are affected by syspref >Ensure values throughout acquisitions are correctly calculated/displayed >(even when greater than 1,000) >--- > C4/Acquisition.pm | 2 +- > C4/Budgets.pm | 4 ++-- > Koha/Number/Price.pm | 7 ++++++- > acqui/spent.pl | 1 + > 4 files changed, 10 insertions(+), 4 deletions(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 3101ed3..d9ec0f0 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -2036,7 +2036,7 @@ returns a price rounded as specified in OrderPriceRounding system preference. > sub get_rounded_price { > my ( $price ) = @_; > my $rounding_pref = C4::Context->preference('OrderPriceRounding'); >- if( $rounding_pref eq 'nearest_cent' ) { return Koha::Number::Price->new( $price )->format(); } >+ if( $rounding_pref eq 'nearest_cent' ) { return Koha::Number::Price->new( $price )->round(); } > else { return $price; } > } > >diff --git a/C4/Budgets.pm b/C4/Budgets.pm >index 243dfec..40d11a1 100644 >--- a/C4/Budgets.pm >+++ b/C4/Budgets.pm >@@ -560,14 +560,14 @@ sub GetBudgetHierarchy { > # Get all the budgets totals in as few queries as possible > my $hr_budget_spent = $dbh->selectall_hashref(q| > SELECT aqorders.budget_id, aqbudgets.budget_parent_id, >- SUM( COALESCE(unitprice_tax_included, ecost_tax_included) * quantity ) AS budget_spent >+ SUM( | . _get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent > FROM aqorders JOIN aqbudgets USING (budget_id) > WHERE quantityreceived > 0 AND datecancellationprinted IS NULL > GROUP BY budget_id > |, 'budget_id'); > my $hr_budget_ordered = $dbh->selectall_hashref(q| > SELECT aqorders.budget_id, aqbudgets.budget_parent_id, >- SUM(ecost_tax_included * quantity) AS budget_ordered >+ SUM( | . _get_rounding_sql(qq|ecost_tax_included|) . q| * quantity) AS budget_ordered > FROM aqorders JOIN aqbudgets USING (budget_id) > WHERE quantityreceived = 0 AND datecancellationprinted IS NULL > GROUP BY budget_id >diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm >index 64c9dfe..e905ebc 100644 >--- a/Koha/Number/Price.pm >+++ b/Koha/Number/Price.pm >@@ -19,7 +19,7 @@ package Koha::Number::Price; > > use Modern::Perl; > >-use Number::Format qw( format_price ); >+use Number::Format qw( format_price round ); > use C4::Context; > use Koha::Acquisition::Currencies; > >@@ -84,6 +84,11 @@ 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); > } > >diff --git a/acqui/spent.pl b/acqui/spent.pl >index 0ff2ee2..4afbd9a 100755 >--- a/acqui/spent.pl >+++ b/acqui/spent.pl >@@ -34,6 +34,7 @@ use C4::Auth; > use C4::Output; > use Modern::Perl; > use CGI qw ( -utf8 ); >+use C4::Acquisition; > use Koha::Acquisition::Invoice::Adjustments; > > my $dbh = C4::Context->dbh; >-- >2.1.4
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 18736
:
64061
|
64065
|
70187
|
70188
|
70189
|
70768
|
71062
|
71063
|
71627
|
71628
|
71629
|
71630
|
71631
|
71632
|
74335
|
74336
|
74337
|
74338
|
74339
|
74340
|
74341
|
74342
|
74370
|
74371
|
74374
|
74397
|
74398
|
74422
|
74427
|
74438
|
76979
|
76980
|
76981
|
76982
|
76983
|
76984
|
76985
|
76986
|
76987
|
76988
|
76989
|
76990
|
76991
|
77614
|
77615
|
77616
|
77617
|
77618
|
78101
|
78120
|
78981
|
78982
|
78983
|
78984
|
78985
|
78986
|
78987
|
78988
|
79087
|
79088
|
79089
|
79090
|
79091
|
79092
|
79093
|
79094
|
79098
|
79099
|
79100
|
79101
|
79102
|
79103
|
79104
|
79105
|
79187
|
79223
|
79562
|
79563
|
82967
|
82968
|
82969
|
82970
|
82971
|
82972
|
82973
|
82974
|
82975
|
82976
|
82977
|
83212
|
83213
|
83214
|
83973
|
83974
|
83975
|
83976
|
83977
|
83978
|
83979
|
83980
|
83981
|
83982
|
83983
|
83984
|
83985
|
86646
|
86647
|
86648
|
86649
|
86650
|
86651
|
86652
|
86653
|
86654
|
86655
|
86656
|
86657
|
86658