mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
PI reset and save step improvements
This commit is contained in:
committed by
Rob Harrington
parent
648753b412
commit
91fc3f33a0
@@ -1,7 +1,13 @@
|
||||
angular.module("ofn.admin").controller "ImportOptionsFormCtrl", ($scope, $timeout, $rootScope, ProductImportService) ->
|
||||
|
||||
$scope.toggleResetAbsent = () ->
|
||||
ProductImportService.updateResetAbsent($scope.supplierId, $scope.nonUpdated, $scope.resetAbsent)
|
||||
confirmed = confirm 'This will set stock level to zero on all products for this \n' +
|
||||
'enterprise that are not present in the uploaded file.' if $scope.resetAbsent
|
||||
|
||||
if confirmed or !$scope.resetAbsent
|
||||
ProductImportService.updateResetAbsent($scope.supplierId, $scope.nonUpdated, $scope.resetAbsent)
|
||||
else
|
||||
$scope.resetAbsent = false
|
||||
|
||||
$scope.resetCount = ProductImportService.resetCount
|
||||
|
||||
|
||||
@@ -172,15 +172,16 @@ table.import-settings {
|
||||
margin-bottom: 0.5em;
|
||||
|
||||
strong {
|
||||
margin-left: 0.5em;
|
||||
margin-right: 0.2em;
|
||||
min-width: 1.8em;
|
||||
display: inline-block;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 1.4em;
|
||||
vertical-align: middle;
|
||||
position: relative;
|
||||
//margin-bottom: -0.8em;
|
||||
}
|
||||
|
||||
i.fa-check-circle {
|
||||
|
||||
@@ -110,6 +110,10 @@ class ProductImporter
|
||||
@variants_updated
|
||||
end
|
||||
|
||||
def products_reset_count
|
||||
@products_reset_count || 0
|
||||
end
|
||||
|
||||
def total_saved_count
|
||||
@products_created + @variants_created + @variants_updated
|
||||
end
|
||||
@@ -177,7 +181,12 @@ class ProductImporter
|
||||
AND spree_variants.deleted_at IS NULL', supplier_id).
|
||||
count
|
||||
|
||||
@supplier_products[:by_supplier][supplier_id] = {existing_products: products_count}
|
||||
if @supplier_products[:by_supplier][supplier_id]
|
||||
@supplier_products[:by_supplier][supplier_id][:existing_products] = products_count
|
||||
else
|
||||
@supplier_products[:by_supplier][supplier_id] = {existing_products: products_count}
|
||||
end
|
||||
|
||||
@supplier_products[:total] += products_count
|
||||
end
|
||||
end
|
||||
@@ -340,11 +349,13 @@ class ProductImporter
|
||||
end
|
||||
|
||||
unless enterprises_to_reset.empty? or @updated_ids.empty?
|
||||
# Set stock to zero for all products in selected enterprises that were not
|
||||
# present in the uploaded spreadsheet.
|
||||
Spree::Variant.joins(:product).
|
||||
# For selected enterprises; set stock to zero for all products
|
||||
# that were not present in the uploaded spreadsheet
|
||||
@products_reset_count = Spree::Variant.joins(:product).
|
||||
where('spree_products.supplier_id IN (?)
|
||||
AND spree_variants.id NOT IN (?)', enterprises_to_reset, @updated_ids).
|
||||
AND spree_variants.id NOT IN (?)
|
||||
AND spree_variants.is_master = false
|
||||
AND spree_variants.deleted_at IS NULL', enterprises_to_reset, @updated_ids).
|
||||
update_all(count_on_hand: 0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
%strong.updated-count= @importer.products_updated_count
|
||||
Products updated
|
||||
|
||||
- if @importer.products_reset_count > 0
|
||||
%p
|
||||
%i.fa.fa-check-circle
|
||||
%strong.reset-count= @importer.products_reset_count
|
||||
Products had stock level reset to zero
|
||||
|
||||
%br
|
||||
|
||||
- if @importer.errors.count == 0
|
||||
|
||||
@@ -16,9 +16,10 @@ feature "Product Import", js: true do
|
||||
let!(:shipping_category) { create(:shipping_category) }
|
||||
let!(:product) { create(:simple_product, supplier: enterprise2, name: 'Hypothetical Cake') }
|
||||
let!(:variant) { create(:variant, product_id: product.id, price: '8.50', on_hand: '100', unit_value: '500', display_name: 'Preexisting Banana') }
|
||||
let!(:product2) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Beans') }
|
||||
let!(:product2) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Beans', unit_value: '500') }
|
||||
let!(:product3) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Sprouts') }
|
||||
let!(:product4) { create(:simple_product, supplier: enterprise2, on_hand: '100', name: 'Lettuce') }
|
||||
let!(:product4) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Cabbage') }
|
||||
let!(:product5) { create(:simple_product, supplier: enterprise2, on_hand: '100', name: 'Lettuce') }
|
||||
|
||||
|
||||
describe "when importing products from uploaded file" do
|
||||
@@ -251,7 +252,7 @@ feature "Product Import", js: true do
|
||||
csv_data = CSV.generate do |csv|
|
||||
csv << ["name", "supplier", "category", "on_hand", "price", "unit_value", "variant_unit", "variant_unit_scale"]
|
||||
csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "weight", "1"]
|
||||
csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "1000", "weight", "1000"]
|
||||
csv << ["Beans", "User Enterprise", "Vegetables", "6", "6.50", "500", "weight", "1"]
|
||||
end
|
||||
File.write('/tmp/test.csv', csv_data)
|
||||
|
||||
@@ -260,6 +261,13 @@ feature "Product Import", js: true do
|
||||
attach_file 'file', '/tmp/test.csv'
|
||||
click_button 'Import'
|
||||
|
||||
expect(page).to have_selector '.item-count', text: "2"
|
||||
expect(page).to have_selector '.invalid-count', text: "0"
|
||||
expect(page).to have_selector '.create-count', text: "1"
|
||||
expect(page).to have_selector '.update-count', text: "1"
|
||||
|
||||
expect(page).to_not have_selector '.reset-count'
|
||||
|
||||
within 'div.import-settings' do
|
||||
find('div.header-description').click # Import settings tab
|
||||
check "settings_#{enterprise.id}_reset_all_absent"
|
||||
@@ -269,13 +277,14 @@ feature "Product Import", js: true do
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_selector '.created-count', text: '2'
|
||||
expect(page).to have_selector '.updated-count', text: '0'
|
||||
expect(page).to have_selector '.created-count', text: '1'
|
||||
expect(page).to have_selector '.updated-count', text: '1'
|
||||
expect(page).to have_selector '.reset-count', text: '2'
|
||||
|
||||
Spree::Product.find_by_name('Carrots').on_hand.should == 5 # Present in file
|
||||
Spree::Product.find_by_name('Potatoes').on_hand.should == 6 # Present in file
|
||||
Spree::Product.find_by_name('Beans').on_hand.should == 0 # In enterprise, not in file
|
||||
Spree::Product.find_by_name('Carrots').on_hand.should == 5 # Present in file, added
|
||||
Spree::Product.find_by_name('Beans').on_hand.should == 6 # Present in file, updated
|
||||
Spree::Product.find_by_name('Sprouts').on_hand.should == 0 # In enterprise, not in file
|
||||
Spree::Product.find_by_name('Cabbage').on_hand.should == 0 # In enterprise, not in file
|
||||
Spree::Product.find_by_name('Lettuce').on_hand.should == 100 # In different enterprise; unchanged
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user