Merge pull request #7853 from artoscinote/ma_SCI_11050

Import fixes [SCI-11050]
This commit is contained in:
Martin Artnik 2024-09-16 10:12:12 +02:00 committed by GitHub
commit bf1c446cc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 11 deletions

View file

@ -133,7 +133,7 @@ class StorageLocationsController < ApplicationController
def import_container
result = StorageLocations::ImportService.new(@storage_location, params[:file], current_user).import_items
if result[:status] == :ok
if (result[:assigned_count] + result[:unassigned_count] + result[:updated_count]).positive?
if (result[:assigned_count] + result[:unassigned_count]).positive?
log_activity(
:storage_location_imported,
{

View file

@ -28,9 +28,9 @@ class StorageLocationRepositoryRow < ApplicationRecord
end
def ensure_uniq_position
if StorageLocationRepositoryRow.where(storage_location: storage_location)
.where('metadata @> ?', { position: metadata['position'] }.to_json)
.where.not(id: id).exists?
if storage_location.storage_location_repository_rows
.where("metadata->'position' = ?", metadata['position'].to_json)
.where.not(id: id).exists?
errors.add(:base, I18n.t('activerecord.errors.models.storage_location.not_uniq_position'))
end
end

View file

@ -8,7 +8,6 @@ module StorageLocations
@storage_location = storage_location
@assigned_count = 0
@unassigned_count = 0
@updated_count = 0
@sheet = SpreadsheetParser.open_spreadsheet(file)
@user = user
end
@ -73,12 +72,10 @@ module StorageLocations
metadata: { position: row[:position] }
)
@assigned_count += 1 if storage_location_repository_row.new_record?
storage_location_repository_row.update!(
repository_row_id: row[:repository_row_id],
created_by: storage_location_repository_row.created_by || @user
)
if storage_location_repository_row.new_record?
@assigned_count += 1
storage_location_repository_row.update!(created_by: @user)
end
end
def unassign_repository_rows!