redmine_crm 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb4edcbb29e05cd8cfc1107b19cf57c3d20f9d2f
4
- data.tar.gz: b38fdf655eabf2265a2148a48e19934bb5889394
3
+ metadata.gz: 7b37a6a71a78445ab8bd0a7943289f7d2de66266
4
+ data.tar.gz: 7314f12328b7d335d16ab0b188ea97805c17b420
5
5
  SHA512:
6
- metadata.gz: 6ab2ddf4fb0123cbbe857378ae6fd31a0daa6de544c4efda9f2162dfea355ca0931c5b0d34c25d8bb2c929b4dc653d6a1f813f05a80781c68fe566db877a9f3b
7
- data.tar.gz: 8a8c3757b763d17b5035685420650934a3d56608932ccb4d70c3250e8c3d83336e6d30a9d21ad850d2c9cd058be18b576278165f03f2a78550046eba3c2166c2
6
+ metadata.gz: 5acbbd27b7da55822a2ccd98894623b8c940ae2ce97937b1d5739e37c17a21ac0767a04b055a83ed5b63578e2a24d519bab5e34a35c7d66d6fb82a8e94db22ae
7
+ data.tar.gz: 5c60eb6ba7e3f5994780dba765274d004e4e37d87322e95fef54d5b1ce2cc00ff1b82c638cc7f2f616ac9f75bb4586f53b36f76e5172a6150e5d01fe17ae42de
@@ -32,8 +32,14 @@ module RedmineCrm
32
32
  rules = normalize_formatting_rules(rules)
33
33
  # byebug
34
34
  rules = Currency.default_formatting_rules.merge(rules)
35
- rules = self.localize_formatting_rules(rules, currency)
36
- rules = self.translate_formatting_rules(rules, currency.code) if rules[:translate]
35
+ if currency
36
+ rules = self.localize_formatting_rules(rules, currency)
37
+ rules = self.translate_formatting_rules(rules, currency.code) if rules[:translate]
38
+ rules[:decimal_mark] = currency.decimal_mark
39
+ rules[:decimal_places] = currency.decimal_places
40
+ rules[:subunit_to_unit] = currency.subunit_to_unit
41
+ rules[:thousands_separator] = currency.thousands_separator
42
+ end
37
43
 
38
44
  # if fractional == 0
39
45
  if rules[:display_free].respond_to?(:to_str)
@@ -43,11 +49,15 @@ module RedmineCrm
43
49
  end
44
50
  # end
45
51
 
46
- symbol_value = currency.symbol
52
+ symbol_value = currency.try(:symbol) || ""
53
+ # decimal_mark = rules["decimal_mark"]
54
+ # decimal_places
55
+
47
56
 
48
57
  formatted = value.abs.to_s
49
58
 
50
59
  # if rules[:rounded_infinite_precision]
