|
|
|
@ -3,6 +3,7 @@ class BulkUpload::Lettings::RowParser
|
|
|
|
|
include ActiveModel::Attributes |
|
|
|
|
|
|
|
|
|
attribute :bulk_upload |
|
|
|
|
attribute :block_log_creation, :boolean, default: -> { false } |
|
|
|
|
|
|
|
|
|
attribute :field_1, :integer |
|
|
|
|
attribute :field_2 |
|
|
|
@ -114,9 +115,9 @@ class BulkUpload::Lettings::RowParser
|
|
|
|
|
attribute :field_108, :string |
|
|
|
|
attribute :field_109, :string |
|
|
|
|
attribute :field_110 |
|
|
|
|
attribute :field_111, :integer |
|
|
|
|
attribute :field_111, :string |
|
|
|
|
attribute :field_112, :string |
|
|
|
|
attribute :field_113, :integer |
|
|
|
|
attribute :field_113, :string |
|
|
|
|
attribute :field_114, :integer |
|
|
|
|
attribute :field_115 |
|
|
|
|
attribute :field_116, :integer |
|
|
|
@ -155,6 +156,13 @@ class BulkUpload::Lettings::RowParser
|
|
|
|
|
validate :validate_dont_know_disabled_needs_conjunction |
|
|
|
|
validate :validate_no_and_dont_know_disabled_needs_conjunction |
|
|
|
|
|
|
|
|
|
validate :validate_owning_org_permitted |
|
|
|
|
validate :validate_owning_org_owns_stock |
|
|
|
|
validate :validate_owning_org_exists |
|
|
|
|
|
|
|
|
|
validate :validate_managing_org_related |
|
|
|
|
validate :validate_managing_org_exists |
|
|
|
|
|
|
|
|
|
def valid? |
|
|
|
|
errors.clear |
|
|
|
|
|
|
|
|
@ -173,15 +181,60 @@ class BulkUpload::Lettings::RowParser
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def blank_row? |
|
|
|
|
attribute_set.to_hash.reject { |k, _| %w[bulk_upload].include?(k) }.values.compact.empty? |
|
|
|
|
attribute_set.to_hash.reject { |k, _| %w[bulk_upload block_log_creation].include?(k) }.values.compact.empty? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def log |
|
|
|
|
@log ||= LettingsLog.new(attributes_for_log) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def block_log_creation! |
|
|
|
|
self.block_log_creation = true |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def block_log_creation? |
|
|
|
|
block_log_creation |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
def validate_managing_org_related |
|
|
|
|
if owning_organisation && managing_organisation && !owning_organisation.can_be_managed_by?(organisation: managing_organisation) |
|
|
|
|
block_log_creation! |
|
|
|
|
errors.add(:field_113, "This managing organisation does not have a relationship with the owning organisation") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def validate_managing_org_exists |
|
|
|
|
if managing_organisation.nil? |
|
|
|
|
errors.delete(:field_113) |
|
|
|
|
errors.add(:field_113, "The managing organisation code is incorrect") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def validate_owning_org_owns_stock |
|
|
|
|
if owning_organisation && !owning_organisation.holds_own_stock? |
|
|
|
|
block_log_creation! |
|
|
|
|
errors.delete(:field_111) |
|
|
|
|
errors.add(:field_111, "The owning organisation code provided is for an organisation that does not own stock") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def validate_owning_org_exists |
|
|
|
|
if owning_organisation.nil? |
|
|
|
|
errors.delete(:field_111) |
|
|
|
|
errors.add(:field_111, "The owning organisation code is incorrect") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def validate_owning_org_permitted |
|
|
|
|
if owning_organisation && !bulk_upload.user.organisation.affiliated_stock_owners.include?(owning_organisation) |
|
|
|
|
block_log_creation! |
|
|
|
|
errors.delete(:field_111) |
|
|
|
|
errors.add(:field_111, "You do not have permission to add logs for this owning organisation") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def validate_no_and_dont_know_disabled_needs_conjunction |
|
|
|
|
if field_59 == 1 && field_60 == 1 |
|
|
|
|
errors.add(:field_59, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) |
|
|
|
@ -483,15 +536,19 @@ private
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def owning_organisation |
|
|
|
|
Organisation.find_by(old_visible_id: field_111) |
|
|
|
|
Organisation.find_by_id_on_mulitple_fields(field_111) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def owning_organisation_id |
|
|
|
|
owning_organisation&.id |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def managing_organisation |
|
|
|
|
Organisation.find_by_id_on_mulitple_fields(field_113) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def managing_organisation_id |
|
|
|
|
Organisation.find_by(old_visible_id: field_113)&.id |
|
|
|
|
managing_organisation&.id |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def attributes_for_log |
|
|
|
|