From 445e63b44c65f266ce33e67a7b0d408e99c0ebdd Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 27 Jul 2022 12:04:17 +0200 Subject: [PATCH] (feature) Improved attached ICS file texts, in reservations emails --- CHANGELOG.md | 1 + app/mailers/notifications_mailer.rb | 2 +- app/models/concerns/i_calendar_concern.rb | 32 +++++++++++++++++++++-- app/pdfs/pdf/invoice.rb | 2 +- config/locales/en.yml | 10 +++---- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1a9695ce..66f1fb5a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Updated rails locales files - Usage of the rails logger instead of printing to standard output - Optionnaly add a username column to the member list (#375) +- Improved attached ICS file texts, in reservations emails - Fix a bug: canceled trainings are still shown on the public profile page - Fix a bug: prevent same slot booking feature ignores canceled reservations - Fix a bug: wrong currency on invoices files diff --git a/app/mailers/notifications_mailer.rb b/app/mailers/notifications_mailer.rb index 119074177..370bd3e92 100644 --- a/app/mailers/notifications_mailer.rb +++ b/app/mailers/notifications_mailer.rb @@ -54,7 +54,7 @@ class NotificationsMailer < NotifyWith::NotificationsMailer end def notify_member_create_reservation - attachments[@attached_object.ics_filename] = @attached_object.to_ics.encode(Encoding::ISO_8859_15) + attachments[@attached_object.ics_filename] = @attached_object.to_ics.encode(Encoding::UTF_8) mail(to: @recipient.email, subject: t('notifications_mailer.notify_member_create_reservation.subject'), template_name: 'notify_member_create_reservation') diff --git a/app/models/concerns/i_calendar_concern.rb b/app/models/concerns/i_calendar_concern.rb index 708bd99a7..fc6c09949 100644 --- a/app/models/concerns/i_calendar_concern.rb +++ b/app/models/concerns/i_calendar_concern.rb @@ -24,8 +24,8 @@ module ICalendarConcern cal.event do |e| e.dtstart = start_time e.dtend = group_slots.last[:end_at] - e.summary = I18n.t('reservation_ics.summary', TYPE: I18n.t("reservation_ics.type.#{reservable.class.name}")) - e.description = I18n.t('reservation_ics.description', COUNT: group_slots.count, ITEM: reservable.name) + e.summary = title + e.description = I18n.t('reservation_ics.description_slot', COUNT: group_slots.count, ITEM: reservable.name) e.ip_class = 'PRIVATE' e.alarm do |a| @@ -38,5 +38,33 @@ module ICalendarConcern end cal end + + private + + def title + case reservable_type + when 'Machine', 'Training', 'Space' + reservable.name + when 'Event' + reservable.title + else + Rails.logger.warn "Unexpected reservable type #{reservable_type}" + reservable_type + end + end + + def description(group_slots) + case reservable_type + when 'Machine', 'Space' + I18n.t('reservation_ics.description_slot', COUNT: group_slots.count, ITEM: reservable.name) + when 'Training' + I18n.t('reservation_ics.description_training', TYPE: reservable.name) + when 'Event' + I18n.t('reservation_ics.description_event', NUMBER: nb_reserve_places + tickets.map(&:booked).reduce(:+)) + else + Rails.logger.warn "Unexpected reservable type #{reservable_type}" + I18n.t('reservation_ics.description_slot', COUNT: group_slots.count, ITEM: reservable_type) + end + end end end diff --git a/app/pdfs/pdf/invoice.rb b/app/pdfs/pdf/invoice.rb index 07de468a8..e2962d57e 100644 --- a/app/pdfs/pdf/invoice.rb +++ b/app/pdfs/pdf/invoice.rb @@ -249,7 +249,7 @@ class PDF::Invoice < Prawn::Document data += [[I18n.t('invoices.including_amount_payed_on_ordering'), number_to_currency(total)]] # checking the round number - rounded = sprintf('%.2f', total_vat / 100.00).to_f + sprintf('%.2f', total_ht / 100.00) + rounded = (sprintf('%.2f', total_vat / 100.00).to_f + sprintf('%.2f', total_ht / 100.00).to_f).to_s if rounded != sprintf('%.2f', total_calc) Rails.logger.error 'rounding the numbers cause an invoice inconsistency. ' \ "Total expected: #{sprintf('%.2f', total_calc)}, total computed: #{rounded}" diff --git a/config/locales/en.yml b/config/locales/en.yml index fa90ed606..e89a7ed57 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -245,13 +245,9 @@ en: reservations: "Reservations" available_seats: "Available seats" reservation_ics: - summary: "%{TYPE} reservation" - type: - Machine: "Machine" - Space: "Space" - Event: "Event" - Training: "Training" - description: "You have reserved %{COUNT} slots of %{ITEM}" + description_slot: "You have booked %{COUNT} slots of %{ITEM}" + description_training: "You have booked a %{TYPE} training" + description_event: "You have booked %{NUMBER} tickets for this event" alarm_summary: "Remind your reservation" roles: member: "Member"