Merge pull request #13804 from rioug/13802-revert-enbling-variant-tag-no-inventory

[Inventory] display inventory link for user who manage enterprises with inventory and enterprises without inventory
This commit is contained in:
Ahmed Ejaz
2025-12-13 01:13:34 +05:00
committed by GitHub
7 changed files with 11 additions and 14 deletions

View File

@@ -44,6 +44,8 @@ module Admin
def load_data
@hubs = OpenFoodNetwork::Permissions.new(spree_current_user).
variant_override_hubs.by_name
# Only display the ones with inventory enabled
@hubs = @hubs.select { |p| helpers.feature?(:inventory, p) }
# Used in JS to look up the name of the producer of each product
@producers = OpenFoodNetwork::Permissions.new(spree_current_user).

View File

@@ -185,16 +185,11 @@ module ProductImport
order('is_primary_producer ASC, name').
map { |e| @editable_enterprises[e.name] = e.id }
return unless inventory_enabled?
return unless OpenFoodNetwork::FeatureToggle.enabled?(:inventory, *@current_user.enterprises)
@inventory_permissions = permissions.variant_override_enterprises_per_hub
end
def inventory_enabled?
!OpenFoodNetwork::FeatureToggle.enabled?(:variant_tag, *@current_user.enterprises) &&
OpenFoodNetwork::FeatureToggle.enabled?(:inventory, *@current_user.enterprises)
end
def open_spreadsheet
if accepted_mimetype
Roo::Spreadsheet.open(@file, extension: accepted_mimetype, encoding: Encoding::UTF_8)

View File

@@ -5,7 +5,7 @@
%h6= t('admin.product_import.index.choose_import_type')
%br
- options = { "#{t('admin.product_import.index.product_list')}" => :product_list }
- options = options.merge("#{t('admin.product_import.index.inventories')}" => :inventories) if inventory_enabled?(spree_current_user.enterprises)
- options = options.merge("#{t('admin.product_import.index.inventories')}" => :inventories) if feature?(:inventory, *spree_current_user.enterprises)
= select_tag "settings[import_into]",
options_for_select(options),
{ "data-controller": "tom-select", class: "primary inline no-search", "ng-model": "settings.import_into" }

View File

@@ -5,7 +5,7 @@
%i.icon-external-link
= t('admin.product_import.index.product_list_template')
- if inventory_enabled?(spree_current_user.enterprises)
- if feature?(:inventory, *spree_current_user.enterprises)
%a.download{href: '/inventory_template.csv'}
%i.icon-external-link
= t('admin.product_import.index.inventory_template')

View File

@@ -81,7 +81,7 @@
= error_message_on variant, :tax_category
- if variant_tag_enabled?(spree_current_user)
%td.col-tags.field.naked_inputs
= render TagListInputComponent.new(name: f.field_name(:tag_list), tags: variant.tag_list, autocomplete_url: variant_tag_rules_admin_tag_rules_path(enterprise_id: variant.supplier_id), placeholder: t('.add_a_tag'), aria_label: t('admin.products_page.columns.tags'))
= render TagListInputComponent.new(name: f.field_name(:tag_list), tags: variant.tag_list, autocomplete_url: variant_tag_rules_admin_tag_rules_path(enterprise_id: variant.supplier_id), placeholder: t('.add_a_tag'), aria_label: t('admin.products_page.columns.tags')) if feature?(:variant_tag, variant.supplier)
%td.col-inherits_properties.align-left
-# empty
%td.align-right

View File

@@ -2,5 +2,5 @@
%ul#sub_nav.inline-menu
= tab :products, :products_v3, url: admin_products_path
= tab :properties
= tab :variant_overrides, url: main_app.admin_inventory_path, match_path: '/inventory' if inventory_enabled?(spree_current_user.enterprises)
= tab :variant_overrides, url: main_app.admin_inventory_path, match_path: '/inventory' if feature?(:inventory, *spree_current_user.enterprises)
= tab :import, url: main_app.admin_product_import_path, match_path: '/product_import'

View File

@@ -44,7 +44,7 @@ Flipper.register(:enterprise_with_no_inventory) do |actor|
# This group applies to enterprises only, so we return false if the actor is not an Enterprise
next false unless actor.actor.instance_of? Enterprise
# Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created
# Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created
# after never had access to the inventory
enterprise_with_variant_override = Enterprise
.where(id: VariantOverride.joins(:hub).select(:hub_id))
@@ -60,17 +60,17 @@ Flipper.register(:enterprise_with_inventory) do |actor|
# This group applies to enterprises only, so we return false if the actor is not an Enterprise
next false unless actor.actor.instance_of? Enterprise
# Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created
# Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created
# after never had access to the inventory
enterprise_with_variant_override = Enterprise
.where(id: VariantOverride.joins(:hub).select(:hub_id))
.where(created_at: ..."2025-08-11")
.distinct
enterprise_with_variant_override.exists?(actor.id)
# Entperprise with inventory and with variant tag not manually enabled.
enterprise_with_variant_override.exists?(actor.id) && !Flipper.enabled?(:variant_tag, actor)
end
Flipper::UI.configure do |config|
config.descriptions_source = ->(_keys) do
# return has to be hash of {String key => String description}