Skip to content

Commit

Permalink
updates sidekiq and sidekiq-scheduler, fix a bug: wrong locale was ca…
Browse files Browse the repository at this point in the history
…using wrong currency in cron jobs, now we manually set the currency locale in number_to_currency
  • Loading branch information
nflorentin committed Nov 14, 2023
1 parent 1fa3f37 commit 08b4127
Show file tree
Hide file tree
Showing 34 changed files with 76 additions and 77 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog Fab-manager

## Next release

- updates sidekiq and sidekiq-scheduler
- fix a bug: wrong locale was causing wrong currency in cron jobs, now we manually set the currency locale in number_to_currency

## v6.3.1 2023 November 10

- Fix a bug: statistic_sub_type.label of plan was nil
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ gem 'friendly_id', '~> 5.1.0'
gem 'aasm'

# Background job processing
gem 'sidekiq', '>= 6.0.7'
gem 'sidekiq', '6.5.12'
# Recurring jobs for Sidekiq
gem 'sidekiq-scheduler'
gem 'sidekiq-scheduler', '5.0.3'
gem 'sidekiq-unique-jobs', '~> 7.1.23'

gem 'stripe', '5.29.0'
Expand Down
23 changes: 11 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.2.2)
connection_pool (2.2.5)
connection_pool (2.4.1)
coveralls_reborn (0.18.0)
simplecov (>= 0.18.1, < 0.20.0)
term-ansicolor (~> 1.6)
Expand Down Expand Up @@ -182,7 +182,7 @@ GEM
forgery (0.7.0)
friendly_id (5.1.0)
activerecord (>= 4.0.0)
fugit (1.5.3)
fugit (1.9.0)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
globalid (1.1.0)
Expand Down Expand Up @@ -428,7 +428,7 @@ GEM
nokogiri (>= 1.10.8)
rubyzip (>= 1.3.0)
rubyzip (2.3.2)
rufus-scheduler (3.8.1)
rufus-scheduler (3.9.1)
fugit (~> 1.1, >= 1.1.6)
safe_yaml (1.0.5)
sassc (2.4.0)
Expand All @@ -448,14 +448,13 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
sidekiq (6.4.2)
connection_pool (>= 2.2.2)
sidekiq (6.5.12)
connection_pool (>= 2.2.5, < 3)
rack (~> 2.0)
redis (>= 4.2.0)
sidekiq-scheduler (4.0.0)
redis (>= 4.2.0)
redis (>= 4.5.0, < 5)
sidekiq-scheduler (5.0.3)
rufus-scheduler (~> 3.2)
sidekiq (>= 4)
sidekiq (>= 6, < 8)
tilt (>= 1.4.0)
sidekiq-unique-jobs (7.1.23)
brpoplpush-redis_script (> 0.1.1, <= 2.0.0)
Expand Down Expand Up @@ -484,7 +483,7 @@ GEM
tins (~> 1.0)
thor (1.2.1)
thread_safe (0.3.6)
tilt (2.0.10)
tilt (2.3.0)
timeout (0.3.2)
tins (1.25.0)
sync
Expand Down Expand Up @@ -609,8 +608,8 @@ DEPENDENCIES
sentry-ruby
sha3
shakapacker (= 6.6.0)
sidekiq (>= 6.0.7)
sidekiq-scheduler
sidekiq (= 6.5.12)
sidekiq-scheduler (= 5.0.3)
sidekiq-unique-jobs (~> 7.1.23)
silencer
spring (~> 4)
Expand Down
18 changes: 9 additions & 9 deletions app/pdfs/pdf/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def initialize(invoice)
invoice.invoice_items.each do |item|
price = item.amount.to_i / 100.00

data += [[Invoices::ItemLabelService.build(invoice, item), number_to_currency(price)]]
data += [[Invoices::ItemLabelService.build(invoice, item), number_to_currency(price, locale: CURRENCY_LOCALE)]]
total_calc += price
total_ht += item.net_amount
total_vat += item.vat
Expand All @@ -92,13 +92,13 @@ def initialize(invoice)

# discount textual description
literal_discount = cp.percent_off
literal_discount = number_to_currency(cp.amount_off / 100.00) if cp.type == 'amount_off'
literal_discount = number_to_currency(cp.amount_off / 100.00, locale: CURRENCY_LOCALE) if cp.type == 'amount_off'

# add a row for the coupon
data += [[_t('invoices.coupon_CODE_discount_of_DISCOUNT',
CODE: cp.code,
DISCOUNT: literal_discount,
TYPE: cp.type), number_to_currency(-discount)]]
TYPE: cp.type), number_to_currency(-discount, locale: CURRENCY_LOCALE)]]
end

# total verification
Expand All @@ -109,18 +109,18 @@ def initialize(invoice)
vat_service = VatHistoryService.new
vat_rate_group = vat_service.invoice_vat(invoice)
if total_vat.zero?
data += [[I18n.t('invoices.total_amount'), number_to_currency(total)]]
data += [[I18n.t('invoices.total_amount'), number_to_currency(total, locale: CURRENCY_LOCALE)]]
else
data += [[I18n.t('invoices.total_including_all_taxes'), number_to_currency(total)]]
data += [[I18n.t('invoices.total_including_all_taxes'), number_to_currency(total, locale: CURRENCY_LOCALE)]]
vat_rate_group.each do |_type, rate|
data += [[I18n.t('invoices.including_VAT_RATE',
**{ RATE: rate[:vat_rate],
AMOUNT: number_to_currency(rate[:amount] / 100.00),
AMOUNT: number_to_currency(rate[:amount] / 100.00, locale: CURRENCY_LOCALE),
NAME: Setting.get('invoice_VAT-name') }),
number_to_currency(rate[:total_vat] / 100.00)]]
number_to_currency(rate[:total_vat] / 100.00, locale: CURRENCY_LOCALE)]]
end
data += [[I18n.t('invoices.including_total_excluding_taxes'), number_to_currency(total_ht / 100.00)]]
data += [[I18n.t('invoices.including_amount_payed_on_ordering'), number_to_currency(total)]]
data += [[I18n.t('invoices.including_total_excluding_taxes'), number_to_currency(total_ht / 100.00, locale: CURRENCY_LOCALE)]]
data += [[I18n.t('invoices.including_amount_payed_on_ordering'), number_to_currency(total, locale: CURRENCY_LOCALE)]]

# checking the round number
rounded = (sprintf('%.2f', total_vat / 100.00).to_f + sprintf('%.2f', total_ht / 100.00).to_f).to_s
Expand Down
6 changes: 3 additions & 3 deletions app/pdfs/pdf/payment_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def initialize(payment_schedule)
price = item.amount.to_i / 100.00
date = I18n.l(item.due_date.to_date)

data += [[date, number_to_currency(price)]]
data += [[date, number_to_currency(price, locale: CURRENCY_LOCALE)]]
end
data += [[I18n.t('payment_schedules.total_amount'), number_to_currency(payment_schedule.total / 100.0)]]
data += [[I18n.t('payment_schedules.total_amount'), number_to_currency(payment_schedule.total / 100.0, locale: CURRENCY_LOCALE)]]

# display table
font_size(8) do
Expand All @@ -100,7 +100,7 @@ def initialize(payment_schedule)
payment_verbose = _t('payment_schedules.settlement_by_METHOD', METHOD: payment_schedule.payment_method)
if payment_schedule.wallet_amount
payment_verbose += I18n.t('payment_schedules.settlement_by_wallet',
**{ AMOUNT: number_to_currency(payment_schedule.wallet_amount / 100.00) })
**{ AMOUNT: number_to_currency(payment_schedule.wallet_amount / 100.00, locale: CURRENCY_LOCALE) })
end
text payment_verbose

Expand Down
8 changes: 4 additions & 4 deletions app/services/invoices/payment_details_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def build(invoice, total)
**{ DATE: I18n.l(invoice.created_at.to_date),
TIME: I18n.l(invoice.created_at, format: :hour_minute) })}"
if total.positive? || wallet_amount.nil?
payment_verbose += " #{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(total) })}"
payment_verbose += " #{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(total, locale: CURRENCY_LOCALE) })}"
end
if invoice.wallet_amount
payment_verbose += if total.positive?
" #{I18n.t('invoices.and')} #{I18n.t('invoices.by_wallet')} " \
"#{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(wallet_amount) })}"
"#{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(wallet_amount, locale: CURRENCY_LOCALE) })}"
else
" #{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(wallet_amount) })}"
" #{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(wallet_amount, locale: CURRENCY_LOCALE) })}"
end
end
payment_verbose
Expand Down Expand Up @@ -88,7 +88,7 @@ def build_avoir_details(invoice, total)
else
Rails.logger.error "specified refunding method (#{details}) is unknown"
end
"#{details} #{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(total) })}"
"#{details} #{I18n.t('invoices.for_an_amount_of_AMOUNT', **{ AMOUNT: number_to_currency(total, locale: CURRENCY_LOCALE) })}"
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
json.title notification.notification_type
json.description t('.refund_created',
AMOUNT: number_to_currency(notification.attached_object.total / 100.00),
AMOUNT: number_to_currency(notification.attached_object.total / 100.00, locale: CURRENCY_LOCALE),
USER: notification.attached_object.invoicing_profile&.full_name)

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
json.title notification.notification_type
amount = notification.attached_object.amount
json.description t('.wallet_is_credited',
AMOUNT: number_to_currency(amount),
AMOUNT: number_to_currency(amount, locale: CURRENCY_LOCALE),
USER: notification.attached_object.wallet.user&.profile&.full_name || t('api.notifications.deleted_user'),
ADMIN: notification.attached_object.user&.profile&.full_name || t('api.notifications.deleted_user'))

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ if notification.attached_object.type == 'percent_off'
CODE: notification.attached_object.code)
else
json.description t('.enjoy_a_discount_of_AMOUNT_with_code_CODE',
AMOUNT: number_to_currency(notification.attached_object.amount_off / 100.00),
AMOUNT: number_to_currency(notification.attached_object.amount_off / 100.00, locale: CURRENCY_LOCALE),
CODE: notification.attached_object.code)
end

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
json.title notification.notification_type
amount = notification.attached_object.amount
json.description t('.your_wallet_is_credited',
AMOUNT: number_to_currency(amount))

AMOUNT: number_to_currency(amount, locale: CURRENCY_LOCALE))
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ json.title notification.notification_type
amount = notification.attached_object.total / 100.0
json.description t('.your_avoir_is_ready_html',
REFERENCE: notification.attached_object.reference,
AMOUNT: number_to_currency(amount),
AMOUNT: number_to_currency(amount, locale: CURRENCY_LOCALE),
INVOICE_ID: notification.attached_object.id)

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ json.title notification.notification_type
amount = notification.attached_object.total / 100.0
json.description t('.your_invoice_is_ready_html',
REFERENCE: notification.attached_object.reference,
AMOUNT: number_to_currency(amount),
AMOUNT: number_to_currency(amount, locale: CURRENCY_LOCALE),
INVOICE_ID: notification.attached_object.id)

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ json.title notification.notification_type
amount = notification.attached_object.total / 100.0
json.description t('.your_schedule_is_ready_html',
REFERENCE: notification.attached_object.reference,
AMOUNT: number_to_currency(amount),
AMOUNT: number_to_currency(amount, locale: CURRENCY_LOCALE),
SCHEDULE_ID: notification.attached_object.id)

10 changes: 5 additions & 5 deletions app/views/archive/_accounting.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ json.invoices do
json.type invoice[:invoice].payment_gateway_object.gateway_object_type
end
end
json.total number_to_currency(invoice[:invoice].total / 100.0)
json.total number_to_currency(invoice[:invoice].total / 100.0, locale: CURRENCY_LOCALE)
json.user do
json.extract! invoice[:invoice].invoicing_profile, :user_id, :email, :first_name, :last_name
json.address invoice[:invoice].invoicing_profile&.address&.address
Expand Down Expand Up @@ -46,7 +46,7 @@ json.payment_schedules do
json.id object.gateway_object_id
json.type object.gateway_object_type
end
json.total number_to_currency(schedule.total / 100.0)
json.total number_to_currency(schedule.total / 100.0, locale: CURRENCY_LOCALE)
json.user do
json.extract! schedule.invoicing_profile, :user_id, :email, :first_name, :last_name
json.address schedule.invoicing_profile&.address&.address
Expand All @@ -60,7 +60,7 @@ json.payment_schedules do
end
json.deadlines schedule.payment_schedule_items do |item|
json.extract! item, :id, :due_date, :state, :details, :invoice_id, :footprint, :created_at
json.amount number_to_currency(item.amount / 100.0)
json.amount number_to_currency(item.amount / 100.0, locale: CURRENCY_LOCALE)
end
json.objects schedule.payment_schedule_objects do |object|
json.type object.object_type
Expand All @@ -71,8 +71,8 @@ json.payment_schedules do
end

json.totals do
json.period_total number_to_currency(period_total / 100.0)
json.perpetual_total number_to_currency(perpetual_total / 100.0)
json.period_total number_to_currency(period_total / 100.0, locale: CURRENCY_LOCALE)
json.perpetual_total number_to_currency(perpetual_total / 100.0, locale: CURRENCY_LOCALE)
end

json.software do
Expand Down
4 changes: 2 additions & 2 deletions app/views/archive/_vat.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

json.amount do
json.without_tax number_to_currency((price - (price * vat_rate)) / 100.0)
json.all_taxes_included number_to_currency(price / 100.0)
json.without_tax number_to_currency((price - (price * vat_rate)) / 100.0, locale: CURRENCY_LOCALE)
json.all_taxes_included number_to_currency(price / 100.0, locale: CURRENCY_LOCALE)
json.vat_rate vat_rate.positive? ? number_to_percentage(vat_rate * 100) : 'none'
end
2 changes: 1 addition & 1 deletion app/views/exports/users_subscriptions.xlsx.axlsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ wb.add_worksheet(name: ExcelService.name_safe(t('export_subscriptions.subscripti
t("duration.#{sub.plan.interval}", count: sub.plan.interval_count),
sub.created_at.to_date,
sub.expired_at.to_date,
number_to_currency(sub.plan.amount / 100.00)
number_to_currency(sub.plan.amount / 100.00, locale: CURRENCY_LOCALE)
]
styles = [nil, nil, nil, nil, nil, date, date, nil, nil]
types = %i[integer string string string string date date string string]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
<%= t('.body.remember',
REFERENCE: @attached_object.payment_schedule.reference,
AMOUNT: number_to_currency(@attached_object.amount / 100.00),
AMOUNT: number_to_currency(@attached_object.amount / 100.00, locale: CURRENCY_LOCALE),
DATE: I18n.l(@attached_object.due_date, format: :long)) %>
<%= t('.body.date') %>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
<%= t('.body.remember',
REFERENCE: @attached_object.payment_schedule.reference,
AMOUNT: number_to_currency(@attached_object.amount / 100.00),
AMOUNT: number_to_currency(@attached_object.amount / 100.00, locale: CURRENCY_LOCALE),
DATE: I18n.l(@attached_object.due_date, format: :long)) %>
<%= t('.body.error', GATEWAY: @attached_object.payment_gateway_object.gateway_object.gateway) %>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
<%= t('.body.remember',
REFERENCE: @attached_object.payment_schedule.reference,
AMOUNT: number_to_currency(@attached_object.amount / 100.00),
AMOUNT: number_to_currency(@attached_object.amount / 100.00, locale: CURRENCY_LOCALE),
DATE: I18n.l(@attached_object.due_date, format: :long)) %>
<%= t('.body.error') %>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
<%= t('.body.remember',
REFERENCE: @attached_object.payment_schedule.reference,
AMOUNT: number_to_currency(@attached_object.amount / 100.00),
AMOUNT: number_to_currency(@attached_object.amount / 100.00, locale: CURRENCY_LOCALE),
DATE: I18n.l(@attached_object.due_date, format: :long)) %>
<%= t('.body.date') %>
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>

<p><%= t('.body.refund_created',
AMOUNT: number_to_currency(@attached_object.total / 100.00),
AMOUNT: number_to_currency(@attached_object.total / 100.00, locale: CURRENCY_LOCALE),
INVOICE: @attached_object.invoice.reference,
USER: @attached_object.invoicing_profile&.full_name) if @attached_object.invoice %>
<%= t('.body.wallet_refund_created',
AMOUNT: number_to_currency(@attached_object.total / 100.00),
AMOUNT: number_to_currency(@attached_object.total / 100.00, locale: CURRENCY_LOCALE),
USER: @attached_object.invoicing_profile&.full_name) if @attached_object.main_item.object_type === WalletTransaction.name %>
</p>
<p><a href="<%= "#{root_url}api/invoices/#{@attached_object.id}/download" %>" target="_blank"><%= t('.body.download') %></a></p>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
<p>
<%= t('.body.wallet_credit_html',
AMOUNT: number_to_currency(@attached_object.amount),
AMOUNT: number_to_currency(@attached_object.amount, locale: CURRENCY_LOCALE),
USER: @attached_object.wallet.user&.profile&.full_name || t('api.notifications.deleted_user'),
ADMIN: @attached_object.user&.profile&.full_name || t('api.notifications.deleted_user'))
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</p>
<% else %>
<p><%= t('.body.enjoy_a_discount_of_AMOUNT_with_code_CODE',
AMOUNT: number_to_currency(@attached_object.amount_off / 100.00),
AMOUNT: number_to_currency(@attached_object.amount_off / 100.00, locale: CURRENCY_LOCALE),
CODE: @attached_object.code
) %>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= _t('.body.please_find_attached_html',
{
DATE: I18n.l(@attached_object.avoir_date.to_date),
AMOUNT: number_to_currency(@attached_object.total / 100.0),
AMOUNT: number_to_currency(@attached_object.total / 100.0, locale: CURRENCY_LOCALE),
TYPE: @attached_object.main_item.object_type
})
# messageFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= _t('.body.please_find_attached_html',
{
DATE: I18n.l(@attached_object.created_at.to_date),
AMOUNT: number_to_currency(@attached_object.total / 100.0),
AMOUNT: number_to_currency(@attached_object.total / 100.0, locale: CURRENCY_LOCALE),
TYPE: @attached_object.main_item.object_type
})
# messageFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
<%= t('.body.remember',
REFERENCE: @attached_object.payment_schedule.reference,
AMOUNT: number_to_currency(@attached_object.amount / 100.00),
AMOUNT: number_to_currency(@attached_object.amount / 100.00, locale: CURRENCY_LOCALE),
DATE: I18n.l(@attached_object.due_date, format: :long)) %>
<%= t('.body.error') %>
</p>
Expand Down
Loading

0 comments on commit 08b4127

Please sign in to comment.