Compare commits

..

1 commit

Author SHA1 Message Date
126015ca67 fix rubocop and add translations 2023-02-20 21:44:57 +01:00
5 changed files with 17 additions and 42 deletions

View file

@ -142,6 +142,9 @@ class Article < ApplicationRecord
new_unit_quantity = new_article.unit_quantity new_unit_quantity = new_article.unit_quantity
new_unit = new_article.unit new_unit = new_article.unit
end end
if options[:update_category] == true
new_article_category = new_article.article_category
end
attribute_hash = { attribute_hash = {
:name => [self.name, new_article.name], :name => [self.name, new_article.name],
@ -155,10 +158,7 @@ class Article < ApplicationRecord
:unit_quantity => [self.unit_quantity.to_s.to_f, new_unit_quantity.to_s.to_f], :unit_quantity => [self.unit_quantity.to_s.to_f, new_unit_quantity.to_s.to_f],
:note => [self.note.to_s, new_article.note.to_s] :note => [self.note.to_s, new_article.note.to_s]
} }
if options[:update_category] == true attribute_hash[:article_category] = [self.article_category, new_article_category] if new_article_category
new_article_category = new_article.article_category
attribute_hash[:article_category] = [self.article_category, new_article_category] unless new_article_category.blank?
end
Article.compare_attributes(attribute_hash) Article.compare_attributes(attribute_hash)
end end

View file

@ -82,10 +82,8 @@ class Supplier < ApplicationRecord
FoodsoftFile::parse file, options do |status, new_attrs, line| FoodsoftFile::parse file, options do |status, new_attrs, line|
article = articles.undeleted.where(order_number: new_attrs[:order_number]).first article = articles.undeleted.where(order_number: new_attrs[:order_number]).first
if new_attrs[:article_category].present? && options[:update_category] unless new_attrs[:article_category].blank?
new_attrs[:article_category] = ArticleCategory.find_match(new_attrs[:article_category]) || ArticleCategory.create_or_find_by!(name: new_attrs[:article_category]) new_attrs[:article_category] = ArticleCategory.find_match(new_attrs[:article_category]) || ArticleCategory.create_or_find_by!(name: new_attrs[:article_category])
else
new_attrs[:article_category] = nil
end end
new_attrs[:tax] ||= FoodsoftConfig[:tax_default] new_attrs[:tax] ||= FoodsoftConfig[:tax_default]

View file

@ -568,7 +568,7 @@ de:
options: options:
convert_units: Derzeitige Einheiten beibehalten, berechne Mengeneinheit und Preis (wie Synchronisieren). convert_units: Derzeitige Einheiten beibehalten, berechne Mengeneinheit und Preis (wie Synchronisieren).
outlist_absent: Artikel löschen, die nicht in der hochgeladenen Datei sind. outlist_absent: Artikel löschen, die nicht in der hochgeladenen Datei sind.
update_category: Kategorien aus der Datei übernehmen und erstellen. update_category: Kategorien aus der Datei übernehmen.
sample: sample:
juices: Säfte juices: Säfte
nuts: Nüsse nuts: Nüsse

View file

@ -569,7 +569,7 @@ en:
options: options:
convert_units: Keep current units, recompute unit quantity and price (like synchronize). convert_units: Keep current units, recompute unit quantity and price (like synchronize).
outlist_absent: Delete articles not in uploaded file. outlist_absent: Delete articles not in uploaded file.
update_category: Create and replace categories from uploaded file. update_category: Take over categoriesfrom uploaded file.
sample: sample:
juices: Juices juices: Juices
nuts: Nuts nuts: Nuts

View file

@ -1,9 +1,9 @@
require_relative '../spec_helper' require_relative '../spec_helper'
feature ArticlesController do feature ArticlesController do
let(:user) { create :user, groups: [create(:workgroup, role_article_meta: true)] } let(:user) { create(:user, groups: [create(:workgroup, role_article_meta: true)]) }
let(:supplier) { create :supplier } let(:supplier) { create(:supplier) }
let!(:article_category) { create :article_category } let!(:article_category) { create(:article_category) }
before { login user } before { login user }
@ -18,7 +18,7 @@ feature ArticlesController do
it 'can create a new article' do it 'can create a new article' do
click_on I18n.t('articles.index.new') click_on I18n.t('articles.index.new')
expect(page).to have_selector('form#new_article') expect(page).to have_selector('form#new_article')
article = build :article, supplier: supplier, article_category: article_category article = build(:article, supplier: supplier, article_category: article_category)
within('#new_article') do within('#new_article') do
fill_in 'article_name', :with => article.name fill_in 'article_name', :with => article.name
fill_in 'article_unit', :with => article.unit fill_in 'article_unit', :with => article.unit
@ -65,7 +65,7 @@ feature ArticlesController do
end end
describe "can update existing article" do describe "can update existing article" do
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 1, unit: '250 g' } let!(:article) { create(:article, supplier: supplier, name: 'Foobar', order_number: 1, unit: '250 g') }
it do it do
find('input[type="submit"]').click find('input[type="submit"]').click
@ -80,43 +80,20 @@ feature ArticlesController do
describe "handles missing data" do describe "handles missing data" do
it do it do
find('input[type="submit"]').click # to overview find('input[type="submit"]').click # to overview
element = find_by_id('new_articles__price')
element.fill_in with: ""
find('input[type="submit"]').click # missing category, re-show form find('input[type="submit"]').click # missing category, re-show form
expect(find('tr.alert')).to be_present expect(find('tr.alert')).to be_present
expect(supplier.articles.count).to eq 0 expect(supplier.articles.count).to eq 0
all("tr select > option")[1].select_option element.fill_in with: 5.56
find('input[type="submit"]').click # now it should succeed find('input[type="submit"]').click # now it should succeed
expect(supplier.articles.count).to eq 1 expect(supplier.articles.count).to eq 1
end end
end end
describe "takes over category from file" do
it do
find(:css, '#articles_update_category[value="1"]').set(true) # check take over category from file
expect(ArticleCategory.count).to eq 1 # new Category vegetables should be created from file
find('input[type="submit"]').click # upload file
find('input[type="submit"]').click # submit changes
expect(ArticleCategory.count).to eq 2 # it is
expect(supplier.articles.count).to eq 1
expect(supplier.articles.first.article_category.name).to eq "Vegetables"
end
end
describe "overwrites article_category from file" do
let!(:article_category) { create(:article_category, name: "Fruit") }
let(:article) { create(:article, supplier: supplier, name: 'Tomatoes', order_number: 1, unit: '250 g', article_category: article_category) }
it do
find(:css, '#articles_update_category[value="1"]').set(true) # check take over category from file
find('input[type="submit"]').click #upload file
find('input[type="submit"]').click #submit changes
expect(supplier.articles.count).to eq 1
expect(supplier.articles.first.article_category.name).to eq "Vegetables"
end
end
describe "can remove an existing article" do describe "can remove an existing article" do
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 99999 } let!(:article) { create(:article, supplier: supplier, name: 'Foobar', order_number: 99999) }
it do it do
check('articles_outlist_absent') check('articles_outlist_absent')
@ -130,7 +107,7 @@ feature ArticlesController do
end end
describe "can convert units when updating" do describe "can convert units when updating" do
let!(:article) { create :article, supplier: supplier, order_number: 1, unit: '250 g' } let!(:article) { create(:article, supplier: supplier, order_number: 1, unit: '250 g') }
it do it do
check('articles_convert_units') check('articles_convert_units')