mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 09:23:58 +08:00
Merge pull request #7713 from artoscinote/ma_SCI_10889
Fix handling of blank rows and stock changes [SCI-10889]
This commit is contained in:
commit
83394b7e9e
2 changed files with 15 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue