|
|
|
@ -549,6 +549,22 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
expect(record_from_db["deposit"]).to eq(123_400) |
|
|
|
expect(record_from_db["deposit"]).to eq(123_400) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "clears deposit for outright sales when mortgage is changed from yes to unknown" do |
|
|
|
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: 5000, saledate: Time.zone.local(2024, 5, 2), mortgageused: 1, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(mortgageused: 3) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "clears deposit for outright sales when mortgage is changed from no to unknown" do |
|
|
|
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: 5000, saledate: Time.zone.local(2024, 5, 2), mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(mortgageused: 3) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does not derive deposit if the sale isn't outright" do |
|
|
|
it "does not derive deposit if the sale isn't outright" do |
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 2) |
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 2) |
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
@ -561,6 +577,50 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "clears deposit when setting mortgage used to yes from no for outright sales" do |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(mortgageused: 1) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not clear deposit when setting mortgage used to yes from no for outright sales with new deposit value" do |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(mortgageused: 1, deposit: 1000) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(1000) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "clears deposit when changing from outright sale with no mortgage to shared ownership" do |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(ownershipsch: 1) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "clears deposit when changing from outright sale with no mortgage to discounted ownership" do |
|
|
|
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(ownershipsch: 2) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(nil) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not clear deposit when changing from outright sale with no mortgage to shared ownership with new deposit value" do |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(ownershipsch: 1, deposit: 1000) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(1000) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not clear when changing from outright sale with no mortgage to discounted ownership with new deposit value" do |
|
|
|
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
sales_log.update!(ownershipsch: 2, deposit: 1000) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["deposit"]).to eq(1000) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "correctly derives and saves pcode1 and pcode1 and pcode2" do |
|
|
|
it "correctly derives and saves pcode1 and pcode1 and pcode2" do |
|
|
|
sales_log.update!(postcode_full: "W6 0SP") |
|
|
|
sales_log.update!(postcode_full: "W6 0SP") |
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
@ -576,6 +636,13 @@ RSpec.describe SalesLog, type: :model do |
|
|
|
expect(record_from_db["mortgage"]).to eq(0.0) |
|
|
|
expect(record_from_db["mortgage"]).to eq(0.0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "derives a mortgage value of 0 when mortgage is unknown" do |
|
|
|
|
|
|
|
Timecop.freeze(2024, 5, 2) |
|
|
|
|
|
|
|
sales_log.update!(value: 123_400, saledate: Time.zone.local(2024, 5, 2), mortgageused: 3, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1) |
|
|
|
|
|
|
|
record_from_db = described_class.find(sales_log.id) |
|
|
|
|
|
|
|
expect(record_from_db["mortgage"]).to eq(0.0) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "clears mortgage value if mortgage used is changed from no to yes" do |
|
|
|
it "clears mortgage value if mortgage used is changed from no to yes" do |
|
|
|
# to avoid log failing validations when mortgage value is removed: |
|
|
|
# to avoid log failing validations when mortgage value is removed: |
|
|
|
new_grant_value = sales_log.grant + sales_log.mortgage |
|
|
|
new_grant_value = sales_log.grant + sales_log.mortgage |
|
|
|
|