Add check for showing consumption column [SCI-10185] (#7085)

This commit is contained in:
ajugo 2024-02-15 13:00:09 +01:00 committed by GitHub
parent b14912e70e
commit e026f2b135
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 21 deletions

View file

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

View file

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

View file

@ -10,7 +10,7 @@
<a href="#" id="selectLiveVersionButton" class="list-group-item live-version-item version-button"
data-id="<%= @repository.id %>"
data-selected="<%= @repository_snapshots.select{ |s| s.selected == true }.blank? %>"
data-table-url="<%= full_view_table_my_module_repository_path(@my_module, @repository, include_stock_consumption: true) %>"
data-table-url="<%= full_view_table_my_module_repository_path(@my_module, @repository, include_stock_consumption: @repository.has_stock_consumption?) %>"
>
<h2 class="list-group-item-heading">
<%= t('my_modules.repository.snapshots.full_view.live') %>

View file

@ -19,15 +19,17 @@
<th id="added-on"><%= t("repositories.table.added_on") %></th>
<th id="added-by"><%= t("repositories.table.added_by") %></th>
<% @repository_snapshot.repository_columns.order(:parent_id).each do |column| %>
<th class="repository-column"
id="<%= column.id %>"
data-type="<%= column.data_type %>"
<% column.metadata.each do |k, v| %>
<%= "data-metadata-#{k}=#{v}" %>
<% end %>
>
<%= display_tooltip(column.name) %>
</th>
<% if column.data_type != 'RepositoryStockConsumptionValue' || @repository_snapshot.has_stock_consumption? %>
<th class="repository-column"
id="<%= column.id %>"
data-type="<%= column.data_type %>"
<% column.metadata.each do |k, v| %>
<%= "data-metadata-#{k}=#{v}" %>
<% end %>
>
<%= display_tooltip(column.name) %>
</th>
<% end %>
<% end %>
</tr>
</thead>

View file

@ -16,7 +16,7 @@
</span>
<% end %>
<div class="action-buttons">
<button class="btn btn-light icon-btn full-screen" data-table-url="<%= assigned_repository_full_view_table_path(@my_module, repository) %>?include_stock_consumption=true">
<button class="btn btn-light icon-btn full-screen" data-table-url="<%= assigned_repository_full_view_table_path(@my_module, repository) %><%= '?include_stock_consumption=true' if repository.has_stock_consumption? %>">
<i class="sn-icon sn-icon-expand"></i>
</button>
</div>
@ -28,12 +28,12 @@
data-name-column-id="<%= assigned_repository_simple_view_name_column_id(repository) %>"
>
<table class="table hidden repository-table repository-dataTable"
data-stock-management="<%= repository.has_stock_management? %>"
data-stock-consumption-editable="<%= can_update_my_module_stock_consumption?(@my_module) %>">
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? %>">
<thead>
<tr>
<th class="row-name"><%= t("repositories.table.row_name") %></th>
<% if repository.has_stock_management? %>
<% if repository.has_stock_management? && repository.has_stock_consumption? %>
<th class="row-stock" data-columns-visible="false"><%= repository.repository_stock_column.name %></th>
<th class="row-consumption" data-columns-visible="false"><%= t("repositories.table.row_consumption") %></th>
<% end %>

View file

@ -25,12 +25,12 @@
data-name-column-id="<%= assigned_repository_simple_view_name_column_id(repository) %>"
>
<table class="table repository-table"
data-stock-management="<%= repository.has_stock_management? %>"
data-stock-management="<%= repository.has_stock_management? && repository.has_stock_consumption? %>"
data-stock-consumption-editable="false">
<thead>
<tr>
<th class="row-name"><%= t("repositories.table.row_name") %></th>
<% if repository.has_stock_management? %>
<% if repository.has_stock_management? && repository.has_stock_consumption? %>
<th class="row-stock" data-columns-visible="false"><%= repository.repository_stock_column.name %></th>
<th class="row-consumption" data-columns-visible="false"><%= t("repositories.table.row_consumption") %></th>
<% end %>