Browse Source
* feat: wip behaviour * feat: hide in cya * feat: show in cya * feat: purchase price range service and rake task * feat: fix hodate validation and use purchase price ranges * db:update * feat: more saledate -> exdate fixing * feat: add min and max conditional text * refactor: linting * refactor: remove duplicated behaviour * refactor: linting * feat: update tests * test: add validation tests * test: add purchase price rangeimport service tests * refactor: linting * feat: allow translation text and title text to display currency formatting even when not a log field * feat: use i18n * feat: update i18n * refactor: pratical -> practical * refactor: linting * refactor: revert unnecessary change * feat: respond to PR comments * tests: update after merge * feat: improve currency interruption screen display * feat: update docs * feat: fix typo * feat: missing end after merge * feat: respond to PR comments * feat: add soft validation to beds and la pages * db:update * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: PO comment responses * tests: update * refactor: linting * refactor: simplification * refactor: railsification * test: fix * refactor: use number_to_currency units * refactor: remove duplicated copy * db:updatepull/1272/head
natdeanlewissoftwire
2 years ago
committed by
GitHub
27 changed files with 1666 additions and 15 deletions
@ -0,0 +1,42 @@
|
||||
class Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@depends_on = [ |
||||
{ |
||||
"purchase_price_out_of_soft_range?" => true, |
||||
}, |
||||
] |
||||
@title_text = { |
||||
"translation" => "soft_validations.purchase_price.title_text", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "value", |
||||
"label" => true, |
||||
"i18n_template" => "value", |
||||
}, |
||||
], |
||||
} |
||||
@informative_text = { |
||||
"translation" => "soft_validations.purchase_price.hint_text", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "purchase_price_soft_min_or_soft_max", |
||||
"label" => false, |
||||
"i18n_template" => "soft_min_or_soft_max", |
||||
"currency" => true, |
||||
}, |
||||
{ |
||||
"key" => "purchase_price_min_or_max_text", |
||||
"label" => false, |
||||
"i18n_template" => "min_or_max", |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,23 @@
|
||||
class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "value_value_check" |
||||
@check_answer_label = "Purchase price confirmation" |
||||
@header = "Are you sure?" |
||||
@type = "interruption_screen" |
||||
@answer_options = { |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"value_value_check" => 0, |
||||
}, |
||||
{ |
||||
"value_value_check" => 1, |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
end |
@ -0,0 +1,2 @@
|
||||
class LaSaleRange < ApplicationRecord |
||||
end |
@ -0,0 +1,27 @@
|
||||
require "csv" |
||||
|
||||
module Imports |
||||
class SaleRangesService |
||||
attr_reader :start_year, :path, :count |
||||
|
||||
def initialize(start_year:, path:) |
||||
@start_year = start_year |
||||
@path = path |
||||
@count = 0 |
||||
end |
||||
|
||||
def call |
||||
CSV.foreach(path, headers: true) do |row| |
||||
LaSaleRange.upsert( |
||||
{ start_year:, |
||||
la: row["la"], |
||||
bedrooms: row["bedrooms"], |
||||
soft_min: row["soft_min"], |
||||
soft_max: row["soft_max"] }, |
||||
unique_by: %i[start_year bedrooms la], |
||||
) |
||||
@count += 1 |
||||
end |
||||
end |
||||
end |
||||
end |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,5 @@
|
||||
class AddAboutPriceSharedOwnershipValueCheckToSalesLog < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :sales_logs, :value_value_check, :integer |
||||
end |
||||
end |
@ -0,0 +1,14 @@
|
||||
class CreateLaSaleRanges < ActiveRecord::Migration[7.0] |
||||
def change |
||||
create_table :la_sale_ranges do |t| |
||||
t.string :la |
||||
t.integer :bedrooms |
||||
t.decimal :soft_min, precision: 10, scale: 2 |
||||
t.decimal :soft_max, precision: 10, scale: 2 |
||||
t.integer :start_year |
||||
|
||||
t.index %i[start_year bedrooms la], unique: true, name: "index_la_sale_ranges_on_start_year_bedrooms_la" |
||||
t.timestamps |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,14 @@
|
||||
namespace :data_import do |
||||
desc "Import annual sale range data" |
||||
task :sale_ranges, %i[start_year path] => :environment do |_task, args| |
||||
start_year = args[:start_year] |
||||
path = args[:path] |
||||
|
||||
raise "Usage: rake data_import:sale_ranges[start_year,'path/to/csv_file']" if path.blank? || start_year.blank? |
||||
|
||||
service = Imports::SaleRangesService.new(start_year:, path:) |
||||
service.call |
||||
|
||||
pp "Created/updated #{service.count} LA Sale Range records for #{start_year}" unless Rails.env.test? |
||||
end |
||||
end |
|
@ -0,0 +1,47 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "data_import" do |
||||
describe ":sale_ranges", type: :task do |
||||
subject(:task) { Rake::Task["data_import:sale_ranges"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/sale_ranges") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
context "when the rake task is run" do |
||||
let(:start_year) { 2022 } |
||||
let(:sale_ranges_file_path) { "./spec/fixtures/files/sale_ranges.csv" } |
||||
let(:wrong_file_path) { "/test/no_csv_here.csv" } |
||||
|
||||
it "creates new rent range records" do |
||||
expect { task.invoke(start_year, sale_ranges_file_path) }.to change(LaSaleRange, :count).by(4) |
||||
expect(LaSaleRange.where(bedrooms: 1).exists?).to be true |
||||
end |
||||
|
||||
it "raises an error when no path is given" do |
||||
expect { task.invoke(start_year, nil) }.to raise_error(RuntimeError, "Usage: rake data_import:sale_ranges[start_year,'path/to/csv_file']") |
||||
end |
||||
|
||||
it "raises an error when no file exists at the given path" do |
||||
expect { task.invoke(start_year, wrong_file_path) }.to raise_error(Errno::ENOENT) |
||||
end |
||||
|
||||
it "asks for a start year if it is not given" do |
||||
expect { task.invoke(nil, sale_ranges_file_path) }.to raise_error(RuntimeError, "Usage: rake data_import:sale_ranges[start_year,'path/to/csv_file']") |
||||
end |
||||
|
||||
context "when a record already exists with a matching index of la, bedrooms and start year" do |
||||
let!(:sale_range) { LaSaleRange.create(la: "E07000223", bedrooms: 2, soft_min: 177_000, soft_max: 384_000, start_year: 2022) } |
||||
|
||||
it "updates rent ranges if the record is matched on la, bedrooms and start year" do |
||||
task.invoke(start_year, sale_ranges_file_path) |
||||
sale_range.reload |
||||
expect(sale_range.soft_max).to eq(384_000) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue