Browse Source

Add managing_organisation_id to sales

pull/2049/head
Kat 3 years ago
parent
commit
19006c6e7d
  1. 2
      app/models/sales_log.rb
  2. 7
      db/migrate/20231121131725_add_sales_managing_organisation.rb
  3. 4
      db/schema.rb

2
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|

7
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

4
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"

Loading…
Cancel
Save