From a9deeda32b57f49a8753433071eb72368d4cabf8 Mon Sep 17 00:00:00 2001 From: viehlieb Date: Mon, 20 Feb 2023 22:19:00 +0100 Subject: [PATCH] add scale_unit_price --- README.md | 44 ++++++++++++++++++++++++++---- lib/foodsoft_article_import/bnn.rb | 4 ++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2e68041..137ccac 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,44 @@ # FoodsoftArticleImport -This gem provides FoodsoftArticleImport integration for Ruby on Rails and allows to parse avariety of files containing article information. These article information are standardized or customly declared. Possible File Ending are: .bnn, .BNN, .csv, .CSV . It relies on [roo](https://github.com/roo-rb/roo) to read and parse the data +This gem provides FoodsoftArticleImport integration for Ruby on Rails and allows to parse a variety of files containing article information. These article information are standardized or customly declared. Possible File Ending are: .bnn, .BNN, .csv, .CSV . It relies on [roo](https://github.com/roo-rb/roo) to read and parse the data ## Getting started -TODO: add bnn codes, explain how to add bnn codes -TODO: review GNU License +This is a very simple gem that can be used to extract data from files in the formats .bnn, .xml and .csv. +Given one of the aforementioned files, the gem returns information. -For correct import of bnn files, please ensure the correct language setting. Your foodsoft account has to be settings set to german if you want to import articles from file. -To set this is imcrucial for guaranteeing the correct format of article prices. -### Requirements +example for foodsoft file: + +|Status|Order number|Name|Note|Manufacturer|Origin|Unit|Price (net)|VAT|Deposit|Unit quantity|(Reserved)|(Reserved)|Category| +|--- | --- | --- | --- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- | +||1234A|Walnuts||Nuttyfarm|CA|500 gr|8.90|7.0|0|6|||Nuts| +|x|4321Z|Tomato juice|Organic|Brownfields|IN|1.5 l|4.35|7.0|0|1|||Juices| +||4322Q|Tomato juice|Organic|Greenfields|TR|1.2 l|4.02|7.0|0|2|||Juices| + +bnn file reference: +https://n-bnn.de/fileadmin/user_upload/Leistungen_Services/Markt-_und_Produktdaten/BNN3_1Schnittstelle_20.08.21.pdf + +Information about Manufacturer, article category, tax and deposit are conveyed through "bnn codes". +A "bnn code" is a mapping of some abbreviation or number to the relevant data. +The data for suppliers lies at DataNatuRe and we just have a list of some mappings. +Much more codes are needed to make this gem more powerfull. Maybe an xml api to DataNatuRe can be implemented in the futurepossibility. +The list used in this gem is not complete, since it needs data from all manufacturers. +If your local foodcoop posesses keys for article mapping, it is possible to use ypour custom code mapping. + +You can extend it for your local foodcoop, if you create a custom_codes.yml, and put it in your root folder. + +extracted article attributes will be: + +* name: article name from bnn +* order_number: order number from bnn +* note: extra note from bnn +* manufacturer: e.g. ALN -> AL Naturkost Handels GmbH" +* origin: e.g. "GB" +* article_category: e.g. "0202": Sauermilchprodukte +* unit: +* price: +* tax: e.g. "1" -> "7.0" +* unit_quantity: +* deposit: e.g. "930190" -> 0.08 + +## Ruby Version This gem requires Ruby 2.7 \ No newline at end of file diff --git a/lib/foodsoft_article_import/bnn.rb b/lib/foodsoft_article_import/bnn.rb index 83809be..14b1ea0 100644 --- a/lib/foodsoft_article_import/bnn.rb +++ b/lib/foodsoft_article_import/bnn.rb @@ -73,11 +73,13 @@ module FoodsoftArticleImport # get scale prices if exists # article.merge!(:scale_quantity => row[40], :scale_price => row[41]) unless row[40].nil? or row[41].nil? + if !row[62].nil? # consider special prices article[:note] = "Sonderpreis: #{article[:price]} von #{row[62]} bis #{row[63]}" yield article, :special, i - + + article.merge!(:scale_unit_price => row[68] * row[37].to_f ) unless row[68].nil? or row[37].nil? # Check now for article status, we only consider outlisted articles right now # N=neu, A=Änderung, X=ausgelistet, R=Restbestand, # V=vorübergehend ausgelistet, W=wiedergelistet