Update logic for saving update at and modified by on repository row [SCI-10746]

This commit is contained in:
Andrej 2024-05-29 17:18:00 +02:00
parent 7d2f6238de
commit 3f58f9e624
14 changed files with 30 additions and 11 deletions

View file

@ -47,6 +47,7 @@ module Api
end
def destroy
@inventory_item.update!(last_modified_by: current_user)
@inventory_cell.destroy!
render body: nil
end

View file

@ -35,7 +35,7 @@ class Asset < ApplicationRecord
has_one :result_asset, inverse_of: :asset, dependent: :destroy
has_one :result, through: :result_asset, touch: true
has_one :repository_asset_value, inverse_of: :asset, dependent: :destroy
has_one :repository_cell, through: :repository_asset_value
has_one :repository_cell, through: :repository_asset_value, touch: true
has_many :report_elements, inverse_of: :asset, dependent: :destroy
has_one :asset_text_datum, inverse_of: :asset, dependent: :destroy
has_many :asset_sync_tokens, dependent: :destroy

View file

@ -12,7 +12,7 @@ class RepositoryAssetValue < ApplicationRecord
belongs_to :asset,
inverse_of: :repository_asset_value,
dependent: :destroy
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value, touch: true
accepts_nested_attributes_for :repository_cell
validates :asset, :repository_cell, presence: true

View file

@ -5,7 +5,7 @@ class RepositoryCell < ApplicationRecord
attr_accessor :importing
belongs_to :repository_row
belongs_to :repository_row, touch: true
belongs_to :repository_column
belongs_to :value, polymorphic: true, inverse_of: :repository_cell, dependent: :destroy
@ -45,10 +45,16 @@ class RepositoryCell < ApplicationRecord
uniqueness: { scope: :repository_column },
unless: :importing
after_touch :update_repository_row_last_modified_by
scope :with_active_reminder, lambda { |user|
reminder_repository_cells_scope(self, user)
}
def update_repository_row_last_modified_by
repository_row.update!(last_modified_by_id: value.last_modified_by_id)
end
def self.create_with_value!(row, column, data, user)
cell = new(repository_row: row, repository_column: column)
cell.transaction do

View file

@ -5,4 +5,15 @@ class RepositoryChecklistItemsValue < ApplicationRecord
belongs_to :repository_checklist_value, inverse_of: :repository_checklist_items_values
validates :repository_checklist_item, :repository_checklist_value, presence: true
after_create :touch_repository_checklist_value
before_destroy :touch_repository_checklist_value
private
# rubocop:disable Rails/SkipsModelValidations
def touch_repository_checklist_value
repository_checklist_value.touch
end
# rubocop:enable Rails/SkipsModelValidations
end

View file

@ -7,7 +7,7 @@ class RepositoryChecklistValue < ApplicationRecord
inverse_of: :created_repository_checklist_values
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User',
inverse_of: :modified_repository_checklist_values
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value, touch: true
has_many :repository_checklist_items_values, dependent: :destroy
has_many :repository_checklist_items, -> { order('data ASC') },
through: :repository_checklist_items_values,

View file

@ -7,7 +7,7 @@ class RepositoryDateTimeRangeValueBase < ApplicationRecord
inverse_of: :created_repository_date_time_values
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User', optional: true,
inverse_of: :modified_repository_date_time_values
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value, touch: true
accepts_nested_attributes_for :repository_cell
validates :repository_cell, :start_time, :end_time, :type, presence: true

View file

@ -7,7 +7,7 @@ class RepositoryDateTimeValueBase < ApplicationRecord
inverse_of: :created_repository_date_time_values
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User', optional: true,
inverse_of: :modified_repository_date_time_values
has_one :repository_cell, as: :value, dependent: :destroy
has_one :repository_cell, as: :value, dependent: :destroy, touch: true
accepts_nested_attributes_for :repository_cell
before_save :reset_notification_sent, if: -> { data_changed? }

View file

@ -8,7 +8,7 @@ class RepositoryListValue < ApplicationRecord
belongs_to :last_modified_by,
foreign_key: :last_modified_by_id,
class_name: 'User'
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value, touch: true
accepts_nested_attributes_for :repository_cell
validates :repository_cell, presence: true

View file

@ -5,7 +5,7 @@ class RepositoryNumberValue < ApplicationRecord
inverse_of: :created_repository_number_values
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User',
inverse_of: :modified_repository_number_values
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value, touch: true
accepts_nested_attributes_for :repository_cell
validates :repository_cell, :data, presence: true

View file

@ -6,7 +6,7 @@ class RepositoryStatusValue < ApplicationRecord
inverse_of: :created_repository_status_value
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true,
inverse_of: :modified_repository_status_value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value, touch: true
accepts_nested_attributes_for :repository_cell
validates :repository_cell, :repository_status_item, presence: true

View file

@ -9,7 +9,7 @@ class RepositoryStockValue < ApplicationRecord
belongs_to :repository_stock_unit_item, optional: true
belongs_to :created_by, class_name: 'User', optional: true, inverse_of: :created_repository_stock_values
belongs_to :last_modified_by, class_name: 'User', optional: true, inverse_of: :modified_repository_stock_values
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value, touch: true
has_one :repository_row, through: :repository_cell
has_many :repository_ledger_records, dependent: :destroy
accepts_nested_attributes_for :repository_cell

View file

@ -7,7 +7,7 @@ class RepositoryTextValue < ApplicationRecord
belongs_to :last_modified_by, foreign_key: :last_modified_by_id,
class_name: 'User',
inverse_of: :modified_repository_text_values
has_one :repository_cell, as: :value, dependent: :destroy
has_one :repository_cell, as: :value, dependent: :destroy, touch: true
accepts_nested_attributes_for :repository_cell
validates :repository_cell, presence: true

View file

@ -26,6 +26,7 @@ module RepositoryRows
@cell = @repository_row.repository_cells.find_by(repository_column_id: @column.id)
if @cell.present? && value.blank?
@repository_row.last_modified_by = @user
@cell.destroy!
@cell = nil
@record_updated = true