Fix snapshot consumption display [SCI-6734] (#4035)

This commit is contained in:
artoscinote 2022-04-20 11:07:26 +02:00 committed by GitHub
parent e3cbf5903a
commit 4daf01feee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -230,6 +230,10 @@ $.fn.dataTable.render.defaultRepositoryStockValue = function() {
};
$.fn.dataTable.render.RepositoryStockConsumptionValue = function(data = {}) {
// covers case of snapshots
if (!data.stock_present && data.value && data.value.consumed_stock_formatted) {
return `<span class="empty-consumed-stock-render">${data.value.consumed_stock_formatted}</span>`;
}
if (!data.stock_present) {
return '<span class="empty-consumed-stock-render"> - </span>';
}

View file

@ -60,7 +60,7 @@ module RepositoryDatatableHelper
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, team, repository) : {}
row['stock'][:stock_managable] = stock_managable
if !options[:include_stock_consumption] || can_update_my_module_stock_consumption?(options[:my_module])
if !options[:include_stock_consumption] || stock_consumption_permitted?(repository, options[:my_module])
row['stock'][:stock_status] = record.repository_stock_cell&.value&.status
end
@ -70,7 +70,7 @@ module RepositoryDatatableHelper
consumption_managable = stock_consumption_managable?(record, repository, options[:my_module])
row['consumedStock'] = {
stock_present: stock_present,
consumptionPermitted: can_update_my_module_stock_consumption?(options[:my_module]),
consumptionPermitted: stock_consumption_permitted?(repository, options[:my_module]),
consumptionManagable: consumption_managable,
updateStockConsumptionUrl: Rails.application.routes.url_helpers.consume_modal_my_module_repository_path(
options[:my_module],
@ -116,7 +116,7 @@ module RepositoryDatatableHelper
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, record.repository.team, repository) : {}
if !options[:include_stock_consumption] || can_update_my_module_stock_consumption?(my_module)
if !options[:include_stock_consumption] || stock_consumption_permitted?(repository, my_module)
row['stock'][:stock_status] = record.repository_stock_cell&.value&.status
end
@ -144,7 +144,7 @@ module RepositoryDatatableHelper
end
row['consumedStock']['stock_present'] = stock_present
row['consumedStock']['consumptionPermitted'] = can_update_my_module_stock_consumption?(my_module)
row['consumedStock']['consumptionPermitted'] = stock_consumption_permitted?(repository, my_module)
row['consumedStock']['consumptionManagable'] = consumption_managable
end
@ -265,9 +265,14 @@ module RepositoryDatatableHelper
repository_rows.active.with_active_reminders(current_user).to_a.pluck(:id).uniq
end
def stock_consumption_permitted?(repository, my_module)
return false unless repository.is_a?(Repository)
can_update_my_module_stock_consumption?(my_module)
end
def stock_consumption_managable?(record, repository, my_module)
return false unless my_module
return false unless record.repository.is_a?(Repository)
return false if repository.archived? || record.archived?
true