Merge pull request #7713 from artoscinote/ma_SCI_10889

Fix handling of blank rows and stock changes [SCI-10889]
This commit is contained in:
Martin Artnik 2024-07-15 14:41:10 +02:00 committed by GitHub
commit 83394b7e9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 10 deletions

View file

@ -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

View file

@ -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'