diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index bf059cc88..bea629e17 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -33,6 +33,8 @@ class SalesLog < Log before_validation :set_derived_fields! before_validation :process_uprn_change!, if: :should_process_uprn_change? + belongs_to :managing_organisation, class_name: "Organisation", optional: true + scope :filter_by_year, ->(year) { where(saledate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) } scope :filter_by_purchaser_code, ->(purchid) { where("purchid ILIKE ?", "%#{purchid}%") } scope :search_by, lambda { |param| diff --git a/db/migrate/20231121131725_add_sales_managing_organisation.rb b/db/migrate/20231121131725_add_sales_managing_organisation.rb new file mode 100644 index 000000000..f4085414a --- /dev/null +++ b/db/migrate/20231121131725_add_sales_managing_organisation.rb @@ -0,0 +1,7 @@ +class AddSalesManagingOrganisation < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.references :managing_organisation, class_name: "Organisation" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7eda570d1..b3c7e3797 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_23_142854) do +ActiveRecord::Schema[7.0].define(version: 2023_11_21_131725) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -624,8 +624,10 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_23_142854) do t.integer "creation_method", default: 1 t.integer "old_form_id" t.datetime "values_updated_at" + t.bigint "managing_organisation_id" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_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 ["old_id"], name: "index_sales_logs_on_old_id", unique: true 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"