redmine_crm 0.0.47 → 0.0.48

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: 69a1fa898e3b5a087d2dd75ad7ef6fe39e28cdde
4
- data.tar.gz: 26dbba848e8586993dfc82a0f6f84f446c81699a
3
+ metadata.gz: a1c034965196dbd50cc840b5655eadcbf75dab04
4
+ data.tar.gz: fa59b69096a8810670a3aa90b5c6e76d3aa24b2d
5
5
  SHA512:
6
- metadata.gz: 29c1d4c2f6b61cd04a6842bae649b85ef9785ab52cd197bfdca70033c21e0b77a413392fefe05436edffea8386be6ba19c50c16bb43d451cc4e7407e6abff70c
7
- data.tar.gz: 9bcfba949514d1a2bcc9abc5f6aa6f6be012c74d3abab92a287297869cc14655f65effe73d252f2b38954616f22dc844622b50670f3c9a829ab129dd0559b6cc
6
+ metadata.gz: 00fafa577fe756a6d0a4dfc6795816fe745bcf56a2ec0bb20fe15a6e76688d54439772b73ed425ebf4e8fadee90f5b9f92a76a6a3e5f42ef3be20a8ebd90ab73
7
+ data.tar.gz: 1b087c66d055885d2d1720608526768c37a6cf9bfa62ac5b98c127c139f7ca6290859bc2a8abba0e06fc88a21d3e47da2b7cef8232724d3ccc214b383bfe695b
@@ -0,0 +1,21 @@
1
+ class RedmineCrmController < ApplicationController
2
+ layout 'admin'
3
+
4
+ before_action :require_admin
5
+ require_sudo_mode :settings
6
+
7
+ def settings
8
+ @section = RedmineCrm::Settings::SECTIONS[params[:id]]
9
+ return render_404 unless @section
10
+
11
+ if request.post?
12
+ setting = params[:settings] ? params[:settings].permit!.to_h : {}
13
+ RedmineCrm::Settings.apply = setting
14
+ flash[:notice] = l(:notice_successful_update)
15
+ redirect_to redmine_crm_settings_path(@section[:id])
16
+ else
17
+ @settings = RedmineCrm::Settings.values
18
+ end
19
+ @section_tabs = RedmineCrm::Settings::SECTIONS.map { |_n, s| { name: s[:id], partial: s[:partial], label: s[:label] } }
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ <p>
2
+ <label for="cb_settings_disable_taxes"><%= l(:label_redmine_crm_disable_taxes) %></label>
3
+ <%= hidden_field_tag 'settings[disable_taxes]', '0' %>
4
+ <%= check_box_tag 'settings[disable_taxes]', 1, RedmineCrm::Settings::Money.disable_taxes?, id: 'cb_settings_disable_taxes' %>
5
+ </p>
6
+
7
+ <span id="tax_data">
8
+ <p>
9
+ <label><%= l(:label_redmine_crm_default_tax) %></label>
10
+ <%= text_field_tag 'settings[default_tax]', RedmineCrm::Settings::Money.default_tax, size: 6, maxlength: 5 %> %
11
+ </p>
12
+
13
+ <p>
14
+ <label><%= l(:label_redmine_crm_tax_type) %></label>
15
+ <%= select_tag 'settings[tax_type]', options_for_select([[l(:label_redmine_crm_tax_type_exclusive), RedmineCrm::Settings::Money::TAX_TYPE_EXCLUSIVE],
16
+ [l(:label_redmine_crm_tax_type_inclusive), RedmineCrm::Settings::Money::TAX_TYPE_INCLUSIVE]],
17
+ @settings['tax_type']) %>
18
+ </p>
19
+ </span>
20
+
21
+ <p>
22
+ <label><%= l(:label_redmine_crm_default_currency) %></label>
23
+ <%= select_tag 'settings[default_currency]', options_for_select(all_currencies.insert(0, ['', '']), RedmineCrm::Settings::Money.default_currency) %>
24
+ </p>
25
+
26
+ <p>
27
+ <label><%= l(:label_redmine_crm_major_currencies) %></label>
28
+ <%= text_field_tag 'settings[major_currencies]', RedmineCrm::Settings::Money.major_currencies.join(', '), size: 40 %>
29
+ <br>
30
+ <em class="info"><%= l(:text_comma_separated) %></em>
31
+ </p>
32
+
33
+ <p>
34
+ <label><%= l(:label_redmine_crm_thousands_delimiter) %></label>
35
+ <%= select_tag 'settings[thousands_delimiter]', options_for_select([["9 999", " "],
36
+ ["9,999", ","],
37
+ ["9.999", "."]], RedmineCrm::Settings::Money.thousands_delimiter) %>
38
+ </p>
39
+
40
+ <p>
41
+ <label><%= l(:label_redmine_crm_decimal_separator) %></label>
42
+ <%= select_tag 'settings[decimal_separator]', options_for_select([["0.00", "."],
43
+ ["0,00", ","]], RedmineCrm::Settings::Money.decimal_separator) %>
44
+ </p>
@@ -0,0 +1,10 @@
1
+ <%= title l(:label_redmine_crm_settings) %>
2
+
3
+ <div id="settings">
4
+ <%= form_tag({ action: 'settings', id: @section[:id] }) do %>
5
+ <div class="box tabular settings">
6
+ <%= render_tabs @section_tabs %>
7
+ </div>
8
+ <%= submit_tag l(:button_apply) %>
9
+ <% end %>
10
+ </div>
@@ -30,6 +30,8 @@ pipelines:
30
30
  - sed -i "s/'sqlite3'/'sqlite3', '~> 1.3.6'/g" redmine_crm.gemspec