60
+ if currency
51
61
  formatted.gsub!(/#{currency.decimal_mark}/, '.') unless '.' == currency.decimal_mark
52
62
  formatted = ((BigDecimal(formatted) * currency.subunit_to_unit).round / BigDecimal(currency.subunit_to_unit.to_s)).to_s("F")
53
63
  formatted.gsub!(/\..*/) do |decimal_part|
@@ -55,7 +65,7 @@ module RedmineCrm
55
65
  decimal_part
56
66
  end
57
67
  formatted.gsub!(/\./, currency.decimal_mark) unless '.' == currency.decimal_mark
58
- # end
68
+ end
59
69
 
60
70
  sign = value < 0 ? '-' : ''
61
71
 
@@ -63,17 +73,18 @@ module RedmineCrm
63
73
  formatted = "#{formatted.to_i}"
64
74
  end
65
75
 
66
- thousands_separator_value = currency.thousands_separator
76
+ # thousands_separator_value = currency.thousands_separator
67
77
  # Determine thousands_separator
68
78
  if rules.has_key?(:thousands_separator)
69
79
  thousands_separator_value = rules[:thousands_separator] || ''
70
80
  end
81
+ decimal_mark = rules[:decimal_mark]
71
82
 
72
83
  # Apply thousands_separator
73
- formatted.gsub!(regexp_format(formatted, rules, currency.decimal_mark, symbol_value),
84
+ formatted.gsub!(regexp_format(formatted, rules, decimal_mark, symbol_value),
74
85
  "\\1#{thousands_separator_value}")
75
86
 
76
- symbol_position = symbol_position_from(rules, currency)
87
+ symbol_position = symbol_position_from(rules, currency) if currency
77
88
 
78
89
  if rules[:sign_positive] == true && (value >= 0)
79
90
  sign = '+'
@@ -98,7 +109,7 @@ module RedmineCrm
98
109
  formatted="#{sign_before}#{sign}#{formatted}"
99
110
  end
100
111
 
101
- apply_decimal_mark_from_rules(formatted, rules)
112
+ # apply_decimal_mark_from_rules(formatted, rules)
102
113
 
103
114
  if rules[:with_currency]
104
115
  formatted << " "
@@ -110,8 +121,11 @@ module RedmineCrm
110
121
  end
111
122
 
112
123
  def default_formatting_rules
113
- # byebug
114
- {}
124
+ {
125
+ :decimal_mark =>".",
126
+ :thousands_separator => ",",
127
+ :subunit_to_unit => 100
128
+ }
115
129
  end
116
130
 
117
131
  def regexp_format(formatted, rules, decimal_mark, symbol_value)
@@ -206,10 +220,10 @@ module RedmineCrm
206
220
  # @param [String] formatted
207
221
  # @param [Hash] rules
208
222
  def apply_decimal_mark_from_rules(formatted, rules)
209
- if rules.has_key?(:decimal_mark) && rules[:decimal_mark] &&
210
- rules[:decimal_mark] != decimal_mark
223
+ if rules.has_key?(:decimal_mark) && rules[:decimal_mark]
224
+ # && rules[:decimal_mark] != decimal_mark
211
225
 
212
- regexp_decimal = Regexp.escape(decimal_mark)
226
+ regexp_decimal = Regexp.escape(rules[:decimal_mark])
213
227
  formatted.sub!(/(.*)(#{regexp_decimal})(.*)\Z/,
214
228
  "\\1#{rules[:decimal_mark]}\\3")
215
229
  end
@@ -57,7 +57,7 @@ module RedmineCrm
57
57
  currency = "USD" unless currency.is_a?(String)
58
58
  currency = RedmineCrm::Currency.find(currency)
59
59
 
60
- return RedmineCrm::Currency.format(price.to_f, currency) if currency
60
+ return RedmineCrm::Currency.format(price.to_f, currency)# if currency
61
61
  price.to_s
62
62
  end
63
63
 
@@ -52,7 +52,7 @@ module RedmineCrm
52
52
 
53
53
  def drop_votable_table options = {}
54
54
  votes_name_table = options[:votes] || :votes
55
- if !self.connection.table_exists?(votes_name_table)
55
+ if self.connection.table_exists?(votes_name_table)
56
56
  self.connection.drop_table votes_name_table
57
57
  end
58
58
  end
@@ -1,3 +1,3 @@
1
1
  module RedmineCrm
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -6,7 +6,7 @@ class MoneyHelperTest < ActiveSupport::TestCase
6
6
  def test_price_to_currency
7
7
  assert_equal '$3,265.65', price_to_currency(3265.65, "USD")
8
8
  assert_equal "3.265,65 ₽", price_to_currency(3265.65, "RUB")
9
- assert_equal "3200", price_to_currency(3200, "")
10
- assert_equal "3200", price_to_currency(3200, "Foo")
9
+ assert_equal "3,200.0", price_to_currency(3200, "")
10
+ assert_equal "3,200.0", price_to_currency(3200, "Foo")
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - RedmineCRM
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-24 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: plugins for Redmine
14
14
  email: