From e026f2b1356f49cf4f42ad7df9188b3b33184be0 Mon Sep 17 00:00:00 2001 From: ajugo Date: Thu, 15 Feb 2024 13:00:09 +0100 Subject: [PATCH] Add check for showing consumption column [SCI-10185] (#7085) --- app/models/my_module.rb | 14 ++++++++----- app/models/repository_base.rb | 4 ++++ .../repositories/_full_view_sidebar.html.erb | 2 +- .../_full_view_snapshot_table.html.erb | 20 ++++++++++--------- .../repositories/_repositories_list.html.erb | 8 ++++---- .../my_modules/_repositories_list.html.erb | 4 ++-- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/app/models/my_module.rb b/app/models/my_module.rb index d6f8e1b28..266582b12 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -338,7 +338,7 @@ class MyModule < ApplicationRecord ] data = [] rows = repository.assigned_rows(self).includes(:created_by).order(created_at: order) - if repository.has_stock_management? + if repository.has_stock_management? && repository.has_stock_consumption? headers.push(I18n.t('repositories.table.row_consumption')) rows = rows.left_joins(my_module_repository_rows: :repository_stock_unit_item) .select( @@ -352,7 +352,7 @@ class MyModule < ApplicationRecord row_json << (row.archived ? "#{row.name} [#{I18n.t('general.archived')}]" : row.name) row_json << I18n.l(row.created_at, format: :full) row_json << row.created_by.full_name - if repository.has_stock_management? + if repository.has_stock_management? && repository.has_stock_consumption? if repository.is_a?(RepositorySnapshot) consumed_stock = row.repository_stock_consumption_cell&.value&.formatted row_json << (consumed_stock || 0) @@ -378,11 +378,15 @@ class MyModule < ApplicationRecord repository.repository_columns.order(:id).each do |column| if column.data_type == 'RepositoryStockValue' - headers.push(I18n.t('repositories.table.row_consumption')) - else + if repository.has_stock_consumption? + headers.push(I18n.t('repositories.table.row_consumption')) + custom_columns.push(column.id) + end + elsif column.data_type != 'RepositoryStockConsumptionValue' && + !(repository.is_a?(RepositorySnapshot) && column.data_type == 'RepositoryStockConsumptionValue') headers.push(column.name) + custom_columns.push(column.id) end - custom_columns.push(column.id) end records = repository.assigned_rows(self) diff --git a/app/models/repository_base.rb b/app/models/repository_base.rb index e260c1bc8..dab25f492 100644 --- a/app/models/repository_base.rb +++ b/app/models/repository_base.rb @@ -43,6 +43,10 @@ class RepositoryBase < ApplicationRecord self.class.stock_management_enabled? && repository_columns.stock_type.exists? end + def has_stock_consumption? + true + end + def cell_preload_includes cell_includes = [] repository_columns.pluck(:data_type).each do |data_type| diff --git a/app/views/my_modules/repositories/_full_view_sidebar.html.erb b/app/views/my_modules/repositories/_full_view_sidebar.html.erb index da91bb695..a5d85b56c 100644 --- a/app/views/my_modules/repositories/_full_view_sidebar.html.erb +++ b/app/views/my_modules/repositories/_full_view_sidebar.html.erb @@ -10,7 +10,7 @@

<%= t('my_modules.repository.snapshots.full_view.live') %> diff --git a/app/views/my_modules/repositories/_full_view_snapshot_table.html.erb b/app/views/my_modules/repositories/_full_view_snapshot_table.html.erb index d18650e48..c60472cfd 100644 --- a/app/views/my_modules/repositories/_full_view_snapshot_table.html.erb +++ b/app/views/my_modules/repositories/_full_view_snapshot_table.html.erb @@ -19,15 +19,17 @@ <%= t("repositories.table.added_on") %> <%= t("repositories.table.added_by") %> <% @repository_snapshot.repository_columns.order(:parent_id).each do |column| %> - - <%= "data-metadata-#{k}=#{v}" %> - <% end %> - > - <%= display_tooltip(column.name) %> - + <% if column.data_type != 'RepositoryStockConsumptionValue' || @repository_snapshot.has_stock_consumption? %> + + <%= "data-metadata-#{k}=#{v}" %> + <% end %> + > + <%= display_tooltip(column.name) %> + + <% end %> <% end %> diff --git a/app/views/my_modules/repositories/_repositories_list.html.erb b/app/views/my_modules/repositories/_repositories_list.html.erb index 1c66ee542..cb6d3c203 100644 --- a/app/views/my_modules/repositories/_repositories_list.html.erb +++ b/app/views/my_modules/repositories/_repositories_list.html.erb @@ -16,7 +16,7 @@ <% end %>
-
@@ -28,12 +28,12 @@ data-name-column-id="<%= assigned_repository_simple_view_name_column_id(repository) %>" > + data-stock-management="<%= repository.has_stock_management? && repository.has_stock_consumption? %>" + data-stock-consumption-editable="<%= can_update_my_module_stock_consumption?(@my_module) && repository.has_stock_consumption? %>"> - <% if repository.has_stock_management? %> + <% if repository.has_stock_management? && repository.has_stock_consumption? %> <% end %> diff --git a/app/views/shareable_links/my_modules/_repositories_list.html.erb b/app/views/shareable_links/my_modules/_repositories_list.html.erb index 4cd4d89cc..8a87b23cc 100644 --- a/app/views/shareable_links/my_modules/_repositories_list.html.erb +++ b/app/views/shareable_links/my_modules/_repositories_list.html.erb @@ -25,12 +25,12 @@ data-name-column-id="<%= assigned_repository_simple_view_name_column_id(repository) %>" > - <% if repository.has_stock_management? %> + <% if repository.has_stock_management? && repository.has_stock_consumption? %> <% end %>
<%= t("repositories.table.row_name") %><%= repository.repository_stock_column.name %> <%= t("repositories.table.row_consumption") %>