mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +02:00
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:
commit
e8c19d16e8
9 changed files with 60 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,7 +15,7 @@ module Invoice::Cancellable
|
|||
end
|
||||
|
||||
def cancelled?
|
||||
cancelled_at
|
||||
cancelled_at.present?
|
||||
end
|
||||
|
||||
def not_cancelled?
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue