Browse Source

Derive providertype from org

pull/291/head
Kat 3 years ago
parent
commit
5bd107ce51
  1. 4
      app/models/case_log.rb
  2. 5
      app/models/constants/case_log.rb
  3. 7
      db/migrate/20220209164758_add_providertype.rb
  4. 22
      db/schema.rb
  5. 2
      spec/fixtures/exports/case_logs.xml
  6. 8
      spec/models/case_log_spec.rb

4
app/models/case_log.rb

@ -142,8 +142,9 @@ class CaseLog < ApplicationRecord
enum nocharge: POLAR, _suffix: true
enum referral: REFERRAL, _suffix: true
enum declaration: POLAR, _suffix: true
enum providertype: PROVIDER_TYPE, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at providertype].freeze
def form
FormHandler.instance.get_form(form_name)
@ -255,6 +256,7 @@ private
self.layear = "Less than 1 year" if renewal == "Yes"
self.underoccupation_benefitcap = "No" if renewal == "Yes" && year == 2021
self.homeless = "No" if renewal == "Yes"
self.providertype = owning_organisation.provider_type
end
def process_postcode_changes!

5
app/models/constants/case_log.rb

@ -1125,4 +1125,9 @@ module Constants::CaseLog
"Other"].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze
PROVIDER_TYPE = {
"LA" => 1,
"PRP" => 2,
}.freeze
end

7
db/migrate/20220209164758_add_providertype.rb

@ -0,0 +1,7 @@
class AddProvidertype < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :providertype, :integer
end
end
end

22
db/schema.rb

@ -10,8 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 202202071123100) do
ActiveRecord::Schema[7.0].define(version: 202202071123100) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -21,8 +20,8 @@ ActiveRecord::Schema.define(version: 202202071123100) do
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "second_factor_attempts_count", default: 0
t.string "encrypted_otp_secret_key"
t.string "encrypted_otp_secret_key_iv"
@ -36,8 +35,8 @@ ActiveRecord::Schema.define(version: 202202071123100) do
create_table "case_logs", force: :cascade do |t|
t.integer "status", default: 0
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "tenant_code"
t.integer "age1"
t.string "sex1"
@ -191,6 +190,7 @@ ActiveRecord::Schema.define(version: 202202071123100) do
t.decimal "tshortfall", precision: 10, scale: 2
t.decimal "chcharge", precision: 10, scale: 2
t.integer "declaration"
t.integer "providertype"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
end
@ -206,8 +206,8 @@ ActiveRecord::Schema.define(version: 202202071123100) do
t.boolean "holds_own_stock"
t.string "other_stock_owners"
t.string "managing_agents"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "active"
t.integer "old_association_type"
t.string "software_supplier_id"
@ -233,8 +233,8 @@ ActiveRecord::Schema.define(version: 202202071123100) do
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.bigint "organisation_id"
t.integer "sign_in_count", default: 0, null: false
@ -256,7 +256,7 @@ ActiveRecord::Schema.define(version: 202202071123100) do
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.datetime "created_at", precision: 6
t.datetime "created_at"
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end

2
spec/fixtures/exports/case_logs.xml vendored

@ -158,6 +158,7 @@
<tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge>
<declaration>Yes</declaration>
<providertype/>
</form>
<form>
<id>{id_2}</id>
@ -317,5 +318,6 @@
<tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge>
<declaration>Yes</declaration>
<providertype/>
</form>
</forms>

8
spec/models/case_log_spec.rb

@ -1177,6 +1177,14 @@ RSpec.describe CaseLog do
expect(case_log["homeless"]).to eq("No")
end
end
it "correctly derives and saves providertype from organisation" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select providertype from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["providertype"]).to eq(2)
expect(case_log.providertype).to eq("PRP")
end
end
describe "resetting invalidated fields" do

Loading…
Cancel
Save