Skip to content

Commit

Permalink
Article CSV: fix #47 and #46 (#84)
Browse files Browse the repository at this point in the history
- 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:
any adaptations for rearranged tables necessary which I've overlooked? (for example sync feature)
  • Loading branch information
twothreenine authored Jul 26, 2024
1 parent b3bc712 commit 3be31d5
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 71 deletions.
42 changes: 21 additions & 21 deletions app/lib/articles_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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_unit_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
Expand Down
28 changes: 14 additions & 14 deletions app/lib/foodsoft_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
77 changes: 49 additions & 28 deletions app/views/articles/upload.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,87 @@
%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
- kgm = ArticleUnitsLib.get_translated_name_for_code('KGM')
- xjy = ArticleUnitsLib.get_translated_name_for_code('XJY')
- ltr = ArticleUnitsLib.get_translated_name_for_code('LTR')
- xbd = ArticleUnitsLib.get_translated_name_for_code('XBD')
- xbo = ArticleUnitsLib.get_translated_name_for_code('XBO')
%tr
%td
%td 1234A
%td= t '.sample.walnuts'
%td= kgm
%td
%td= t '.sample.supplier_1'
%td CA
%td 500 gr
%td 8.90
%td
%td
%td= kgm
%td 0.5
%td= kgm
%td 17.80
%td= 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= xjy
%td
%td= '1.5 ' + ltr
%td 4
%td= ltr
%td 1
%td= xjy
%td 4.35
%td= ltr
%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= xbd
%td
%td= '6 ' + xbo + ', 1 ' + ltr
%td
%td= xbd
%td 1
%td= xbo
%td 4.02
%td= xbo
%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'

Expand Down
8 changes: 8 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/fixtures/foodsoft_file_01.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
avail.;Order number;Name;Note;Manufacturer;Origin;Unit;Price (net);VAT;Deposit;Supplier order unit;Price unit;Group order unit;Group order granularity;Minimum order quantity;Billing unit;Category;Ratios to supplier order unit
Yes;29932;Walnoten (ongeroosterd);bio ◎;Het grote bomenbos;Veluwe, NL;kg;2.34;6;0;;;;1;;;Nuts;
Yes;28391;Pijnboompitten;dem;Het warme woud;TR;100g;5.56;6;0;;;;1;;;Nuts;10 Piece
Yes;1829;Appelsap (verpakt);;Appelgaarde;DE;4x250ml;3.21;6;0.4;;;;1;;;Drinks;10 Piece
Yes;177813;Tomaten;bio;De röde hof;Best, NL;500 g;1.2;6;0;;;;1;;;Vegetables;20 Piece
avail.;Order number;Name;Supplier order unit;Unit;Ratios to supplier order unit;Minimum order quantity;Billing unit;Group order granularity;Group order unit;Price (net);Price unit;VAT;Deposit;Note;Category;Origin;Manufacturer
Yes;29932;Walnoten (ongeroosterd);;kg;;;;1;;2.34;;6;0;bio ◎;Nuts;Veluwe, NL;Het grote bomenbos
Yes;28391;Pijnboompitten;;100g;10 Piece;;;1;;5.56;;6;0;dem;Nuts;TR;Het warme woud
Yes;1829;Appelsap (verpakt);;4x250ml;10 Piece;;;1;;3.21;;6;0.4;;Drinks;DE;Appelgaarde
Yes;177813;Tomaten;;500 g;20 Piece;;;1;;1.2;;6;0;bio;Vegetables;Best, NL;De röde hof
Binary file modified spec/fixtures/foodsoft_file_01.ods
Binary file not shown.
Binary file modified spec/fixtures/foodsoft_file_01.xls
Binary file not shown.
Binary file modified spec/fixtures/foodsoft_file_01.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions spec/fixtures/foodsoft_file_02.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
avail.;Order number;Name;Note;Manufacturer;Origin;Unit;Price (net);VAT;Deposit;Supplier order unit;Price unit;Group order unit;Group order granularity;Minimum order quantity;Billing unit;Category;Ratios to supplier order unit
Yes;1;Tomatoes;organic;Tommy farm;Somewhere, UK;500 g;1.2;6;0;;;;1;;;Vegetables;20 Piece
avail.;Order number;Name;Supplier order unit;Unit;Ratios to supplier order unit;Minimum order quantity;Billing unit;Group order granularity;Group order unit;Price (net);Price unit;VAT;Deposit;Note;Category;Origin;Manufacturer
Yes;1;Tomatoes;;500 g;20 Piece;;;1;;1.2;;6;0;organic;Vegetables;Somewhere, UK;Tommy farm

0 comments on commit 3be31d5

Please sign in to comment.