31
31
  - sed -i "s/'mysql2'/'mysql2', '~> 0.4.0'/g" redmine_crm.gemspec
32
32
  - sed -i "s/'pg'/'pg', '~> 0.18.0'/g" redmine_crm.gemspec
33
+ - sed -i "s/^end/ spec.add_development_dependency 'minitest', '~> 5.11.3'\nend/g" redmine_crm.gemspec
34
+ - sed -i "s/^end/ spec.add_development_dependency 'sprockets', '~> 3.5.2'\nend/g" redmine_crm.gemspec
33
35
  - bundle install
34
36
  - bundle exec rake test DB=sqlite
35
37
  - bundle exec rake test DB=mysql
@@ -0,0 +1,13 @@
1
+ en:
2
+ label_redmine_crm_settings: Redmine Crm Settings
3
+ label_redmine_crm_money: Money
4
+
5
+ label_redmine_crm_disable_taxes: Disable taxes
6
+ label_redmine_crm_default_tax: Default tax value
7
+ label_redmine_crm_tax_type: Tax type
8
+ label_redmine_crm_tax_type_exclusive: Tax exclusive
9
+ label_redmine_crm_tax_type_inclusive: Tax inclusive
10
+ label_redmine_crm_default_currency: Default currency
11
+ label_redmine_crm_major_currencies: Major currencies
12
+ label_redmine_crm_thousands_delimiter: Thousands delimiter
13
+ label_redmine_crm_decimal_separator: Decimal separator
@@ -0,0 +1,13 @@
1
+ ru:
2
+ label_redmine_crm_settings: Настройки Redmine Crm
3
+ label_redmine_crm_money: Деньги
4
+
5
+ label_redmine_crm_disable_taxes: Отключить налоги
6
+ label_redmine_crm_default_tax: Ставка налога
7
+ label_redmine_crm_tax_type: Тип налога
8
+ label_redmine_crm_tax_type_exclusive: Налог добавлен к общей сумме
9
+ label_redmine_crm_tax_type_inclusive: Налог включен с общую сумму
10
+ label_redmine_crm_default_currency: Валюта по умолчанию
11
+ label_redmine_crm_major_currencies: Основные валюты
12
+ label_redmine_crm_thousands_delimiter: Разделитель разрядов
13
+ label_redmine_crm_decimal_separator: Десятичный разделитель
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ match 'redmine_crm/settings/:id', to: 'redmine_crm#settings', as: 'redmine_crm_settings', via: [:get, :post]
5
+ end
@@ -4,6 +4,11 @@ Redmine crm gem - general functions for plugins (tags, vote, viewing, currency)
4
4
  Copyright (C) 2011-2019 RedmineUP
5
5
  https://www.redmineup.com/
6
6
 
7
+ == 2019-11-07 v0.0.48
8
+
9
+ * Added global money setting
10
+ * Fixed select2 format
11
+
7
12
  == 2019-08-26 v0.0.47
8
13
 
9
14
  * Fixed bug with tag cloud
@@ -2,6 +2,10 @@ require 'active_record'
2
2
  require 'action_view'
3
3
 
4
4
  require 'redmine_crm/version'
5
+ require 'redmine_crm/engine'
6
+
7
+ require 'redmine_crm/settings'
8
+ require 'redmine_crm/settings/money'
5
9
 
6
10
  require 'redmine_crm/acts_as_list/list'
7
11
  require 'redmine_crm/acts_as_taggable/tag'
@@ -33,6 +33,17 @@ module RedmineCrm
33
33
 
34
34
  class << self
35
35
 
36
+ def add_admin_money_menu
37
+ return if Redmine::MenuManager.map(:admin_menu).exists?(:redmine_crm_money)
38
+
39
+ require 'redmine_crm/hooks/views_layouts_hook'
40
+ Redmine::MenuManager.map(:admin_menu).push(:redmine_crm_money,
41
+ { controller: 'redmine_crm', action: 'settings', id: 'money' },
42
+ caption: :label_redmine_crm_money,
43
+ html: { class: 'icon icon-redminecrm-money' })
44
+
45
+ end
46
+
36
47
  # Lookup a currency with given +id+ an returns a +Currency+ instance on
37
48
  # success, +nil+ otherwise.
38
49
  #
@@ -190,40 +201,40 @@ module RedmineCrm
190
201
  end
191
202
  end
192
203
 
193
- # @!attribute [r] id
204
+ # @!attribute [r] id
194
205
  # @return [Symbol] The symbol used to identify the currency, usually THE
195
206
  # lowercase +iso_code+ attribute.
196
- # @!attribute [r] priority
207
+ # @!attribute [r] priority
197
208
  # @return [Integer] A numerical value you can use to sort/group the
198
209
  # currency list.
199
- # @!attribute [r] iso_code
210
+ # @!attribute [r] iso_code
200
211
  # @return [String] The international 3-letter code as defined by the ISO
201
212
  # 4217 standard.
202
- # @!attribute [r] iso_numeric
213
+ # @!attribute [r] iso_numeric
203
214
  # @return [String] The international 3-numeric code as defined by the ISO
204
215
  # 4217 standard.
205
- # @!attribute [r] name
216
+ # @!attribute [r] name
206
217
  # @return [String] The currency name.
207
- # @!attribute [r] symbol
218
+ # @!attribute [r] symbol
208
219
  # @return [String] The currency symbol (UTF-8 encoded).
209
- # @!attribute [r] disambiguate_symbol
220
+ # @!attribute [r] disambiguate_symbol
210
221
  # @return [String] Alternative currency used if symbol is ambiguous
211
- # @!attribute [r] html_entity
222
+ # @!attribute [r] html_entity
212
223
  # @return [String] The html entity for the currency symbol
213
- # @!attribute [r] subunit
224
+ # @!attribute [r] subunit
214
225
  # @return [String] The name of the fractional monetary unit.
215
- # @!attribute [r] subunit_to_unit
226
+ # @!attribute [r] subunit_to_unit
216
227
  # @return [Integer] The proportion between the unit and the subunit
217
- # @!attribute [r] decimal_mark
228
+ # @!attribute [r] decimal_mark
218
229
  # @return [String] The decimal mark, or character used to separate the
219
230
  # whole unit from the subunit.
220
- # @!attribute [r] The
231
+ # @!attribute [r] The
221
232
  # @return [String] character used to separate thousands grouping of the
222
233
  # whole unit.
223
- # @!attribute [r] symbol_first
234
+ # @!attribute [r] symbol_first
224
235
  # @return [Boolean] Should the currency symbol precede the amount, or
225
236
  # should it come after?
226
- # @!attribute [r] smallest_denomination
237
+ # @!attribute [r] smallest_denomination
227
238
  # @return [Integer] Smallest amount of cash possible (in the subunit of
228
239
  # this currency)
229
240
 
@@ -301,7 +312,7 @@ module RedmineCrm
301
312
  end
302
313
  self.id.to_s.downcase == other_currency_id
303
314
  end
304
-
315
+
305
316
  private :compare_ids
306
317
 
307
318
  # Returns a Fixnum hash value based on the +id+ attribute in order to use
@@ -402,7 +413,7 @@ module RedmineCrm
402
413
  end
403
414
 
404
415
  private
405
-
416
+
406
417
  def cache
407
418
  self.class.decimal_places_cache
408
419
  end
@@ -436,4 +447,4 @@ module RedmineCrm
436
447
  @thousands_separator = data[:thousands_separator]
437
448
  end
438
449
  end
439
- end
450
+ end
@@ -4,8 +4,8 @@ module RedmineCrm
4
4
  module Formatting
5
5
  def self.included(base)
6
6
  [
7
- [:thousands_separator, :delimiter, ","],
8
- [:decimal_mark, :separator, "."]
7
+ [:thousands_separator, :delimiter, RedmineCrm::Settings::Money.thousands_delimiter],
8
+ [:decimal_mark, :separator, RedmineCrm::Settings::Money.decimal_separator]
9
9
  ].each do |method, name, character|
10
10
  define_i18n_method(method, name, character)
11
11
  end
@@ -115,9 +115,9 @@ module RedmineCrm
115
115
 
116
116
  def default_formatting_rules
117
117
  {
118
- :decimal_mark =>".",
119
- :thousands_separator => ",",
120
- :subunit_to_unit => 100
118
+ decimal_mark: RedmineCrm::Settings::Money.decimal_separator || '.',
119
+ thousands_separator: RedmineCrm::Settings::Money.thousands_delimiter || ',',
120
+ subunit_to_unit: 100
121
121
  }
122
122
  end
123
123
 
@@ -0,0 +1,4 @@
1
+ module RedmineCrm
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedmineCrm
4
+ module Hooks
5
+ class ViewsLayoutsHook < Redmine::Hook::ViewListener
6
+ def view_layouts_base_html_head(_context = {})
7
+ stylesheet_link_tag(:money, plugin: 'redmine_crm')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,14 +1,14 @@
1
1
  require 'action_view'
2
+ require 'redmine_crm/settings/money'
2
3
 
3
4
  module RedmineCrm
4
5
  module MoneyHelper
5
-
6
6
  def object_price(obj, price_field = :price, options = {})
7
7
  options.merge!({:symbol => true})
8
8
  price_to_currency(obj.try(price_field), obj.currency, options).to_s if obj.respond_to?(:currency)
9
9
  end
10
10
 
11
- def prices_collection_by_currency(prices_collection, options={})
11
+ def prices_collection_by_currency(prices_collection, options = {})
12
12
  return [] if prices_collection.blank? || prices_collection == 0
13
13
  prices = prices_collection
14
14
  prices.reject!{|k, v| v.to_i == 0} if options[:hide_zeros]
@@ -18,17 +18,17 @@ module RedmineCrm
18
18
  def deal_currency_icon(currency)
19
19
  case currency.to_s.upcase
20
20
  when 'EUR'
21
- "icon-money-euro"
21
+ 'icon-money-euro'
22
22
  when 'GBP'
23
- "icon-money-pound"
23
+ 'icon-money-pound'
24
24
  when 'JPY'
25
- "icon-money-yen"
25
+ 'icon-money-yen'
26
26
  else
27
- "icon-money-dollar"
27
+ 'icon-money-dollar'
28
28
  end
29
29
  end
30
30
 
