diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index 60888e3b9..9c7d0e1ed 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/app/services/bulk_upload/lettings/row_parser.rb @@ -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 @@ -176,17 +177,26 @@ 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_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 @@ -201,6 +211,7 @@ private 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 diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index a93abeef0..b8c18923b 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/row_parser_spec.rb @@ -479,6 +479,10 @@ RSpec.describe BulkUpload::Lettings::RowParser do it "is not permitted" do expect(parser.errors[:field_111]).to eql(["The owning organisation code provided is for an organisation that does not own stock"]) end + + it "blocks log creation" do + expect(parser).to be_block_log_creation + end end context "when not affiliated with owning org" do @@ -489,6 +493,10 @@ RSpec.describe BulkUpload::Lettings::RowParser do it "is not permitted" do expect(parser.errors[:field_111]).to eql(["You do not have permission to add logs for this owning organisation"]) end + + it "blocks log creation" do + expect(parser).to be_block_log_creation + end end end