diff --git a/app/mailers/invoice_mailer.rb b/app/mailers/invoice_mailer.rb index 4f01b2c15..a9d544d63 100644 --- a/app/mailers/invoice_mailer.rb +++ b/app/mailers/invoice_mailer.rb @@ -1,9 +1,10 @@ class InvoiceMailer < ApplicationMailer - def invoice_email(invoice:, recipient:) + def invoice_email(invoice:, recipient:, paid: false) @invoice = invoice subject = default_i18n_subject(invoice_number: invoice.number) + subject << I18n.t('invoice.already_paid') if paid attachments["invoice-#{invoice.number}.pdf"] = invoice.as_pdf mail(to: recipient, subject: subject) end -end \ No newline at end of file +end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 264029c8a..284df83aa 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -101,7 +101,8 @@ class Registrar < ApplicationRecord ) unless payable - InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now + InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email, paid: !payable) + .deliver_later(wait: 1.minute) end SendEInvoiceJob.perform_later(invoice.id, payable) diff --git a/config/locales/en.yml b/config/locales/en.yml index ac31d19e9..a28d97f81 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -470,7 +470,8 @@ en: price: 'Price' total: 'Total' paid_at: 'Paid at' - invoice: 'Invoice' + invoice: + already_paid: " (already paid)" bank_statements: 'Bank statements' back_to_bank_statements: 'Back to bank statements' back_to_bank_statement: 'Back to bank statement' diff --git a/config/locales/et.yml b/config/locales/et.yml index 9cb8aaa4a..a2afd9848 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -6,3 +6,5 @@ et: # Don't forget the nil at the beginning; there's no such thing as a 0th month month_names: [~, Jaanuar, Veebruar, Märts, Aprill, Mai, Juuni, Juuli, August, September, Oktoober, November, Detsember] emails: "Meillaadressid" + invoice: + already_paid: " (juba makstud)" diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index 9cccee96e..a078dfec1 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ProcessPaymentsTaskTest < ActiveSupport::TestCase +class ProcessPaymentsTaskTest < ActiveJob::TestCase setup do @payment_amount = payment_amount = 0.1 @payment_currency = payment_currency = 'EUR' @@ -162,6 +162,28 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase assert_equal 0.1, registrar.invoices.last.total end + def test_topup_creates_invoice_and_send_it_as_paid + registrar = registrars(:bestnames) + @invoice.payment_orders.destroy_all + @invoice.destroy + + perform_enqueued_jobs do + run_task + end + + invoice = Invoice.last + assert invoice.paid? + assert_not invoice.e_invoice_sent_at.blank? + + pdf_source = Invoice::PdfGenerator.new(invoice) + pdf_source.send(:invoice_html).include?('Receipt date') + + email= ActionMailer::Base.deliveries.last + assert email.subject.include?('already paid') + + assert_equal 0.1, registrar.invoices.last.total + end + def test_output assert_output "Transactions processed: 1\n" do run_task