31
- def collection_for_currencies_select(default_currency = 'USD', major_currencies = %w(USD EUR GBP RUB CHF))
31
+ def collection_for_currencies_select(default_currency = RedmineCrm::Settings::Money.default_currency, major_currencies = RedmineCrm::Settings::Money.major_currencies)
32
32
  currencies = []
33
33
  currencies << default_currency.to_s unless default_currency.blank?
34
34
  currencies |= major_currencies
@@ -46,17 +46,18 @@ module RedmineCrm
46
46
  end.sort{|x, y| x[0] <=> y[0]}
47
47
  end
48
48
 
49
- def price_to_currency(price, currency="USD", options={})
49
+ def price_to_currency(price, currency = RedmineCrm::Settings::Money.default_currency, options = {})
50
50
  return '' if price.blank?
51
51
 
52
- currency = "USD" unless currency.is_a?(String)
53
- currency = RedmineCrm::Currency.find(currency)
52
+ currency = 'USD' unless currency.is_a?(String)
53
+ default_options = {
54
+ decimal_mark: RedmineCrm::Settings::Money.decimal_separator,
55
+ thousands_separator: RedmineCrm::Settings::Money.thousands_delimiter
56
+ }.reject { |_k, v| v.nil? }
54
57
 
55
- return RedmineCrm::Currency.format(price.to_f, currency, options)# if currency
56
- price.to_s
58
+ currency = RedmineCrm::Currency.find(currency)
59
+ RedmineCrm::Currency.format(price.to_f, currency, default_options.merge(options))
57
60
  end
58
-
59
-
60
61
  end
61
62
  end
62
63
 
@@ -0,0 +1,39 @@
1
+ module RedmineCrm
2
+ class Settings
3
+ SECTIONS = {
4
+ 'money' => { id: :money, label: :label_redmine_crm_money, partial: 'money' }
5
+ }.freeze
6
+
7
+ class << self
8
+ # Initialize settings before using with this method
9
+ # @example
10
+ # RedmineCrm::Settings.initialize_gem_settings
11
+ def initialize_gem_settings
12
+ return if Setting.respond_to?(:plugin_redmine_crm)
13
+
14
+ Setting.send(:define_setting, 'plugin_redmine_crm', { 'default' => default_settings, 'serialized' => true })
15
+ end
16
+
17
+ # Use apply instead attrs assign because it can rewrite other attributes
18
+ def apply=(values)
19
+ Setting.plugin_redmine_crm = Setting.plugin_redmine_crm.merge(values)
20
+ end
21
+
22
+ def values
23
+ Object.const_defined?('Setting') ? Setting.plugin_redmine_crm : {}
24
+ end
25
+
26
+ def [](value)
27
+ return Setting.plugin_redmine_crm[value] if Object.const_defined?('Setting')
28
+
29
+ nil
30
+ end
31
+
32
+ private
33
+
34
+ def default_settings
35
+ {}
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ require 'redmine_crm/settings'
2
+
3
+ module RedmineCrm
4
+ class Settings
5
+ class Money
6
+ TAX_TYPE_EXCLUSIVE = 1
7
+ TAX_TYPE_INCLUSIVE = 2
8
+
9
+ class << self
10
+ def default_currency
11
+ RedmineCrm::Settings['default_currency'] || 'USD'
12
+ end
13
+
14
+ def major_currencies
15
+ currencies = RedmineCrm::Settings['major_currencies'].to_s.split(',').select { |c| !c.blank? }.map(&:strip)
16
+ currencies = %w[USD EUR GBP RUB CHF] if currencies.blank?
17
+ currencies.compact.uniq
18
+ end
19
+
20
+ def default_tax
21
+ RedmineCrm::Settings['default_tax'].to_f
22
+ end
23
+
24
+ def tax_type
25
+ ((['1', '2'] & [RedmineCrm::Settings['tax_type'].to_s]).first || TAX_TYPE_EXCLUSIVE).to_i
26
+ end
27
+
28
+ def tax_exclusive?
29
+ tax_type == TAX_TYPE_EXCLUSIVE
30
+ end
31
+
32
+ def thousands_delimiter
33
+ ([' ', ',', '.'] & [RedmineCrm::Settings['thousands_delimiter']]).first
34
+ end
35
+
36
+ def decimal_separator
37
+ ([',', '.'] & [RedmineCrm::Settings['decimal_separator']]).first
38
+ end
39
+
40
+ def disable_taxes?
41
+ RedmineCrm::Settings['disable_taxes'].to_i > 0
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module RedmineCrm
2
- VERSION = '0.0.47'
2
+ VERSION = '0.0.48'
3
3
  end
