12_generate_custom_csv_file #58

Open
philipp wants to merge 59 commits from 12_generate_custom_csv_file into develop
2 changed files with 13 additions and 1 deletions
Showing only changes of commit 33034e66b8 - Show all commits

View file

@ -211,7 +211,7 @@ class Article < ApplicationRecord
rescue StandardError rescue StandardError
nil nil
end end
if fc_unit && supplier_unit && fc_unit =~ supplier_unit if fc_unit != 0 && supplier_unit != 0 && fc_unit && supplier_unit && fc_unit =~ supplier_unit
conversion_factor = (supplier_unit / fc_unit).to_base.to_r conversion_factor = (supplier_unit / fc_unit).to_base.to_r
new_price = new_article.price / conversion_factor new_price = new_article.price / conversion_factor
new_unit_quantity = new_article.unit_quantity * conversion_factor new_unit_quantity = new_article.unit_quantity * conversion_factor

View file

@ -25,6 +25,18 @@ describe Article do
expect(article.convert_units(article1)).to be false expect(article.convert_units(article1)).to be false
end end
it 'returns false if unit = 0' do
article1 = build(:article, supplier: supplier, unit: '1kg', price: 2, unit_quantity: 1)
article2 = build(:article, supplier: supplier, unit: '0kg', price: 2, unit_quantity: 1)
expect(article1.convert_units(article2)).to be false
end
it 'returns false if unit becomes zero because of , symbol in unit format' do
article1 = build(:article, supplier: supplier, unit: '0,8kg', price: 2, unit_quantity: 1)
article2 = build(:article, supplier: supplier, unit: '0,9kg', price: 2, unit_quantity: 1)
expect(article1.convert_units(article2)).to be false
end
it 'converts from ST to KI (german foodcoops legacy)' do it 'converts from ST to KI (german foodcoops legacy)' do
article1 = build(:article, supplier: supplier, unit: 'ST') article1 = build(:article, supplier: supplier, unit: 'ST')
article2 = build(:article, supplier: supplier, name: 'banana 10-12 St', price: 12.34, unit: 'KI') article2 = build(:article, supplier: supplier, name: 'banana 10-12 St', price: 12.34, unit: 'KI')