Merge pull request #2011 from internetee/2009-mark-internal-invoice-as-paid

Mark internal invoices as paid prior to sending
This commit is contained in:
Timo Võhmar 2021-06-01 13:08:13 +03:00 committed by GitHub
commit e8c19d16e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 16 deletions

View file

@ -21,7 +21,7 @@ class SendEInvoiceJob < ApplicationJob
end
def process(invoice:, payable:)
invoice.to_e_invoice(payable: payable).deliver
invoice.to_e_invoice(payable: payable).deliver unless Rails.env.development?
invoice.update(e_invoice_sent_at: Time.zone.now)
log_success(invoice)
end

View file

@ -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
end

View file

@ -15,7 +15,7 @@ module Invoice::Cancellable
end
def cancelled?
cancelled_at
cancelled_at.present?
end
def not_cancelled?

View file

@ -105,7 +105,7 @@ class Invoice < ApplicationRecord
end
def do_not_send_e_invoice?
e_invoice_sent? || cancelled? || paid?
e_invoice_sent? || cancelled?
end
def e_invoice_sent?

View file

@ -101,10 +101,11 @@ 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)
SendEInvoiceJob.perform_now(invoice.id, payable)
invoice
end