mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 13:15:40 +02:00
parent
6fa1ce9128
commit
30ea880211
6 changed files with 8 additions and 60 deletions
|
@ -26,7 +26,6 @@ class Invoice < ActiveRecord::Base
|
||||||
|
|
||||||
scope :overdue, -> { unpaid.non_cancelled.where('due_date < ?', Time.zone.today) }
|
scope :overdue, -> { unpaid.non_cancelled.where('due_date < ?', Time.zone.today) }
|
||||||
|
|
||||||
validates :issue_date, presence: true
|
|
||||||
validates :due_date, :currency, :seller_name,
|
validates :due_date, :currency, :seller_name,
|
||||||
:seller_iban, :buyer_name, :items, presence: true
|
:seller_iban, :buyer_name, :items, presence: true
|
||||||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
|
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeInvoicesIssueDateToNotNull < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column_null :invoices, :issue_date, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -1082,7 +1082,7 @@ CREATE TABLE public.invoices (
|
||||||
total numeric(10,2) NOT NULL,
|
total numeric(10,2) NOT NULL,
|
||||||
in_directo boolean DEFAULT false,
|
in_directo boolean DEFAULT false,
|
||||||
buyer_vat_no character varying,
|
buyer_vat_no character varying,
|
||||||
issue_date date
|
issue_date date NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -4934,6 +4934,8 @@ INSERT INTO schema_migrations (version) VALUES ('20190311111718');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20190312211614');
|
INSERT INTO schema_migrations (version) VALUES ('20190312211614');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20190315172802');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20190319133036');
|
INSERT INTO schema_migrations (version) VALUES ('20190319133036');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20190322152123');
|
INSERT INTO schema_migrations (version) VALUES ('20190322152123');
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
namespace :data_migrations do
|
|
||||||
task populate_invoice_issue_date: [:environment] do
|
|
||||||
processed_invoice_count = 0
|
|
||||||
|
|
||||||
Invoice.transaction do
|
|
||||||
Invoice.find_each do |invoice|
|
|
||||||
invoice_issue_date = invoice.created_at.to_date
|
|
||||||
invoice.update!(issue_date: invoice_issue_date)
|
|
||||||
|
|
||||||
processed_invoice_count += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
puts "Invoices processed: #{processed_invoice_count}"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -33,11 +33,6 @@ class InvoiceTest < ActiveSupport::TestCase
|
||||||
assert_not Invoice.overdue.include?(@invoice), 'Should not return non-overdue invoice'
|
assert_not Invoice.overdue.include?(@invoice), 'Should not return non-overdue invoice'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_without_issue_date
|
|
||||||
@invoice.issue_date = nil
|
|
||||||
assert @invoice.invalid?
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_optional_vat_rate
|
def test_optional_vat_rate
|
||||||
@invoice.vat_rate = nil
|
@invoice.vat_rate = nil
|
||||||
assert @invoice.valid?
|
assert @invoice.valid?
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
require 'test_helper'
|
|
||||||
|
|
||||||
class PopulateInvoiceIssueDateTaskTest < ActiveSupport::TestCase
|
|
||||||
setup do
|
|
||||||
@invoice = invoices(:one)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_populates_invoice_issue_date
|
|
||||||
eliminate_effect_of_other_invoices
|
|
||||||
@invoice.update_columns(issue_date: nil, created_at: Time.zone.parse('2010-07-05'))
|
|
||||||
assert_nil @invoice.read_attribute(:issue_date)
|
|
||||||
|
|
||||||
capture_io { run_task }
|
|
||||||
@invoice.reload
|
|
||||||
|
|
||||||
assert_equal Date.parse('2010-07-05'), @invoice.issue_date
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_outputs_results
|
|
||||||
eliminate_effect_of_other_invoices
|
|
||||||
@invoice.update_columns(issue_date: nil, created_at: Time.zone.parse('2010-07-05'))
|
|
||||||
|
|
||||||
assert_output("Invoices processed: 1\n") { run_task }
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def eliminate_effect_of_other_invoices
|
|
||||||
Invoice.connection.disable_referential_integrity do
|
|
||||||
Invoice.delete_all("id != #{@invoice.id}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def run_task
|
|
||||||
Rake::Task['data_migrations:populate_invoice_issue_date'].execute
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue