mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 13:36:15 +02:00
Fix admin invoices CSV output
This commit is contained in:
parent
f44bdd1930
commit
7d79e6528d
4 changed files with 41 additions and 1 deletions
|
@ -117,6 +117,23 @@ class Invoice < ApplicationRecord
|
|||
e_invoice_sent_at.present?
|
||||
end
|
||||
|
||||
def as_csv_row
|
||||
[
|
||||
number,
|
||||
buyer,
|
||||
cancelled? ? I18n.t(:cancelled) : due_date,
|
||||
receipt_date_status,
|
||||
issue_date,
|
||||
total,
|
||||
currency,
|
||||
seller_name
|
||||
]
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
['Number', 'Buyer', 'Due Date', 'Receipt Date', 'Issue Date', 'Total', 'Currency', 'Seller Name'].freeze
|
||||
end
|
||||
|
||||
def self.create_from_transaction!(transaction)
|
||||
registrar_user = Registrar.find_by(reference_no: transaction.parsed_ref_number)
|
||||
return unless registrar_user
|
||||
|
@ -128,6 +145,16 @@ class Invoice < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def receipt_date_status
|
||||
if paid?
|
||||
receipt_date
|
||||
elsif cancelled?
|
||||
I18n.t(:cancelled)
|
||||
else
|
||||
I18n.t(:unpaid)
|
||||
end
|
||||
end
|
||||
|
||||
def apply_default_buyer_vat_no
|
||||
self.buyer_vat_no = buyer.vat_no
|
||||
end
|
||||
|
|
|
@ -12,6 +12,6 @@ class CsvGenerator
|
|||
private
|
||||
|
||||
def self.custom_csv(class_name)
|
||||
[Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice].include?(class_name)
|
||||
[Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice, Account].include?(class_name)
|
||||
end
|
||||
end
|
||||
|
|
3
test/fixtures/files/invoices.csv
vendored
Normal file
3
test/fixtures/files/invoices.csv
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
Number,Buyer,Due Date,Receipt Date,Issue Date,Total,Currency,Seller Name
|
||||
2,Best Names,2010-07-06,Unpaid,2010-07-05,16.5,EUR,Seller Ltd
|
||||
1,Best Names,2010-07-06,2010-07-05,2010-07-05,16.5,EUR,Seller Ltd
|
|
|
@ -40,4 +40,14 @@ class AdminAreaInvoicesTest < ApplicationSystemTestCase
|
|||
assert_current_path admin_invoice_path(@invoice)
|
||||
assert_text 'Invoice has been sent'
|
||||
end
|
||||
|
||||
def test_download_invoices_list_as_csv
|
||||
travel_to Time.zone.parse('2010-07-05 10:30')
|
||||
|
||||
visit admin_invoices_url
|
||||
click_link('CSV')
|
||||
|
||||
assert_equal "attachment; filename=\"invoices_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''invoices_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition']
|
||||
assert_equal file_fixture('invoices.csv').read, page.body
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue