Bugzilla – Attachment 59756 Details for
Bug 17138
UpdateFine() modyfies existing fine records even when there is no need
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 17138: Add and use comparison function and tests
SIGNED-OFF-Bug-17138-Add-and-use-comparison-functi.patch (text/plain), 3.57 KB, created by
Josef Moravec
on 2017-02-01 21:15:24 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 17138: Add and use comparison function and tests
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2017-02-01 21:15:24 UTC
Size:
3.57 KB
patch
obsolete
>From 98c8297f40706463f466031437bf5a5b03d05bd1 Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Tue, 3 Jan 2017 00:22:20 +0000 >Subject: [PATCH] [SIGNED-OFF] Bug 17138: Add and use comparison function and > tests > >Added C4::Koha::compareNumbers($n1,$n2,$accuracy). >Added corresponding tests to t/Koha.t >Tweaked C4/Overdues to use the new function. > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > C4/Koha.pm | 34 ++++++++++++++++++++++++++++++++++ > C4/Overdues.pm | 2 +- > t/Koha.t | 14 +++++++++++++- > 3 files changed, 48 insertions(+), 2 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index b6e494a..9e280a6 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -1310,6 +1310,40 @@ sub IsKohaFieldLinked { > return $is_linked->[0]; > } > >+=head2 compareNumbers >+ >+ As floating point numbers may be rounded differently and >+ inconsistently, this function converts them to strings of >+ a given accuracy for the comparison. >+ >+ my $number1 = 5.60000; >+ my $number2 = 5.6; >+ if (C4::Koha::compareNumbers($number1,$number2,2) { >+ print "The two numbers match.\n"; >+ } else { >+ print "The two numbers do not match.\n"; >+ } >+ >+ Return 1 if the numbers match. >+ >+=cut >+ >+sub compareNumbers { >+ my ($n1,$n2,$accuracy) = @_; >+ if (defined $n1 && defined $n2) { >+ if (!defined $accuracy) { >+ $accuracy = 2; >+ } >+ my $format1 = "%.${accuracy}f"; >+ my $format2 = $format1; >+ return (sprintf($format1,$n1) eq sprintf($format2,$n2)); >+ } elsif (!defined $n1 && !defined $n2) { >+ return 1; >+ } else { >+ return 0; >+ } >+} >+ > 1; > > __END__ >diff --git a/C4/Overdues.pm b/C4/Overdues.pm >index feb4eef..6c347c0 100644 >--- a/C4/Overdues.pm >+++ b/C4/Overdues.pm >@@ -575,7 +575,7 @@ sub UpdateFine { > # we're updating an existing fine. Only modify if amount changed > # Note that in the current implementation, you cannot pay against an accruing fine > # (i.e. , of accounttype 'FU'). Doing so will break accrual. >- if ( $data->{'amount'} ne sprintf('%.6f', $amount) ) { >+ if ( C4::Koha::compareNumbers($data->{'amount'},$amount,6) ) { > my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} ); > my $diff = $amount - $data->{'amount'}; > >diff --git a/t/Koha.t b/t/Koha.t >index e617146..f00bf98 100755 >--- a/t/Koha.t >+++ b/t/Koha.t >@@ -25,7 +25,7 @@ use Module::Load::Conditional qw/check_install/; > > BEGIN { > if ( check_install( module => 'Test::DBIx::Class' ) ) { >- plan tests => 38; >+ plan tests => 47; > } else { > plan skip_all => "Need Test::DBIx::Class" > } >@@ -155,4 +155,16 @@ ok($@ eq '', 'NormalizeISSN does not throw exception when parsing invalid ISSN') > is($issns[0], 'abc', 'Original ISSN passed through even if invalid'); > is(scalar(@issns), 1, 'zero additional variations returned of invalid ISSN'); > >+ok( C4::Koha::compareNumbers(1,1,2),'1 matches 1 as expected'); >+ok( C4::Koha::compareNumbers(1.25,1.251,2),'1.25 matches 1.251 with 2 decimal accuracy'); >+ >+ok(!C4::Koha::compareNumbers(1,2,2),'1 does not match 2 as expected'); >+ok(!C4::Koha::compareNumbers(undef,1 ,2),'undef does not match 1 as expected'); >+ok(!C4::Koha::compareNumbers(1,undef,2),'1 does not match undef as expected'); >+ >+ok(C4::Koha::compareNumbers( 5.600000 , 5.6 ),'number-number test'); >+ok(C4::Koha::compareNumbers( 5.600000 ,'5.6'),'number-string test'); >+ok(C4::Koha::compareNumbers('5.600000', 5.6 ),'string-number test'); >+ok(C4::Koha::compareNumbers('5.600000','5.6'),'string-string test'); >+ > 1; >-- >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 17138
:
54532
|
58559
|
59755
| 59756