diff --git a/app/assets/javascripts/repositories/renderers/view_renderers.js b/app/assets/javascripts/repositories/renderers/view_renderers.js index 6696cec90..4c8d84f43 100644 --- a/app/assets/javascripts/repositories/renderers/view_renderers.js +++ b/app/assets/javascripts/repositories/renderers/view_renderers.js @@ -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 `${data.value.consumed_stock_formatted}`; + } if (!data.stock_present) { return ' - '; } diff --git a/app/helpers/repository_datatable_helper.rb b/app/helpers/repository_datatable_helper.rb index 44db5ec20..dec43cd3d 100644 --- a/app/helpers/repository_datatable_helper.rb +++ b/app/helpers/repository_datatable_helper.rb @@ -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