Rename supplier to enterprise

This commit is contained in:
Matt-Yorkley
2018-10-02 12:25:57 +01:00
parent 8a0a33deec
commit e7a909e828
13 changed files with 84 additions and 84 deletions

View File

@@ -3,7 +3,7 @@ angular.module("admin.productImport").controller "ImportFormCtrl", ($scope, $htt
$scope.entries = {}
$scope.update_counts = {}
$scope.reset_counts = {}
$scope.supplier_product_counts = ams_data.supplier_product_counts
$scope.enterprise_product_counts = ams_data.enterprise_product_counts
$scope.updates = {}
$scope.updated_total = 0
@@ -19,7 +19,7 @@ angular.module("admin.productImport").controller "ImportFormCtrl", ($scope, $htt
}
$scope.countResettable = () ->
angular.forEach $scope.supplier_product_counts, (value, key) ->
angular.forEach $scope.enterprise_product_counts, (value, key) ->
$scope.reset_counts[key] = value
if $scope.update_counts[key]
$scope.reset_counts[key] -= $scope.update_counts[key]

View File

@@ -17,7 +17,7 @@ angular.module("admin.productImport").controller "ImportOptionsFormCtrl", ($scop
confirmed = confirm t('js.product_import.confirmation') if checked
if confirmed or !checked
ProductImportService.updateResetAbsent($scope.supplierId, $scope.reset_counts[$scope.supplierId], checked)
ProductImportService.updateResetAbsent($scope.enterpriseId, $scope.reset_counts[$scope.enterpriseId], checked)
else
$scope.settings['reset_all_absent'] = false

View File

@@ -18,15 +18,15 @@ angular.module("admin.productImport").filter 'entriesFilterValid', ->
filtered
angular.module("admin.productImport").filter 'entriesFilterSupplier', ->
(entries, supplier) ->
if supplier == 'all'
angular.module("admin.productImport").filter 'entriesFilterEnterprise', ->
(entries, enterprise) ->
if enterprise == 'all'
return entries
filtered = {}
angular.forEach entries, (entry, line_number) ->
if supplier == entry.attributes['supplier']
if enterprise == entry.attributes['enterprise']
filtered[line_number] = entry
filtered

View File

@@ -1,15 +1,15 @@
angular.module("admin.productImport").factory "ProductImportService", ($rootScope) ->
new class ProductImportService
suppliers: {}
enterprises: {}
resetTotal: 0
settings: {}
updateResetAbsent: (supplierId, resetCount, resetAbsent) ->
updateResetAbsent: (enterpriseId, resetCount, resetAbsent) ->
if resetAbsent
@suppliers[supplierId] = resetCount
@enterprises[enterpriseId] = resetCount
@resetTotal += resetCount
else
@suppliers[supplierId] = null
@enterprises[enterpriseId] = null
@resetTotal -= resetCount
$rootScope.resetTotal = @resetTotal

View File

@@ -90,7 +90,7 @@ module Admin
{
filepath: @filepath,
item_count: @importer.item_count,
supplier_product_counts: @importer.supplier_products,
enterprise_product_counts: @importer.enterprise_products,
import_url: main_app.admin_product_import_process_async_path,
save_url: main_app.admin_product_import_save_async_path,
reset_url: main_app.admin_product_import_reset_async_path,

View File

@@ -5,8 +5,8 @@
module ProductImport
class EntryProcessor
attr_reader :inventory_created, :inventory_updated, :products_created,
:variants_created, :variants_updated, :supplier_products,
:total_supplier_products, :products_reset_count
:variants_created, :variants_updated, :enterprise_products,
:total_enterprise_products, :products_reset_count
def initialize(importer, validator, import_settings, spreadsheet_data, editable_enterprises, import_time, updated_ids)
@importer = importer
@@ -23,8 +23,8 @@ module ProductImport
@variants_created = 0
@variants_updated = 0
@products_reset_count = 0
@supplier_products = {}
@total_supplier_products = 0
@enterprise_products = {}
@total_enterprise_products = 0
end
def save_all(entries)
@@ -40,24 +40,24 @@ module ProductImport
end
def count_existing_items
@spreadsheet_data.suppliers_index.each do |_supplier_name, attrs|
supplier_id = attrs[:id]
next unless supplier_id && permission_by_id?(supplier_id)
@spreadsheet_data.enterprises_index.each do |_enterprise_name, attrs|
enterprise_id = attrs[:id]
next unless enterprise_id && permission_by_id?(enterprise_id)
products_count =
if settings.importing_into_inventory?
VariantOverride.where('variant_overrides.hub_id IN (?)', supplier_id).count
VariantOverride.where('variant_overrides.hub_id IN (?)', enterprise_id).count
else
Spree::Variant.
not_deleted.
not_master.
joins(:product).
where('spree_products.supplier_id IN (?)', supplier_id).
where('spree_products.supplier_id IN (?)', enterprise_id).
count
end
@supplier_products[supplier_id] = products_count
@total_supplier_products += products_count
@enterprise_products[enterprise_id] = products_count
@total_enterprise_products += products_count
end
end
@@ -88,8 +88,8 @@ module ProductImport
@products_created + @variants_created + @variants_updated + @inventory_created + @inventory_updated
end
def permission_by_id?(supplier_id)
@editable_enterprises.value?(Integer(supplier_id))
def permission_by_id?(enterprise_id)
@editable_enterprises.value?(Integer(enterprise_id))
end
private
@@ -122,7 +122,7 @@ module ProductImport
end
def import_into_inventory?(entry)
entry.supplier_id && settings.importing_into_inventory?
entry.enterprise_id && settings.importing_into_inventory?
end
def save_new_inventory_item(entry)
@@ -158,8 +158,8 @@ module ProductImport
# If we've already added a new product with these attributes
# from this spreadsheet, mark this entry as a new variant with
# the new product id, as this is a now variant of that product...
if @already_created[entry.supplier_id] && @already_created[entry.supplier_id][entry.name]
product_id = @already_created[entry.supplier_id][entry.name]
if @already_created[entry.enterprise_id] && @already_created[entry.enterprise_id][entry.name]
product_id = @already_created[entry.enterprise_id][entry.name]
@validator.mark_as_new_variant(entry, product_id)
return
end
@@ -176,7 +176,7 @@ module ProductImport
@importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", product.errors.full_messages)
end
@already_created[entry.supplier_id] = { entry.name => product.id }
@already_created[entry.enterprise_id] = { entry.name => product.id }
end
def save_variant(entry)

View File

@@ -27,10 +27,10 @@ module ProductImport
def validate_all(entries)
entries.each do |entry|
supplier_validation(entry)
enterprise_validation(entry)
unit_fields_validation(entry)
next if entry.supplier_id.blank?
next if entry.enterprise_id.blank?
if import_into_inventory?
producer_validation(entry)
@@ -59,37 +59,37 @@ module ProductImport
private
def supplier_validation(entry)
def enterprise_validation(entry)
return if name_presence_error entry
return if enterprise_not_found_error entry
return if permissions_error entry
return if primary_producer_error entry
entry.supplier_id = @spreadsheet_data.suppliers_index[entry.supplier][:id]
entry.enterprise_id = @spreadsheet_data.enterprises_index[entry.enterprise][:id]
end
def name_presence_error(entry)
return if entry.supplier.present?
mark_as_invalid(entry, attribute: "supplier", error: I18n.t(:error_required))
return if entry.enterprise.present?
mark_as_invalid(entry, attribute: "enterprise", error: I18n.t(:error_required))
true
end
def enterprise_not_found_error(entry)
return if @spreadsheet_data.suppliers_index[entry.supplier][:id]
mark_as_invalid(entry, attribute: "supplier", error: I18n.t(:error_not_found_in_database, name: entry.supplier))
return if @spreadsheet_data.enterprises_index[entry.enterprise][:id]
mark_as_invalid(entry, attribute: "enterprise", error: I18n.t(:error_not_found_in_database, name: entry.enterprise))
true
end
def permissions_error(entry)
return if permission_by_name?(entry.supplier)
mark_as_invalid(entry, attribute: "supplier", error: I18n.t(:error_no_permission_for_enterprise, name: entry.supplier))
return if permission_by_name?(entry.enterprise)
mark_as_invalid(entry, attribute: "enterprise", error: I18n.t(:error_no_permission_for_enterprise, name: entry.enterprise))
true
end
def primary_producer_error(entry)
return if import_into_inventory?
return if @spreadsheet_data.suppliers_index[entry.supplier][:is_primary_producer]
mark_as_invalid(entry, attribute: "supplier", error: I18n.t(:error_not_primary_producer, name: entry.supplier))
return if @spreadsheet_data.enterprises_index[entry.enterprise][:is_primary_producer]
mark_as_invalid(entry, attribute: "enterprise", error: I18n.t(:error_not_primary_producer, name: entry.enterprise))
true
end
@@ -126,7 +126,7 @@ module ProductImport
return
end
unless inventory_permission?(entry.supplier_id, @spreadsheet_data.producers_index[producer_name])
unless inventory_permission?(entry.enterprise_id, @spreadsheet_data.producers_index[producer_name])
mark_as_invalid(entry, attribute: "producer", error: "\"#{producer_name}\": #{I18n.t('admin.product_import.model.inventory_no_permission')}")
return
end
@@ -186,7 +186,7 @@ module ProductImport
end
def product_validation(entry)
products = Spree::Product.where(supplier_id: entry.supplier_id, name: entry.name, deleted_at: nil)
products = Spree::Product.where(supplier_id: entry.enterprise_id, name: entry.name, deleted_at: nil)
if products.empty?
mark_as_new_product(entry)
@@ -222,7 +222,7 @@ module ProductImport
if existing_variant.valid?
entry.product_object = existing_variant
entry.validates_as = 'existing_variant' unless entry.errors?
updates_count_per_supplier(entry.supplier_id) unless entry.errors?
updates_count_per_enterprise(entry.enterprise_id) unless entry.errors?
else
mark_as_invalid(entry, product_validations: existing_variant.errors)
end
@@ -243,16 +243,16 @@ module ProductImport
existing_product.public_send(attribute).blank? && entry.public_send(attribute).blank?
end
def permission_by_name?(supplier_name)
@editable_enterprises.key?(supplier_name)
def permission_by_name?(enterprise_name)
@editable_enterprises.key?(enterprise_name)
end
def permission_by_id?(supplier_id)
@editable_enterprises.value?(Integer(supplier_id))
def permission_by_id?(enterprise_id)
@editable_enterprises.value?(Integer(enterprise_id))
end
def inventory_permission?(supplier_id, producer_id)
@current_user.admin? || ( @inventory_permissions[supplier_id] && @inventory_permissions[supplier_id].include?(producer_id) )
def inventory_permission?(enterprise_id, producer_id)
@current_user.admin? || ( @inventory_permissions[enterprise_id] && @inventory_permissions[enterprise_id].include?(producer_id) )
end
def mark_as_invalid(entry, options = {})
@@ -273,9 +273,9 @@ module ProductImport
end
def create_inventory_item(entry, existing_variant)
existing_variant_override = VariantOverride.where(variant_id: existing_variant.id, hub_id: entry.supplier_id).first
existing_variant_override = VariantOverride.where(variant_id: existing_variant.id, hub_id: entry.enterprise_id).first
variant_override = existing_variant_override || VariantOverride.new(variant_id: existing_variant.id, hub_id: entry.supplier_id)
variant_override = existing_variant_override || VariantOverride.new(variant_id: existing_variant.id, hub_id: entry.enterprise_id)
variant_override.assign_attributes(count_on_hand: entry.on_hand, import_date: @import_time)
check_on_hand_nil(entry, variant_override)
variant_override.assign_attributes(entry.attributes.slice('price', 'on_demand'))
@@ -287,18 +287,18 @@ module ProductImport
if variant_override.id
entry.validates_as = 'existing_inventory_item'
entry.product_object = variant_override
updates_count_per_supplier(entry.supplier_id) unless entry.errors?
updates_count_per_enterprise(entry.enterprise_id) unless entry.errors?
else
entry.validates_as = 'new_inventory_item'
entry.product_object = variant_override
end
end
def updates_count_per_supplier(supplier_id)
if @reset_counts[supplier_id] && @reset_counts[supplier_id][:updates_count]
@reset_counts[supplier_id][:updates_count] += 1
def updates_count_per_enterprise(enterprise_id)
if @reset_counts[enterprise_id] && @reset_counts[enterprise_id][:updates_count]
@reset_counts[enterprise_id][:updates_count] += 1
else
@reset_counts[supplier_id] = { updates_count: 1 }
@reset_counts[enterprise_id] = { updates_count: 1 }
end
end

View File

@@ -65,27 +65,27 @@ module ProductImport
end
def reset_counts
# Return indexed data about existing product count, reset count, and updates count per supplier
@reset_counts.each do |supplier_id, values|
# Return indexed data about existing product count, reset count, and updates count per enterprise
@reset_counts.each do |enterprise_id, values|
values[:updates_count] = 0 if values[:updates_count].blank?
if values[:updates_count] && values[:existing_products]
@reset_counts[supplier_id][:reset_count] = values[:existing_products] - values[:updates_count]
@reset_counts[enterprise_id][:reset_count] = values[:existing_products] - values[:updates_count]
end
end
@reset_counts
end
def suppliers_index
@spreadsheet_data.suppliers_index
def enterprises_index
@spreadsheet_data.enterprises_index
end
def supplier_products
@processor.andand.supplier_products
def enterprise_products
@processor.andand.enterprise_products
end
def total_supplier_products
@processor.total_supplier_products
def total_enterprise_products
@processor.total_enterprise_products
end
def all_entries
@@ -165,8 +165,8 @@ module ProductImport
@processor.reset_absent_items
end
def permission_by_id?(supplier_id)
@editable_enterprises.value?(Integer(supplier_id))
def permission_by_id?(enterprise_id)
@editable_enterprises.value?(Integer(enterprise_id))
end
private

View File

@@ -6,8 +6,8 @@ module ProductImport
def defaults(entry)
@import_settings.key?(:settings) &&
settings[entry.supplier_id.to_s] &&
settings[entry.supplier_id.to_s]['defaults']
settings[entry.enterprise_id.to_s] &&
settings[entry.enterprise_id.to_s]['defaults']
end
def settings

View File

@@ -11,8 +11,8 @@ module ProductImport
@entries = entries
end
def suppliers_index
@suppliers_index || create_suppliers_index
def enterprises_index
@enterprises_index || create_enterprises_index
end
def producers_index
@@ -33,15 +33,15 @@ module ProductImport
private
def create_suppliers_index
@suppliers_index = {}
def create_enterprises_index
@enterprises_index = {}
@entries.each do |entry|
supplier_name = entry.supplier
next if @suppliers_index.key? supplier_name
enterprise = Enterprise.find_by_name(supplier_name, select: 'id, name, is_primary_producer')
@suppliers_index[supplier_name] = { id: enterprise.try(:id), is_primary_producer: enterprise.try(:is_primary_producer) }
enterprise_name = entry.enterprise
next if @enterprises_index.key? enterprise_name
enterprise = Enterprise.find_by_name(enterprise_name, select: 'id, name, is_primary_producer')
@enterprises_index[enterprise_name] = { id: enterprise.try(:id), is_primary_producer: enterprise.try(:is_primary_producer) }
end
@suppliers_index
@enterprises_index
end
def create_producers_index

View File

@@ -11,7 +11,7 @@ module ProductImport
attr_accessor :line_number, :valid, :validates_as, :product_object, :product_validations, :on_hand_nil,
:has_overrides, :units, :unscaled_units, :unit_type, :tax_category, :shipping_category
attr_accessor :id, :product_id, :producer, :producer_id, :supplier, :supplier_id, :name, :display_name, :sku,
attr_accessor :id, :product_id, :producer, :producer_id, :enterprise, :enterprise_id, :name, :display_name, :sku,
:unit_value, :unit_description, :variant_unit, :variant_unit_scale, :variant_unit_name,
:display_as, :category, :primary_taxon_id, :price, :on_hand, :count_on_hand, :on_demand,
:tax_category_id, :shipping_category_id, :description, :import_date
@@ -77,7 +77,7 @@ module ProductImport
end
def non_display_attributes
['id', 'product_id', 'unscaled_units', 'variant_id', 'supplier_id', 'primary_taxon', 'primary_taxon_id', 'category_id', 'shipping_category_id', 'tax_category_id', 'variant_unit_scale', 'variant_unit', 'unit_value']
['id', 'product_id', 'unscaled_units', 'variant_id', 'enterprise_id', 'primary_taxon', 'primary_taxon_id', 'category_id', 'shipping_category_id', 'tax_category_id', 'variant_unit_scale', 'variant_unit', 'unit_value']
end
def non_product_attributes

View File

@@ -1,7 +1,7 @@
%h5= t('admin.product_import.import.options_and_defaults')
%br
- @importer.suppliers_index.each do |name, attrs|
- @importer.enterprises_index.each do |name, attrs|
- if name and attrs[:id] and @importer.permission_by_id?(attrs[:id])
%div.panel-section.import-settings
%div.panel-header{ng: {click: 'togglePanel()', class: '{active: active}'}}
@@ -32,7 +32,7 @@
%i.fa.fa-warning
%div.header-description
= t('admin.product_import.import.no_name')
%span.header-error= " - #{t('admin.product_import.import.blank_supplier')}"
%span.header-error= " - #{t('admin.product_import.import.blank_enterprise')}"
%br.panels.clearfix
%br

View File

@@ -554,7 +554,7 @@ en:
no_permission: you do not have permission to manage this enterprise
not_found: enterprise could not be found in database
no_name: No name
blank_supplier: some products have blank supplier name
blank_enterprise: some products do not have an enterprise defined
reset_absent?: Reset absent products
reset_absent_tip: Set stock to zero for all exiting products not present in the file
overwrite_all: Overwrite all