From 8a53ae2d2cb1d291de97c3a826356c2b03f10621 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 29 Mar 2016 18:02:40 +0200 Subject: [PATCH] fix invoice attachement name --- app/mailers/notifications_mailer.rb | 4 ++-- app/models/invoice.rb | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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