Bugzilla – Attachment 35724 Details for
Bug 13352
Editing amount in Acquisitions budget causes error due to formatting
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 13352: On editing, prices should not be formatted
PASSED-QA-Bug-13352-On-editing-prices-should-not-b.patch (text/plain), 9.07 KB, created by
Katrin Fischer
on 2015-02-08 15:26:21 UTC
(
hide
)
Description:
[PASSED QA] Bug 13352: On editing, prices should not be formatted
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2015-02-08 15:26:21 UTC
Size:
9.07 KB
patch
obsolete
>From ab84fa1fc0fa241b74aa350085675aa0ed075a91 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Mon, 26 Jan 2015 10:28:27 +0100 >Subject: [PATCH] [PASSED QA] Bug 13352: On editing, prices should not be > formatted > >Bug 12979 refactored the way to display prices. >The price format configuration was duplicated everywhere it was used. > >All calls looks good except the one in admin/aqbudgetperiods.pl >In this one, the prices are formatted for an edition field (input). >This means the input is incorrectly filled even if the user does not >update the field. > >At the end, maybe should we manage formatted prices everywhere, even in >inputs, but it's not in the scope of this bug. > >Technically, a new subroutine format_for_editing is added to the >Koha::Number::Price module. >It should be called everywhere a price is displayed in an input field. >At the moment, it only does a sprintf("%.2f"), but it is a first step to >let the number of decimals to display configurable. > >To test: >1/ Verify the issue described is fixed (editing a budget with a total >amount > 1000 (With CurrencyFormat is US or FR). >2/ Verify you can edit a fund with a total amount > 1000 > >Signed-off-by: Paola Rossi <paola.rossi@cineca.it> >Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> >--- > Koha/Number/Price.pm | 15 +++++++++++++++ > Koha/Template/Plugin/Price.pm | 9 +++++++-- > admin/aqbudgetperiods.pl | 6 ------ > admin/aqbudgets.pl | 1 - > .../prog/en/modules/admin/aqbudgetperiods.tt | 7 +++---- > .../intranet-tmpl/prog/en/modules/admin/aqbudgets.tt | 6 +++--- > t/Prices.t | 9 ++++++++- > 7 files changed, 36 insertions(+), 17 deletions(-) > >diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm >index 6380bbc..f29fe06 100644 >--- a/Koha/Number/Price.pm >+++ b/Koha/Number/Price.pm >@@ -44,6 +44,21 @@ sub format { > return Number::Format->new(%$format_params)->format_price($self->value); > } > >+sub format_for_editing { >+ my ( $self, $params ) = @_; >+ return unless defined $self->value; >+ >+ my $format_params = $self->_format_params( $params ); >+ $format_params = { >+ %$format_params, >+ int_curr_symbol => '', >+ mon_thousands_sep => '', >+ mon_decimal_point => '.', >+ }; >+ >+ return Number::Format->new(%$format_params)->format_price($self->value); >+} >+ > sub unformat { > my ( $self, $params ) = @_; > return unless defined $self->value; >diff --git a/Koha/Template/Plugin/Price.pm b/Koha/Template/Plugin/Price.pm >index f5d2a42..807f301 100644 >--- a/Koha/Template/Plugin/Price.pm >+++ b/Koha/Template/Plugin/Price.pm >@@ -23,11 +23,16 @@ use Template::Plugin::Filter; > use base qw( Template::Plugin::Filter ); > > use Koha::Number::Price; >+our $DYNAMIC = 1; > > sub filter { >- my ( $self, $value ) = @_; >+ my ( $self, $value, $args, $config ) = @_; > $value ||= 0; >- return Koha::Number::Price->new( $value )->format; >+ $config->{on_editing} //= 0; >+ my $formatted_price; >+ return $config->{on_editing} >+ ? Koha::Number::Price->new( $value )->format_for_editing >+ : Koha::Number::Price->new( $value )->format; > } > > 1; >diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl >index 0de825a..94f77e7 100755 >--- a/admin/aqbudgetperiods.pl >+++ b/admin/aqbudgetperiods.pl >@@ -46,7 +46,6 @@ script to administer the budget periods table > > use Modern::Perl; > >-use Number::Format qw(format_price); > use CGI qw ( -utf8 ); > use List::Util qw/min/; > use Koha::DateUtils; >@@ -59,8 +58,6 @@ use C4::Acquisition; > use C4::Budgets; > use C4::Debug; > >-use Koha::Number::Price; >- > my $dbh = C4::Context->dbh; > > my $input = new CGI; >@@ -108,9 +105,6 @@ if ( $op eq 'add_form' ) { > my $budgetperiod_hash=GetBudgetPeriod($budget_period_id); > # get dropboxes > >- $budgetperiod_hash->{budget_period_total} = >- Koha::Number::Price->new( $budgetperiod_hash->{budget_period_total} ) >- ->format; > $template->param( > %$budgetperiod_hash > ); >diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl >index b32f925..f1c2f39 100755 >--- a/admin/aqbudgets.pl >+++ b/admin/aqbudgets.pl >@@ -130,7 +130,6 @@ if ($op eq 'add_form') { > $dropbox_disabled = BudgetHasChildren($budget_id); > my $borrower = &GetMember( borrowernumber=>$budget->{budget_owner_id} ); > $budget->{budget_owner_name} = ( $borrower ? $borrower->{'firstname'} . ' ' . $borrower->{'surname'} : '' ); >- $$budget{$_}= sprintf("%.2f", $budget->{$_}) for grep{ /amount|encumb|expend/ } keys %$budget; > } > > # build budget hierarchy >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt >index a0a811a..6e78916 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt >@@ -1,5 +1,4 @@ > [% USE KohaDates %] >-[% USE format %] > [% USE Price %] > > [%- BLOCK action_menu %] >@@ -360,7 +359,7 @@ > <!-- ############################## --> > <label for="budget_period_total">Total amount: </label> > <input type="text" id="budget_period_total" name="budget_period_total" >- size="10" maxlength="80" value="[% budget_period_total %]" /> >+ size="10" maxlength="80" value="[% budget_period_total | $Price on_editing => 1 %]" /> > </li> > > <li> >@@ -498,7 +497,7 @@ > [% IF r.orders_moved.size > 0 %] > [% FOR order IN r.orders_moved %] > <tr> >- <td>[% r.budget.budget_name %] (id=[% r.budget.budget_id %]) Amount=[% r.budget.budget_amount | format ("%.2f") %][% IF r.unspent_moved %] ([% r.unspent_moved | format ("%.2f")%] remaining has been moved)[% END %]</td> >+ <td>[% r.budget.budget_name %] (id=[% r.budget.budget_id %]) Amount=[% r.budget.budget_amount | $Price %][% IF r.unspent_moved %] ([% r.unspent_moved | $Price %] remaining has been moved)[% END %]</td> > <td>[% order.basketname %]</td> > <td>[% order.ordernumber %]</td> > <td>Moved!</td> >@@ -515,7 +514,7 @@ > [% ELSE %] > [% IF r.error == 'budget_code_not_exists' %] > <tr> >- <td>[% r.budget.budget_id %] [% r.budget.budget_amount | format ("%.2f") %][% IF r.unspent_moved %] ([% r.unspent_moved | format ("%.2f") %] remaining has been moved)[% END %]</td> >+ <td>[% r.budget.budget_id %] [% r.budget.budget_amount | $Price %][% IF r.unspent_moved %] ([% r.unspent_moved | $Price %] remaining has been moved)[% END %]</td> > <td></td> > <td></td> > <td>This fund code does not exist in the destination budget.</td> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt >index 9056027..e56509f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt >@@ -458,18 +458,18 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") > > <li> > <label style="white-space: nowrap;" for="budget_amount" class="required">Amount: </label> >- <input type="text" name="budget_amount" id="budget_amount" value="[% budget_amount %]" size="8" /> >+ <input type="text" name="budget_amount" id="budget_amount" value="[% budget_amount | $Price on_editing => 1 %]" size="8" /> > </li> > > <li> > <label for="budget_encumb">Warning at (%): </label> >- <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb %]" size="10" /> >+ <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb | $Price on_editing => 1 %]" size="10" /> > <span class="hint">0 to disable</span> > </li> > > <li> > <label for="budget_expend">Warning at (amount): </label> >- <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend %]" size="10" /> >+ <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend | $Price on_editing => 1 %]" size="10" /> > <span class="hint">0 to disable</span> > </li> > >diff --git a/t/Prices.t b/t/Prices.t >index 92bb432..aa864d2 100644 >--- a/t/Prices.t >+++ b/t/Prices.t >@@ -1,5 +1,5 @@ > use Modern::Perl; >-use Test::More tests => 12; >+use Test::More tests => 16; > use Test::MockModule; > > use t::lib::Mocks; >@@ -403,3 +403,10 @@ sub compare { > "configuration $params->{conf}: $params->{field} should be correctly calculated" > ); > } >+ >+# format_for_editing >+for my $currency_format ( qw( US FR ) ) { >+ t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format ); >+ is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' ); >+ is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' ); >+} >-- >1.9.1
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 13352
:
35517
|
35703
| 35724 |
35725
|
35894
|
35895