Browse Source

feat: remove sales log managing_organisation_id

pull/1169/head
natdeanlewissoftwire 3 years ago
parent
commit
eed79b9778
  1. 12
      app/components/log_summary_component.html.erb
  2. 1
      app/models/organisation.rb
  3. 1
      app/models/user.rb
  4. 13
      db/migrate/20230110094518_remove_managing_organisation_id_from_sales_logs.rb
  5. 5
      db/schema.rb
  6. 2
      spec/requests/sales_logs_controller_spec.rb

12
app/components/log_summary_component.html.erb

@ -37,16 +37,18 @@
<% end %> <% end %>
<% if current_user.support? %> <% if current_user.support? %>
<% if log.owning_organisation or log.managing_organisation %> <% if log.owning_organisation %>
<dl class="app-metadata"> <dl class="app-metadata">
<div class="app-metadata__item"> <div class="app-metadata__item">
<dt class="app-metadata__term">Owned by</dt> <dt class="app-metadata__term">Owned by</dt>
<dd class="app-metadata__definition"><%= log.owning_organisation&.name %></dd> <dd class="app-metadata__definition"><%= log.owning_organisation&.name %></dd>
</div> </div>
<div class="app-metadata__item"> <% if log.managing_organisation %>
<dt class="app-metadata__term">Managed by</dt> <div class="app-metadata__item">
<dd class="app-metadata__definition"><%= log.managing_organisation&.name %></dd> <dt class="app-metadata__term">Managed by</dt>
</div> <dd class="app-metadata__definition"><%= log.managing_organisation&.name %></dd>
</div>
<% end %>
</dl> </dl>
<% end %> <% end %>
<% end %> <% end %>

1
app/models/organisation.rb

@ -3,7 +3,6 @@ class Organisation < ApplicationRecord
has_many :owned_lettings_logs, class_name: "LettingsLog", foreign_key: "owning_organisation_id", dependent: :delete_all has_many :owned_lettings_logs, class_name: "LettingsLog", foreign_key: "owning_organisation_id", dependent: :delete_all
has_many :managed_lettings_logs, class_name: "LettingsLog", foreign_key: "managing_organisation_id" has_many :managed_lettings_logs, class_name: "LettingsLog", foreign_key: "managing_organisation_id"
has_many :owned_sales_logs, class_name: "SalesLog", foreign_key: "owning_organisation_id", dependent: :delete_all has_many :owned_sales_logs, class_name: "SalesLog", foreign_key: "owning_organisation_id", dependent: :delete_all
has_many :managed_sales_logs, class_name: "SalesLog", foreign_key: "managing_organisation_id"
has_many :data_protection_confirmations has_many :data_protection_confirmations
has_many :organisation_rent_periods has_many :organisation_rent_periods
has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id", dependent: :delete_all has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id", dependent: :delete_all

1
app/models/user.rb

@ -10,7 +10,6 @@ class User < ApplicationRecord
has_many :owned_lettings_logs, through: :organisation has_many :owned_lettings_logs, through: :organisation
has_many :managed_lettings_logs, through: :organisation has_many :managed_lettings_logs, through: :organisation
has_many :owned_sales_logs, through: :organisation has_many :owned_sales_logs, through: :organisation
has_many :managed_sales_logs, through: :organisation
has_many :legacy_users has_many :legacy_users
validates :name, presence: true validates :name, presence: true

13
db/migrate/20230110094518_remove_managing_organisation_id_from_sales_logs.rb

@ -0,0 +1,13 @@
class RemoveManagingOrganisationIdFromSalesLogs < ActiveRecord::Migration[7.0]
def up
change_table :sales_logs, bulk: true do |t|
t.remove :managing_organisation_id
end
end
def down
change_table :sales_logs, bulk: true do |t|
t.column :managing_organisation_id, :bigint
end
end
end

5
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_01_09_160738) do ActiveRecord::Schema[7.0].define(version: 2023_01_10_094518) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -352,7 +352,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_09_160738) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.bigint "owning_organisation_id" t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.bigint "created_by_id" t.bigint "created_by_id"
t.string "purchid" t.string "purchid"
t.integer "type" t.integer "type"
@ -471,8 +470,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_09_160738) do
t.integer "hoday" t.integer "hoday"
t.integer "homonth" t.integer "homonth"
t.integer "hoyear" t.integer "hoyear"
t.integer "extrabor"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"
t.index ["updated_by_id"], name: "index_sales_logs_on_updated_by_id" t.index ["updated_by_id"], name: "index_sales_logs_on_updated_by_id"
end end

2
spec/requests/sales_logs_controller_spec.rb

@ -119,7 +119,7 @@ RSpec.describe SalesLogsController, type: :request do
it "does have organisation values" do it "does have organisation values" do
get "/sales-logs", headers: headers, params: {} get "/sales-logs", headers: headers, params: {}
expect(page).to have_content("Owned by") expect(page).to have_content("Owned by")
expect(page).to have_content("Managed by") expect(page).not_to have_content("Managed by")
end end
it "shows sales logs for all organisations" do it "shows sales logs for all organisations" do

Loading…
Cancel
Save