From cb6b868525a728ab9c41a2c01ad2e4a48f6ce4f9 Mon Sep 17 00:00:00 2001 From: twothreenine Date: Tue, 23 Jul 2024 00:16:06 +0200 Subject: [PATCH] Article CSV: fix #47 and partly #46 - rearrange CSV columns as I suggested in #47 - add locales for column headings according to my suggestions in #50 (to do: adjust terms across menus -- post-merge?) - update documentation of CSV layout (#46) TO DO: #83, #81 (more important) #80, #82 (less important) --- app/lib/articles_csv.rb | 42 ++++++++--------- app/lib/foodsoft_file.rb | 28 +++++------ app/views/articles/upload.html.haml | 72 ++++++++++++++++++----------- config/locales/de.yml | 8 ++++ config/locales/en.yml | 10 +++- 5 files changed, 96 insertions(+), 64 deletions(-) diff --git a/app/lib/articles_csv.rb b/app/lib/articles_csv.rb index 2f14593b..8c6b3696 100644 --- a/app/lib/articles_csv.rb +++ b/app/lib/articles_csv.rb @@ -6,21 +6,21 @@ def header Article.human_attribute_name(:availability_short), Article.human_attribute_name(:order_number), Article.human_attribute_name(:name), - Article.human_attribute_name(:note), - Article.human_attribute_name(:manufacturer), - Article.human_attribute_name(:origin), - Article.human_attribute_name(:unit), - Article.human_attribute_name(:price), - Article.human_attribute_name(:tax), - Article.human_attribute_name(:deposit), Article.human_attribute_name(:supplier_order_unit), - Article.human_attribute_name(:price_unit), - Article.human_attribute_name(:group_order_unit), - Article.human_attribute_name(:group_order_granularity), + Article.human_attribute_name(:custom_unit), + Article.human_attribute_name(:ratios_to_supplier_order_unit), Article.human_attribute_name(:minimum_order_quantity), Article.human_attribute_name(:billing_unit), + Article.human_attribute_name(:group_order_granularity), + Article.human_attribute_name(:group_order_unit), + Article.human_attribute_name(:price), + Article.human_attribute_name(:price_unit), + Article.human_attribute_name(:tax), + Article.human_attribute_name(:deposit), + Article.human_attribute_name(:note), Article.human_attribute_name(:article_category), - Article.human_attribute_name(:ratios_to_supplier_order_unit) + Article.human_attribute_name(:origin), + Article.human_attribute_name(:manufacturer) ] end @@ -30,21 +30,21 @@ def data article.availability ? I18n.t('simple_form.yes') : I18n.t('simple_form.no'), article.order_number, article.name, - article.note, - article.manufacturer, - article.origin, + ArticleUnitsLib.get_translated_name_for_code(article.supplier_order_unit), article.unit, + get_csv_ratios(article), + article.minimum_order_quantity, + ArticleUnitsLib.get_translated_name_for_code(article.billing_unit), + article.group_order_granularity, + ArticleUnitsLib.get_translated_name_for_code(article.group_order_unit), article.price, + ArticleUnitsLib.get_translated_name_for_code(article.price_unit), article.tax, article.deposit, - ArticleUnitsLib.get_translated_name_for_code(article.supplier_order_unit), - ArticleUnitsLib.get_translated_name_for_code(article.price_unit), - ArticleUnitsLib.get_translated_name_for_code(article.group_order_unit), - article.group_order_granularity, - article.minimum_order_quantity, - ArticleUnitsLib.get_translated_name_for_code(article.billing_unit), + article.note, article.article_category.try(:name), - get_csv_ratios(article) + article.origin, + article.manufacturer ] end end diff --git a/app/lib/foodsoft_file.rb b/app/lib/foodsoft_file.rb index 17a26ba5..deca4d22 100644 --- a/app/lib/foodsoft_file.rb +++ b/app/lib/foodsoft_file.rb @@ -11,21 +11,21 @@ def self.parse(file, options = {}) article = { availability: row[0]&.strip == I18n.t('simple_form.yes'), order_number: row[1], name: row[2], - note: row[3], - manufacturer: row[4], - origin: row[5], - unit: row[6], - price: row[7], - tax: row[8], - deposit: (row[9].nil? ? '0' : row[9]), - supplier_order_unit: ArticleUnitsLib.get_code_for_unit_name(row[10]), + supplier_order_unit: ArticleUnitsLib.get_code_for_unit_name(row[3]), + unit: row[4], + article_unit_ratios: FoodsoftFile.parse_ratios_cell(row[5]), + minimum_order_quantity: row[6], + billing_unit: ArticleUnitsLib.get_code_for_unit_name(row[7]), + group_order_granularity: row[8], + group_order_unit: ArticleUnitsLib.get_code_for_unit_name(row[9]), + price: row[10], price_unit: ArticleUnitsLib.get_code_for_unit_name(row[11]), - group_order_unit: ArticleUnitsLib.get_code_for_unit_name(row[12]), - group_order_granularity: row[13], - minimum_order_quantity: row[14], - billing_unit: ArticleUnitsLib.get_code_for_unit_name(row[15]), - article_category: row[16], - article_unit_ratios: FoodsoftFile.parse_ratios_cell(row[17]) } + tax: row[12], + deposit: (row[13].nil? ? '0' : row[13]), + note: row[14], + article_category: row[15], + origin: row[16], + manufacturer: row[17] } articles << article end diff --git a/app/views/articles/upload.html.haml b/app/views/articles/upload.html.haml index 8f91d790..fea1e31e 100644 --- a/app/views/articles/upload.html.haml +++ b/app/views/articles/upload.html.haml @@ -5,66 +5,82 @@ %table.table.table-bordered %thead %tr - %th= t '.field.status' + %th= Article.human_attribute_name(:availability_short) %th= Article.human_attribute_name(:order_number) %th= Article.human_attribute_name(:name) - %th= Article.human_attribute_name(:note) - %th= Article.human_attribute_name(:manufacturer) - %th= Article.human_attribute_name(:origin) - %th= Article.human_attribute_name(:unit) + %th= Article.human_attribute_name(:supplier_order_unit) + %th= Article.human_attribute_name(:custom_unit) + %th= Article.human_attribute_name(:ratios_to_supplier_order_unit) + %th= Article.human_attribute_name(:minimum_order_quantity) + %th= Article.human_attribute_name(:billing_unit) + %th= Article.human_attribute_name(:group_order_granularity) + %th= Article.human_attribute_name(:group_order_unit) %th= Article.human_attribute_name(:price) + %th= Article.human_attribute_name(:price_unit) %th= Article.human_attribute_name(:tax) %th= Article.human_attribute_name(:deposit) - %th= Article.human_attribute_name(:unit_quantity) - %th.muted= t '.fields.reserved' - %th.muted= t '.fields.reserved' + %th= Article.human_attribute_name(:note) %th= Article.human_attribute_name(:article_category) + %th= Article.human_attribute_name(:origin) + %th= Article.human_attribute_name(:manufacturer) %tbody %tr %td %td 1234A %td= t '.sample.walnuts' + %td= ArticleUnitsLib.get_translated_name_for_code('KGM') %td - %td= t '.sample.supplier_1' - %td CA - %td 500 gr - %td 8.90 + %td + %td + %td= ArticleUnitsLib.get_translated_name_for_code('KGM') + %td 0.5 + %td= ArticleUnitsLib.get_translated_name_for_code('KGM') + %td 17.80 + %td= ArticleUnitsLib.get_translated_name_for_code('KGM') %td= FoodsoftConfig[:tax_default] || 6 %td 0 - %td 6 - %td %td %td= t '.sample.nuts' + %td CA + %td= t '.sample.supplier_1' %tr %td x %td 4321Z %td= t '.sample.tomato_juice' - %td= t '.sample.organic' - %td= t '.sample.supplier_2' - %td IN - %td 1.5 l + %td= ArticleUnitsLib.get_translated_name_for_code('XJY') + %td + %td= '1.5 ' + ArticleUnitsLib.get_translated_name_for_code('LTR') + %td + %td + %td 1 + %td= ArticleUnitsLib.get_translated_name_for_code('XJY') %td 4.35 + %td= ArticleUnitsLib.get_translated_name_for_code('XJY') %td= FoodsoftConfig[:tax_default] || 6 %td 0 - %td 1 - %td - %td + %td= t '.sample.organic' %td= t '.sample.juices' + %td IN + %td= t '.sample.supplier_2' %tr %td %td 4322Q %td= t '.sample.tomato_juice' - %td= t '.sample.organic' - %td= t '.sample.supplier_3' - %td TR - %td 1.2 l + %td= ArticleUnitsLib.get_translated_name_for_code('XBO') + %td + %td= '1.2 ' + ArticleUnitsLib.get_translated_name_for_code('LTR') + %td 4 + %td= ArticleUnitsLib.get_translated_name_for_code('LTR') + %td 1 + %td= ArticleUnitsLib.get_translated_name_for_code('XBO') %td 4.02 + %td= ArticleUnitsLib.get_translated_name_for_code('LTR') %td= FoodsoftConfig[:tax_default] || 6 %td 0 - %td 2 - %td - %td + %td= t '.sample.organic' %td= t '.sample.juices' + %td TR + %td= t '.sample.supplier_3' %p= t '.text_2' diff --git a/config/locales/de.yml b/config/locales/de.yml index 9b4c4ad1..58d4ce8a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -22,9 +22,17 @@ de: supplier: Lieferantin tax: MwSt unit: Einheit + custom_unit: Benutzerdefinierte Einheit unit_quantity: Gebindegröße unit_quantity_short: GebGr units: Gebinde + supplier_order_unit: von Lieferantin bestellbar in (Einheit) + ratios_to_supplier_order_unit: Inhalt + minimum_order_quantity: Mindestbestellmenge + billing_unit: abgerechnet nach (Einheit) + group_order_granularity: für Mitglieder bestellbar in (Menge) + group_order_unit: für Mitglieder bestellbar in (Einheit) + price_unit: pro (Preiseinheit) article_unit: code: Einheitencode gemäß Empfehlung der United Nations Economic Commission (UNECE) code_short: Code diff --git a/config/locales/en.yml b/config/locales/en.yml index fe6a49c0..5bf6e818 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -22,10 +22,18 @@ en: supplier: Supplier tax: VAT unit: Unit + custom_unit: Custom unit unit_quantity: Unit quantity unit_quantity_short: U.Q. units: Units - supplier_order_unit: Supplier order unit + supplier_order_unit: orderable from supplier per (unit) + ratios_to_supplier_order_unit: Content + minimum_order_quantity: Minimum order quantity + billing_unit: billed per (unit) + group_order_granularity: members can order per (amount) + group_order_unit: members can order per (unit) + price_unit: per (price unit) + article_unit: code: Unit code according to the recommendation of the United Nations Economic Commission (UNECE) code_short: Code