@@ -100,7 +100,8 @@ function formatStateWithMultiaddress(opt) {
100
100
  }
101
101
 
102
102
  function formatSelectionWithEmails(opt) {
103
- return opt.name ? opt.name + ' <' + opt.email + '>' : opt.text
103
+ email = $.trim(opt.email).length ? ' <' + opt.email + '>' : ''
104
+ return (opt.text || opt.name || '') + email
104
105
  }
105
106
 
106
107
  function transformToSelect2(field, options) {
@@ -0,0 +1,3 @@
1
+ .icon-redminecrm-money {
2
+ background-image: url(../images/money.png);
3
+ }
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.47
4
+ version: 0.0.48
5
5
  platform: ruby
6
6
  authors:
7
7
  - RedmineUP
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-26 00:00:00.000000000 Z
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -92,8 +92,14 @@ files:
92
92
  - Gemfile
93
93
  - README.md
94
94
  - Rakefile
95
+ - app/controllers/redmine_crm_controller.rb
96
+ - app/views/redmine_crm/_money.html.erb
97
+ - app/views/redmine_crm/settings.html.erb
95
98
  - bitbucket-pipelines.yml
96
99
  - config/currency_iso.json
100
+ - config/locales/en.yml
101
+ - config/locales/ru.yml
102
+ - config/routes.rb
97
103
  - doc/CHANGELOG
98
104
  - doc/LICENSE.txt
99
105
  - lib/redmine_crm.rb
@@ -117,10 +123,12 @@ files:
117
123
  - lib/redmine_crm/currency/formatting.rb
118
124
  - lib/redmine_crm/currency/heuristics.rb
119
125
  - lib/redmine_crm/currency/loader.rb
126
+ - lib/redmine_crm/engine.rb
120
127
  - lib/redmine_crm/helpers/external_assets_helper.rb
121
128
  - lib/redmine_crm/helpers/form_tag_helper.rb
122
129
  - lib/redmine_crm/helpers/tags_helper.rb
123
130
  - lib/redmine_crm/helpers/vote_helper.rb
131
+ - lib/redmine_crm/hooks/views_layouts_hook.rb
124
132
  - lib/redmine_crm/liquid/drops/issues_drop.rb
125
133
  - lib/redmine_crm/liquid/drops/news_drop.rb
126
134
  - lib/redmine_crm/liquid/drops/projects_drop.rb
@@ -130,6 +138,8 @@ files:
130
138
  - lib/redmine_crm/liquid/filters/base.rb
131
139
  - lib/redmine_crm/liquid/filters/colors.rb
132
140
  - lib/redmine_crm/money_helper.rb
141
+ - lib/redmine_crm/settings.rb
142
+ - lib/redmine_crm/settings/money.rb
133
143
  - lib/redmine_crm/version.rb
134
144
  - redmine_crm.gemspec
135
145
  - test/acts_as_draftable/draft_test.rb
@@ -172,10 +182,12 @@ files:
172
182
  - test/tags_helper_test.rb
173
183
  - test/test_helper.rb
174
184
  - test/vote_helper_test.rb
185
+ - vendor/assets/images/money.png
175
186
  - vendor/assets/images/vcard.png
176
187
  - vendor/assets/javascripts/Chart.bundle.min.js
177
188
  - vendor/assets/javascripts/select2.js
178
189
  - vendor/assets/javascripts/select2_helpers.js
190
+ - vendor/assets/stylesheets/money.css
179
191
  - vendor/assets/stylesheets/select2.css
180
192
  homepage: ''
181
193
  licenses: