diff --git a/app/mailers/notifications_mailer.rb b/app/mailers/notifications_mailer.rb index e7d51e96a..f30a17535 100644 --- a/app/mailers/notifications_mailer.rb +++ b/app/mailers/notifications_mailer.rb @@ -28,12 +28,12 @@ class NotificationsMailer < NotifyWith::NotificationsMailer end def notify_user_when_invoice_ready - attachments['facture.pdf'] = File.read(@attached_object.file) + attachments[@attached_object.filename] = File.read(@attached_object.file) mail(to: @recipient.email, subject: t('notifications_mailer.notify_member_invoice_ready.subject'), template_name: 'notify_member_invoice_ready') end def notify_user_when_avoir_ready - attachments['avoir.pdf'] = File.read(@attached_object.file) + attachments[@attached_object.filename] = File.read(@attached_object.file) mail(to: @recipient.email, subject: t('notifications_mailer.notify_member_avoir_ready.subject'), template_name: 'notify_member_avoir_ready') end end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 6c0c252eb..0421c364d 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -18,7 +18,11 @@ class Invoice < ActiveRecord::Base # create directories if they doesn't exists (invoice & user_id) FileUtils::mkdir_p dir - "#{dir}/#{ENV['INVOICE_PREFIX']}-#{self.id}_#{self.created_at.strftime('%d%m%Y')}.pdf" + "#{dir}/#{self.filename}" + end + + def filename + "#{ENV['INVOICE_PREFIX']}-#{self.id}_#{self.created_at.strftime('%d%m%Y')}.pdf" end