PiRSquared17 / activescaffold

Automatically exported from code.google.com/p/activescaffold
MIT License
0 stars 0 forks source link

Insert localized currency or number_with_delimiter #748

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
At first I've localized currency like this:
ru:
  number:
    currency:
      format:
        format: "%n"
        unit: "руб."
        separator: ","
        delimiter: ""
        precision: 3

I have some columns with:
config.columns[:somecolumn].options[:format] = :currency
represented in forms as just input type="text". when I try to put the 
number with localized separator, for example: 1,3. It saves it but then 
represent like 13,000. If the form object has errors, fields are refreshed 
with such a values: 1,3 -> 13,000 -> 13000,000 and so on. I think this 
happens because it tries to convert 1,3 to float without pre gsub of 
localized separator to native.  
Actual for the last AS commit: f3b2fd57a89863e9f2da

Original issue reported on code.google.com by VoronkovAA@gmail.com on 26 May 2010 at 12:06

GoogleCodeExporter commented 9 years ago
Fixed in a275c7ffadd5d1a6c07a7791572d53f68d83da12

Original comment by sergio.c...@gmail.com on 26 May 2010 at 7:49

GoogleCodeExporter commented 9 years ago
No, it only works when input value with native separator. For example:
1.3 becomes 1,300
but 1,3 becomes 13,000

Original comment by VoronkovAA@gmail.com on 26 May 2010 at 9:12

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Have you updated and restarted the application? I can't reproduce it and also I 
have
some tests for your configuration with no fail

Original comment by sergio.c...@gmail.com on 26 May 2010 at 9:37

GoogleCodeExporter commented 9 years ago
You can run the tests from your active_scaffold directory:
cd vendor/plugins/active_scaffold
rake

Original comment by sergio.c...@gmail.com on 26 May 2010 at 9:40

GoogleCodeExporter commented 9 years ago
That's what I see in my console, when creating a new record:
Processing FinancingsController#create (for 127.0.0.1 at 2010-05-26 22:48:25) 
[POST]
  Parameters: {"commit"=>"Создать запись", 
"authenticity_token"=>"zbxflMyF0Awvo2IXRBvGuGlNwX73dHvsXQYzO4kN18o=", "_"=>"", 
"record"=>{"current_regional_budget"=>"1.1", "extrabudgetary"=>"0", 
"date(1i)"=>"2010", "date(2i)"=>"5", "date(3i)"=>"1", 
"old_regional_budget"=>"0", 
"local_budget"=>"0", "federal_budget"=>"1,1"}}
  User Columns (0.6ms)   SHOW FIELDS FROM `users`
  User Load (0.2ms)   SELECT * FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
  SQL (0.1ms)   BEGIN
  Financing Create (0.2ms)   INSERT INTO `financings` (`current_regional_budget`, 
`name`, `extrabudgetary`, `created_at`, `event_id`, `updated_at`, 
`district_id`, 
`old_regional_budget`, `date`, `type`, `federal_budget`, `local_budget`, 
`parent_id`) 
VALUES(1.1, NULL, 0.0, '2010-05-26 12:48:25', NULL, '2010-05-26 12:48:25', 
NULL, 0.0, 
'2010-05-01', NULL, 11.0, 0.0, NULL)

Original comment by VoronkovAA@gmail.com on 26 May 2010 at 1:27

GoogleCodeExporter commented 9 years ago
It.is strange because in console:
>> separator = ","
=> ","
>> a = "1,1"
=> "1,1"
>> a.gsub(/[^0-9\-#{separator}]/, '').gsub(separator, '.')
=> "1.1"
>> a.gsub(/[^0-9\-#{separator}]/, '').gsub(separator, '.').to_d
#<BigDecimal:b5d9fb4c,'0.11E1',8(8)>

Original comment by VoronkovAA@gmail.com on 26 May 2010 at 1:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
What is there in line 130 of lib/active_scaffold/attribute_params.rb?
It should be:
unless !value.include?(separator) && value.include?(native) && (delimiter != 
native
|| value !~ /\.\d{3}$/)

Original comment by sergio.c...@gmail.com on 26 May 2010 at 3:20

GoogleCodeExporter commented 9 years ago
Yes, I have this string 

Original comment by VoronkovAA@gmail.com on 26 May 2010 at 10:24

GoogleCodeExporter commented 9 years ago
My AS is at a3b61a3e88b8cce538b0f240681a1da2844118ec now.
And I tried to turn off all of the localization and add 
en:
  number:
    currency:
      format:
        format: "%n"
        unit: "руб."
        separator: ","
        delimiter: ""
        precision: 3
the same thing in non localized app.

Original comment by VoronkovAA@gmail.com on 26 May 2010 at 10:40

GoogleCodeExporter commented 9 years ago
At last! I've just understand where is an error.
It's in line 128 of attribute_params.rb:
separator = I18n.t('number.format.separator')
But if I want to change only currency appearance, it should be 
separator = I18n.t('number.currency.format.separator')
but you have both [:i18n_number, :currency].include? in condition and only one 
definition of separator and delimiter and it is for :i18n_number, so for 
:currency it 
taks wrong value (In my case separator = ".")
And I think in line 130 you should change #{I18n.t('number.format.separator')} 
to 
just #{separator}

Original comment by VoronkovAA@gmail.com on 26 May 2010 at 11:54

GoogleCodeExporter commented 9 years ago
I've just made a patch and submitted a pull request.

Original comment by VoronkovAA@gmail.com on 27 May 2010 at 1:41

GoogleCodeExporter commented 9 years ago
Thanks, I have merged and improved to support :percentage and :size too, because
they were supported in list and forms, but they weren't converted to native 
format.

Original comment by sergio.c...@gmail.com on 27 May 2010 at 8:42