diff --git a/app/models/invoice.rb b/app/models/invoice.rb index a36825848d..50453f61fc 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -3,7 +3,6 @@ class Invoice < ActiveRecord::Base include Concerns::Invoice::Cancellable include Concerns::Invoice::Payable - belongs_to :seller, class_name: 'Registrar' belongs_to :buyer, class_name: 'Registrar' has_one :account_activity has_many :items, class_name: 'InvoiceItem', dependent: :destroy diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml index 9ed8b91d54..76a2966b53 100644 --- a/app/views/registrar/invoices/index.haml +++ b/app/views/registrar/invoices/index.haml @@ -57,7 +57,7 @@ %th{class: 'col-xs-3'}= t(:total) %tbody - @invoices.each do |invoice| - %tr.invoice + %tr %td= link_to(invoice, [:registrar, invoice]) - if invoice.paid? %td= l invoice.receipt_date diff --git a/db/migrate/20190811184334_remove_invoices_seller_id.rb b/db/migrate/20190811184334_remove_invoices_seller_id.rb new file mode 100644 index 0000000000..d96dfedb41 --- /dev/null +++ b/db/migrate/20190811184334_remove_invoices_seller_id.rb @@ -0,0 +1,5 @@ +class RemoveInvoicesSellerId < ActiveRecord::Migration + def change + remove_column :invoices, :seller_id + end +end diff --git a/db/structure.sql b/db/structure.sql index befd74afd3..a3d9fb4816 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -935,7 +935,6 @@ CREATE TABLE public.invoices ( description character varying, reference_no character varying NOT NULL, vat_rate numeric(4,3) NOT NULL, - seller_id integer, seller_name character varying NOT NULL, seller_reg_no character varying, seller_iban character varying NOT NULL, @@ -3453,13 +3452,6 @@ CREATE INDEX index_invoice_items_on_invoice_id ON public.invoice_items USING btr CREATE INDEX index_invoices_on_buyer_id ON public.invoices USING btree (buyer_id); --- --- Name: index_invoices_on_seller_id; Type: INDEX; Schema: public; Owner: -; Tablespace: --- - -CREATE INDEX index_invoices_on_seller_id ON public.invoices USING btree (seller_id); - - -- -- Name: index_keyrelays_on_accepter_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -4817,3 +4809,5 @@ INSERT INTO schema_migrations (version) VALUES ('20190617122505'); INSERT INTO schema_migrations (version) VALUES ('20190620084334'); +INSERT INTO schema_migrations (version) VALUES ('20190811184334'); + diff --git a/test/system/registrar_area/invoices/list_test.rb b/test/system/registrar_area/invoices/list_test.rb index e63d8c1a48..b6d659a96b 100644 --- a/test/system/registrar_area/invoices/list_test.rb +++ b/test/system/registrar_area/invoices/list_test.rb @@ -3,10 +3,9 @@ class ListInvoicesTest < ApplicationSystemTestCase setup do @user = users(:api_bestnames) - sign_in @user - @invoice = invoices(:one) - eliminate_effect_of_other_invoices + + sign_in @user end def test_show_balance @@ -14,31 +13,23 @@ def test_show_balance assert_text "Your current account balance is 100,00 EUR" end - def test_show_invoices_of_current_registrar - registrar = registrars(:bestnames) - @user.update!(registrar: registrar) - @invoice.update!(seller: registrar) + def test_shows_invoice_owned_by_current_user + owning_registrar = registrars(:bestnames) + assert_equal owning_registrar, @user.registrar + @invoice.update!(buyer: owning_registrar) visit registrar_invoices_url - assert_css '.invoice' + assert_text @invoice.to_s end - def test_do_not_show_invoices_of_other_registrars - registrar = registrars(:goodnames) - @user.update!(registrar: registrar) - @invoice.update!(seller: registrar) + def test_hides_invoice_owned_by_other_user + other_registrar = registrars(:goodnames) + assert_not_equal other_registrar, @user.registrar + @invoice.update!(buyer: other_registrar) visit registrar_invoices_url - assert_no_css '.invoice' - end - - private - - def eliminate_effect_of_other_invoices - Invoice.connection.disable_referential_integrity do - Invoice.delete_all("id != #{@invoice.id}") - end + assert_no_text @invoice.to_s end end \ No newline at end of file