Skip to content

Commit 5c47b54

Browse files
Currency2 (#1983)
* currencies step2
1 parent fbcbdf4 commit 5c47b54

59 files changed

Lines changed: 12187 additions & 142 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TODO.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# TODO
2+
3+
## Rate Management Project form - nullable boolean fields with include_blank: false
4+
5+
`app/admin/rate_management/projects.rb` has `include_blank: false` on:
6+
- `reverse_billing` — nullable in DB (`default(FALSE)`, no NOT NULL constraint)
7+
- `routing_tag_mode_id` — nullable in DB (`default(0)`, no NOT NULL constraint), validation uses `allow_nil: true`
8+
9+
Check whether these fields should actually allow nil (user should be able to clear them),
10+
in which case `include_blank: false` is wrong and should be removed.
11+
12+
Compare with:
13+
- `enabled` — NOT NULL in DB, validates inclusion without allow_nil → `include_blank: false` is correct
14+
- `exclusive_route` — NOT NULL in DB → `include_blank: false` is correct

app/admin/billing/accounts.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ def scoped_collection
252252
f.inputs form_title do
253253
f.input :name
254254
f.contractor_input :contractor_id
255-
f.input :currency_id, as: :select, input_html: { class: 'tom-select', disabled: !f.object.new_record? },
256-
collection: Billing::Currency.order(:name).map { |c| [c.name, c.id] }
255+
f.input :currency_id, as: :select, required: true, include_blank: false, collection: Billing::Currency.order(:name), input_html: { class: 'tom-select', disabled: !f.object.new_record? }
257256
f.input :min_balance
258257
f.input :max_balance
259258
f.input :vat
@@ -265,7 +264,7 @@ def scoped_collection
265264
f.input :termination_capacity
266265
f.input :total_capacity
267266

268-
f.input :timezone, as: :select, input_html: { class: 'tom-select' }, collection: Yeti::TimeZoneHelper.all
267+
f.input :timezone, as: :select, required: true, include_blank: false, input_html: { class: 'tom-select' }, collection: Yeti::TimeZoneHelper.all
269268
f.input :uuid, as: :string
270269
end
271270

app/admin/cdr/cdrs.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def try_cdr_replica(&)
393393

394394
column :vendor_price, &:decorated_vendor_price
395395
column :vendor_duration, &:decorated_vendor_duration
396-
column :profit
396+
column :profit, &:decorated_profit
397397
column('Orig call', &:orig_call_id)
398398
column :local_tag
399399
column :legb_local_tag
@@ -580,7 +580,7 @@ def try_cdr_replica(&)
580580
row :customer_duration, &:decorated_customer_duration
581581
row :vendor_price, &:decorated_vendor_price
582582
row :vendor_duration, &:decorated_vendor_duration
583-
row :profit
583+
row :profit, &:decorated_profit
584584

585585
row :rateplan
586586
row :destination
@@ -799,7 +799,7 @@ def try_cdr_replica(&)
799799

800800
column :vendor_price, &:decorated_vendor_price
801801
column :vendor_duration, &:decorated_vendor_duration
802-
column :profit
802+
column :profit, &:decorated_profit
803803
column :orig_call_id
804804
column :local_tag
805805
column :legb_local_tag

app/admin/routing/destinations.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
:initial_interval, :next_interval,
4545
:use_dp_intervals,
4646
:initial_rate, :next_rate, :connect_fee,
47+
[:currency_name, proc { |row| row.currency.name }],
4748
:dp_margin_fixed, :dp_margin_percent,
4849
:profit_control_mode_name,
4950
:valid_from, :valid_till,
@@ -108,7 +109,7 @@
108109
:dp_margin_percent, :rate_policy_id, :reverse_billing, :initial_rate,
109110
:reject_calls, :use_dp_intervals, :test, :profit_control_mode_id,
110111
:valid_from, :valid_till, :asr_limit, :acd_limit, :short_calls_limit, :batch_prefix,
111-
:reverse_billing, :routing_tag_mode_id, :allow_package_billing, :scheduler_id, routing_tag_ids: []
112+
:reverse_billing, :routing_tag_mode_id, :allow_package_billing, :scheduler_id, :currency_id, routing_tag_ids: []
112113

113114
action_item :show_rates, only: [:show] do
114115
link_to 'Show Rates', destination_destination_next_rates_path(resource.id)
@@ -136,7 +137,7 @@ def update
136137
#
137138
# preload have more controllable behavior, but sorting by associated tables not possible
138139
def scoped_collection
139-
super.preload(:rate_group, network_prefix: %i[country network])
140+
super.preload(:rate_group, :currency, network_prefix: %i[country network])
140141
end
141142
end
142143

@@ -176,15 +177,11 @@ def scoped_collection
176177
column :valid_till, &:decorated_valid_till
177178

178179
column :rate_policy, &:rate_policy_name
179-
column :reverse_billing
180180
column :allow_package_billing
181181

182182
## fixed price
183-
column :initial_interval
184-
column :initial_rate
185-
column :next_interval
186-
column :next_rate
187-
column :connect_fee
183+
column :rates, &:decorated_rates
184+
column :intervals, &:decorated_intervals
188185
column :use_dp_intervals
189186

190187
# cost + X ( $ or % )
@@ -241,6 +238,7 @@ def scoped_collection
241238
end
242239
end
243240
f.inputs 'Fixed rating configuration' do
241+
f.input :currency, as: :select, include_blank: false, input_html: { class: 'tom-select' }
244242
f.input :initial_rate
245243
f.input :next_rate
246244
f.input :connect_fee
@@ -301,6 +299,9 @@ def scoped_collection
301299
end
302300
panel 'Fixed rating configuration' do
303301
attributes_table_for s do
302+
row :currency do
303+
status_tag s.currency.name
304+
end
304305
row :initial_rate
305306
row :next_rate
306307
row :connect_fee

app/admin/routing/dialpeers.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
[:scheduler_name, proc { |row| row.scheduler.try(:name) }],
2828
:prefix, :priority, :force_hit_rate, :exclusive_route,
2929
:initial_interval, :initial_rate, :next_interval, :next_rate, :connect_fee,
30+
[:currency_name, proc { |row| row.currency.name }],
3031
:lcr_rate_multiplier,
3132
[:gateway_name, proc { |row| row.gateway.try(:name) }],
3233
[:gateway_group_name, proc { |row| row.gateway_group.try(:name) }],
@@ -67,7 +68,7 @@ def update
6768
# preload have more controllable behavior, but sorting by associated tables not possible
6869
def scoped_collection
6970
super.preload(:gateway, :gateway_group, :routing_group, :vendor, :account, :statistic,
70-
:routeset_discriminator, network_prefix: %i[country network])
71+
:currency, :routeset_discriminator, network_prefix: %i[country network])
7172
end
7273
end
7374

@@ -102,15 +103,10 @@ def scoped_collection
102103
end
103104
column :routing_group
104105
column :routing_tags
105-
column :priority
106+
column :priority, &:decorated_priority
106107
column :force_hit_rate
107-
column :exclusive_route
108-
column :initial_interval
109-
column :initial_rate
110-
column :next_interval
111-
column :next_rate
112-
column :connect_fee
113-
column :reverse_billing
108+
column :rates, &:decorated_rates
109+
column :intervals, &:decorated_intervals
114110
column :lcr_rate_multiplier
115111
column :gateway do |c|
116112
auto_link(c.gateway, c.gateway.decorated_termination_display_name) unless c.gateway.nil?
@@ -254,13 +250,14 @@ def scoped_collection
254250
f.input :priority
255251
f.input :force_hit_rate
256252
f.input :exclusive_route
257-
f.input :initial_interval
258253
f.input :initial_rate
259-
f.input :next_interval
260254
f.input :next_rate
261-
f.input :lcr_rate_multiplier
262255
f.input :connect_fee
256+
f.input :currency, as: :select, include_blank: false, input_html: { class: 'tom-select' }
263257
f.input :reverse_billing
258+
f.input :lcr_rate_multiplier
259+
f.input :initial_interval
260+
f.input :next_interval
264261

265262
f.association_ajax_input :gateway_id,
266263
label: 'Gateway',
@@ -329,6 +326,9 @@ def scoped_collection
329326
row :initial_rate
330327
row :next_interval
331328
row :next_rate
329+
row :currency do
330+
status_tag s.currency.name
331+
end
332332
row :lcr_rate_multiplier
333333
row :connect_fee
334334
row :reverse_billing

app/assets/javascripts/tom-select.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ function initTomSelect(parent, options = {}) {
3232
parent.find('select.tom-select, select.tom-select-wide').each(function () {
3333
if (this.tomselect) return
3434

35-
var plugins = ['clear_button', 'dropdown_input']
35+
var plugins = ['dropdown_input']
3636
var el = this
3737
var $el = $(el)
3838
var isMultiple = !!$el.attr('multiple')
3939
var allowEmptyOption = !!$el.data('allow-empty-option')
40+
if (hasBlankOption(el)) plugins.push('clear_button')
4041
if (isMultiple) plugins.push('remove_button')
4142
new TomSelect(this, {
4243
plugins: plugins,

app/decorators/cdr_decorator.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,31 @@ def decorated_vendor_duration
8181
end
8282

8383
def decorated_customer_price
84+
currency_name = h.currencies_map[customer_currency_id]
8485
h.safe_join([
8586
customer_price,
87+
*(h.tag.span(currency_name, class: 'status_tag') if currency_name),
8688
*(h.tag.span('R', class: 'status_tag red') if destination_reverse_billing)
8789
], ' ')
8890
end
8991

9092
def decorated_vendor_price
93+
currency_name = h.currencies_map[vendor_currency_id]
9194
h.safe_join([
9295
vendor_price,
96+
*(h.tag.span(currency_name, class: 'status_tag') if currency_name),
9397
*(h.tag.span('R', class: 'status_tag red') if dialpeer_reverse_billing)
9498
], ' ')
9599
end
96100

101+
def decorated_profit
102+
system_currency_name = h.currencies_map[0]
103+
h.safe_join([
104+
profit,
105+
*(h.tag.span(system_currency_name, class: 'status_tag') if system_currency_name)
106+
], ' ')
107+
end
108+
97109
def decorated_destination_rates
98110
h.safe_join([
99111
"#{destination_fee} #{destination_initial_rate}/#{destination_next_rate}".chomp('/'),

app/decorators/destination_decorator.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ def decorated_display_name
2323
end
2424
end
2525

26+
def decorated_rates
27+
h.safe_join([
28+
"#{connect_fee} #{initial_rate}/#{next_rate}".chomp('/'),
29+
h.tag.span(currency.name, class: 'status_tag'),
30+
*(h.tag.span('R', class: 'status_tag red') if reverse_billing)
31+
], ' ')
32+
end
33+
34+
def decorated_intervals
35+
"#{initial_interval}/#{next_interval}"
36+
end
37+
2638
def decorated_valid_from
2739
is_valid_from? ? valid_from : h.content_tag(:font, valid_from, color: :red)
2840
end

app/decorators/dialpeer_decorator.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ def decorated_display_name
2727
end
2828
end
2929

30+
def decorated_priority
31+
h.safe_join([
32+
priority.to_s,
33+
*(h.tag.span('exclusive', class: 'status_tag orange') if exclusive_route)
34+
], ' ')
35+
end
36+
37+
def decorated_intervals
38+
"#{initial_interval}/#{next_interval}"
39+
end
40+
41+
def decorated_rates
42+
h.safe_join([
43+
"#{connect_fee} #{initial_rate}/#{next_rate}".chomp('/'),
44+
h.tag.span(currency.name, class: 'status_tag'),
45+
*(h.tag.span('R', class: 'status_tag red') if reverse_billing)
46+
], ' ')
47+
end
48+
3049
def decorated_valid_from
3150
is_valid_from? ? valid_from : h.content_tag(:font, valid_from, color: :red)
3251
end

app/helpers/application_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def routing_tags_map
6060
@routing_tags_map ||= Routing::RoutingTag.all.pluck(:id, :name).to_h
6161
end
6262

63+
def currencies_map
64+
@currencies_map ||= Billing::Currency.pluck(:id, :name).to_h
65+
end
66+
6367
def tag_action_value_options
6468
@tag_action_value_options ||= Routing::RoutingTag.all.map { |record| [record.display_name, record.id] }
6569
end

0 commit comments

Comments
 (0)