diff --git a/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee b/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee index 965692c86d..79764ecc30 100644 --- a/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee +++ b/app/assets/javascripts/admin/product_import/controllers/import_options_form.js.coffee @@ -2,37 +2,24 @@ angular.module("admin.productImport").controller "ImportOptionsFormCtrl", ($scop $scope.initForm = () -> $scope.settings = {} if $scope.settings == undefined - $scope.settings[$scope.supplierId] = { - import_into: 'product_list' - defaults: - count_on_hand: - mode: 'overwrite_all' - on_hand: - mode: 'overwrite_all' - tax_category_id: - mode: 'overwrite_all' - shipping_category_id: - mode: 'overwrite_all' - available_on: - mode: 'overwrite_all' + $scope.settings = { + import_into: 'product_list', + reset_all_absent: false } $scope.import_into = 'product_list' - $scope.updateImportInto = () -> - $scope.import_into = $scope.settings[$scope.supplierId]['import_into'] - $scope.$watch 'settings', (updated) -> ProductImportService.updateSettings(updated) , true - $scope.toggleResetAbsent = (id) -> - checked = $scope.settings[id]['reset_all_absent'] + $scope.toggleResetAbsent = -> + checked = $scope.settings['reset_all_absent'] confirmed = confirm t('js.product_import.confirmation') if checked if confirmed or !checked ProductImportService.updateResetAbsent($scope.supplierId, $scope.reset_counts[$scope.supplierId], checked) else - $scope.settings[id]['reset_all_absent'] = false + $scope.settings['reset_all_absent'] = false $scope.resetTotal = ProductImportService.resetTotal diff --git a/app/models/product_import/entry_processor.rb b/app/models/product_import/entry_processor.rb index 509a21fd43..23d0b88ddf 100644 --- a/app/models/product_import/entry_processor.rb +++ b/app/models/product_import/entry_processor.rb @@ -109,7 +109,7 @@ module ProductImport end def import_into_inventory?(entry) - entry.supplier_id && @import_settings[:settings][entry.supplier_id.to_s]['import_into'] == 'inventories' + entry.supplier_id && @import_settings[:settings]['import_into'] == 'inventories' end def save_new_inventory_item(entry) @@ -228,7 +228,7 @@ module ProductImport end def import_into_inventory_by_supplier?(supplier_id) - @import_settings[:settings] && @import_settings[:settings][supplier_id.to_s] && @import_settings[:settings][supplier_id.to_s]['import_into'] == 'inventories' + @import_settings[:settings] && @import_settings[:settings][supplier_id.to_s] && @import_settings[:settings]['import_into'] == 'inventories' end end end diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 8ffb2edf2c..d3632911ad 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -221,7 +221,7 @@ module ProductImport end def import_into_inventory?(entry) - entry.supplier_id && @import_settings[:settings][entry.supplier_id.to_s]['import_into'] == 'inventories' + entry.supplier_id && @import_settings[:settings]['import_into'] == 'inventories' end def validate_inventory_item(entry, variant_override) diff --git a/app/views/admin/product_import/_import_options.html.haml b/app/views/admin/product_import/_import_options.html.haml index 3c79357e46..c03f16237a 100644 --- a/app/views/admin/product_import/_import_options.html.haml +++ b/app/views/admin/product_import/_import_options.html.haml @@ -3,38 +3,31 @@ - @importer.suppliers_index.each do |name, supplier_id| - if name and supplier_id and @importer.permission_by_id?(supplier_id) - %div.panel-section.import-settings{ng: {controller: 'DropdownPanelsCtrl'}} + %div.panel-section.import-settings %div.panel-header{ng: {click: 'togglePanel()', class: '{active: active}'}} - %div.header-caret - %i{ng: {class: "{'icon-chevron-down': active, 'icon-chevron-right': !active}"}} - %div.header-icon.neutral - %i.fa.fa-edit + %div.header-icon.success + %i.fa.fa-check-circle %div.header-description = name - %div.panel-content{ng: {hide: '!active'}} - = render 'options_form', supplier_id: supplier_id, name: name - elsif name and supplier_id - %div.panel-section.import-settings{ng: {controller: 'DropdownPanelsCtrl'}} + %div.panel-section.import-settings %div.panel-header - %div.header-caret %div.header-icon.error %i.fa.fa-warning %div.header-description = name %span.header-error= " - #{t('admin.product_import.import.no_permission')}" - elsif name - %div.panel-section.import-settings{ng: {controller: 'DropdownPanelsCtrl'}} + %div.panel-section.import-settings %div.panel-header - %div.header-caret %div.header-icon.error %i.fa.fa-warning %div.header-description = name %span.header-error= " - #{t('admin.product_import.import.not_found')}" - else - %div.panel-section.import-settings{ng: {controller: 'DropdownPanelsCtrl'}} + %div.panel-section.import-settings %div.panel-header - %div.header-caret %div.header-icon.error %i.fa.fa-warning %div.header-description diff --git a/app/views/admin/product_import/_upload_form.html.haml b/app/views/admin/product_import/_upload_form.html.haml index 008f027139..00aa4a6cd4 100644 --- a/app/views/admin/product_import/_upload_form.html.haml +++ b/app/views/admin/product_import/_upload_form.html.haml @@ -1,11 +1,30 @@ -%div{ng: {app: 'admin.productImport'}} +%div{ng: {app: 'admin.productImport', controller: 'ImportOptionsFormCtrl', init: "initForm()"}} - %h5= t('admin.product_import.index.select_file') - %br = form_tag main_app.admin_product_import_path, multipart: true, class: 'product-import' do - %label #{t('admin.product_import.index.spreadsheet')} + + %h6= t('admin.product_import.index.choose_import_type') + %br + = select_tag "import_into", options_for_select({"#{t('admin.product_import.index.product_list')}" => :product_list, "#{t('admin.product_import.index.inventories')}" => :inventories}), {class: 'select2 select2-no-search', 'ng-model' => 'settings.import_into'} + %br + %br + %br + + %h6= t('admin.product_import.index.select_file') %br = file_field_tag :file %br %br + %br + + %h6= t('admin.product_import.import.reset_absent?') + %br + = hidden_field_tag "settings[reset_all_absent]", 0 + = check_box_tag "settings[reset_all_absent]", 1, false, 'ng-model' => 'settings.reset_all_absent' + %span= t('admin.product_import.import.reset_absent_tip') + %br + %br + %br + = submit_tag "#{t('admin.product_import.index.upload')}" + %br + %br diff --git a/config/locales/en.yml b/config/locales/en.yml index 870ff898d1..c3f51fd2f5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -466,7 +466,8 @@ en: index: select_file: Select a spreadsheet to upload spreadsheet: Spreadsheet - import_into: "Import into:" + choose_import_type: Select import type + import_into: Import type product_list: Product list inventories: Inventories import: Import @@ -496,7 +497,8 @@ en: not_found: enterprise could not be found in database no_name: No name blank_supplier: some products have blank supplier name - reset_absent?: Reset absent products? + 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 overwrite_empty: Overwrite if empty default_stock: Set stock level diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 73c7423cc3..aeaf1c2eae 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -44,7 +44,7 @@ describe ProductImport::ProductImporter do end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') - settings = {enterprise.id.to_s => {'import_into' => 'product_list'}} + settings = {'import_into' => 'product_list'} @importer = ProductImport::ProductImporter.new(file, admin, start: 1, end: 100, settings: settings) end after { File.delete('/tmp/test-m.csv') } @@ -131,7 +131,7 @@ describe ProductImport::ProductImporter do end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') - settings = {enterprise.id.to_s => {'import_into' => 'product_list'}} + settings = {'import_into' => 'product_list'} @importer = ProductImport::ProductImporter.new(file, admin, start: 1, end: 100, settings: settings) end after { File.delete('/tmp/test-m.csv') }