Bugzilla – Attachment 152509 Details for
Bug 33028
Wrongly formatted monetary amounts in circulation rules break scripts and calculations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33028: Fix calculations around cronjob fines.pl
Bug-33028-Fix-calculations-around-cronjob-finespl.patch (text/plain), 4.02 KB, created by
Katrin Fischer
on 2023-06-21 10:48:45 UTC
(
hide
)
Description:
Bug 33028: Fix calculations around cronjob fines.pl
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2023-06-21 10:48:45 UTC
Size:
4.02 KB
patch
obsolete
>From 2e7710076694f4fcb3c436811d7275230a052c8e Mon Sep 17 00:00:00 2001 >From: Thibaud Guillot <thibaud.guillot@biblibre.com> >Date: Tue, 21 Feb 2023 17:05:45 +0100 >Subject: [PATCH] Bug 33028: Fix calculations around cronjob fines.pl > >When currency format is set on FR commas are decimals separators >but when cron like fines.pl try to calculate fines it's fails due to >this format. > >I changed this behavior by targetted 'fine' and 'overduefinescap' in >circulation_rules.rule_name to unformat them when we save them. > >This also fix the display in smart_rules table (before with commas price >was not good displayed - without decimals) > >Test Plan : >1) Set your currency format on 'FR' and 'fine' OR/AND 'overduefinescap' >with commas >2) Be sure to have some patron overdues >3) Run ~/misc/cronjobs/fines.pl with args to find overdues >4) See an error like 'isn't numeric in substraction[..] or gt > [...]' >5) Run updatedatabase script (it will replace commas in your rules >changed in step 1) ) >6) Repeat step 3 and see that everything was going "fine" (:tada:) > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/CirculationRules.pm | 7 +++ > ...ix_calc_fines_fr-currency_21-11-MT39815.pl | 51 +++++++++++++++++++ > 2 files changed, 58 insertions(+) > create mode 100755 installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl > >diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm >index f96df496fb..d002937237 100644 >--- a/Koha/CirculationRules.pm >+++ b/Koha/CirculationRules.pm >@@ -24,6 +24,7 @@ use Koha::Exceptions; > use Koha::CirculationRule; > use Koha::Caches; > use Koha::Cache::Memory::Lite; >+use Koha::Number::Price; > > use base qw(Koha::Objects); > >@@ -388,6 +389,12 @@ sub set_rule { > } > )->next(); > >+ if ( $rule >+ && ( $rule->rule_name eq 'overduefinescap' || $rule->rule_name eq 'fine' ) ) >+ { >+ $rule_value = Koha::Number::Price->new($rule_value)->unformat; >+ } >+ > if ($rule) { > if ( defined $rule_value ) { > $rule->rule_value($rule_value); >diff --git a/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl b/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl >new file mode 100755 >index 0000000000..8502dc00a6 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl >@@ -0,0 +1,51 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "BUG_33028", >+ description => >+"Fix calculations around fines and values with comma as decimal separator", >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ >+ my $rules = $dbh->selectall_arrayref( >+q|select * from circulation_rules where rule_name IN ('fine', 'overduefinescap')|, >+ { Slice => {} } >+ ); >+ >+ my $query = $dbh->prepare( >+ "UPDATE circulation_rules SET rule_value = ? where id = ?"); >+ >+ foreach my $rule ( @{$rules} ) { >+ my $rule_id = $rule->{'id'}; >+ my $rule_value = $rule->{'rule_value'}; >+ if ( $rule_value =~ /[a-zA-Z]/ ) { >+ die( >+ sprintf( >+ 'No only numbers in rule id %s ("%s") - fix it before restart this update', >+ $rule_id, $rule_value >+ ) >+ ); >+ } >+ else { >+ if ( $rule_value =~ /,/ ) { >+ if ( $rule_value !~ /,.*?,/ ) { >+ $rule_value =~ s/,/./; >+ $query->execute( $rule_value, $rule_id ); >+ } >+ else { >+ die( >+ sprintf( >+ 'Many commas in rule id %s ("%s") - fix it before restart this update', >+ $rule_id, $rule_value >+ ) >+ ); >+ } >+ } >+ } >+ >+ } >+ say $out >+ "BUG_33028 - Patch applied"; >+ }, >+ } >-- >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 33028
:
147058
|
147686
|
147687
|
147688
|
152441
|
152442
|
152443
|
152444
|
152445
|
152446
|
152509
|
152510
|
152511
|
152512
|
152513
|
152514
|
152515
|
152752
|
152753
|
152754
|
152755
|
152756
|
152757
|
152758
|
152759
|
152760
|
152761
|
152762
|
152763
|
152764
|
152803
|
152804
|
152805
|
152829
|
152928
|
152929
|
152930
|
152931
|
152932
|
152933
|
152934
|
152935
|
152936
|
153313
|
153314
|
153315
|
153316
|
153317
|
153318
|
153319
|
153320
|
153321
|
153322
|
153323
|
153619
|
153620
|
153632
|
153633
|
153634
|
153635
|
153636
|
153677