diff --git a/app/models/repository_stock_value.rb b/app/models/repository_stock_value.rb index 02a87c974..0e26c0bc1 100644 --- a/app/models/repository_stock_value.rb +++ b/app/models/repository_stock_value.rb @@ -118,14 +118,18 @@ class RepositoryStockValue < ApplicationRecord new_amount = new_data[:amount].to_d delta = new_amount - amount.to_d self.comment = new_data[:comment].presence - repository_ledger_records.create!( - user: last_modified_by, - amount: delta, - balance: new_amount, - reference: repository_cell.repository_column.repository, - comment: comment, - unit: repository_stock_unit_item&.data - ) + + unless preview + repository_ledger_records.create!( + user: last_modified_by, + amount: delta, + balance: new_amount, + reference: repository_cell.repository_column.repository, + comment: comment, + unit: repository_stock_unit_item&.data + ) + end + self.amount = new_amount preview ? validate : save! end diff --git a/app/utilities/repository_import_parser/importer.rb b/app/utilities/repository_import_parser/importer.rb index 79dcf7fb7..5c511a8a9 100644 --- a/app/utilities/repository_import_parser/importer.rb +++ b/app/utilities/repository_import_parser/importer.rb @@ -20,7 +20,7 @@ module RepositoryImportParser @header_skipped = false @repository = repository @sheet = sheet - @rows = SpreadsheetParser.spreadsheet_enumerator(@sheet).compact_blank + @rows = SpreadsheetParser.spreadsheet_enumerator(@sheet).reject { |r| r.all?(&:blank?) } @mappings = mappings @user = user @repository_columns = @repository.repository_columns @@ -188,9 +188,10 @@ module RepositoryImportParser handle_existing_cell_value(existing_cell, cell_value, repository_row) end - @updated ||= existing_cell&.value&.changed? + @updated ||= @preview ? existing_cell&.value&.changed? : existing_cell&.value&.saved_changes? @errors << existing_cell.value.errors.full_messages.join(',') if existing_cell&.value&.errors.present? end + repository_row.import_status = if @errors.present? 'invalid' elsif repository_row.import_status == 'created'