include foodsoft-article-import

This commit is contained in:
viehlieb 2023-01-31 15:25:36 +01:00
parent fb8ccfea4a
commit a92a51d88a
3 changed files with 18 additions and 3 deletions

View file

@ -50,6 +50,8 @@ gem 'attribute_normalizer'
gem 'ice_cube'
# At time of development 01-06-2022 mmddyyyy necessary fix for config_helper.rb form builder was not in rubygems so we pull from github, see: https://github.com/gregschmit/recurring_select/pull/152
gem 'recurring_select', git: 'https://github.com/gregschmit/recurring_select'
# TODO: publish gem on github
gem 'foodsoft_article_import', git: 'https://git.local-it.org/Foodsoft/foodsoft_article_import', tag: 'v0.1'
gem 'roo'
gem 'roo-xls'
gem 'spreadsheet'

View file

@ -1,3 +1,12 @@
GIT
remote: https://git.local-it.org/Foodsoft/foodsoft_article_import
revision: c7e432c247ca6aa327ae889d22f78227efed2479
tag: v0.1
specs:
foodsoft_article_import (1.0.0)
roo (~> 2.9.0)
simplecov
GIT
remote: https://github.com/gregschmit/recurring_select
revision: 29febc4c4abdd6c30636c33a7d2daecb09973ecf
@ -615,6 +624,7 @@ DEPENDENCIES
exception_notification
factory_bot_rails
faker
foodsoft_article_import!
foodsoft_discourse!
foodsoft_documents!
foodsoft_links!
@ -686,4 +696,4 @@ DEPENDENCIES
whenever
BUNDLED WITH
2.4.3
2.4.2

View file

@ -1,3 +1,4 @@
require 'foodsoft_article_import'
class Supplier < ApplicationRecord
include MarkAsDeletedWithName
include CustomFields
@ -76,10 +77,12 @@ class Supplier < ApplicationRecord
# @param options [Hash] Options passed to {FoodsoftFile#parse} except when listed here.
# @option options [Boolean] :outlist_absent Set to +true+ to remove articles not in spreadsheet.
# @option options [Boolean] :convert_units Omit or set to +true+ to keep current units, recomputing unit quantity and price.
def sync_from_file(file, options = {})
def sync_from_file(file, type, options = {})
all_order_numbers = []
updated_article_pairs, outlisted_articles, new_articles = [], [], []
FoodsoftFile::parse file, options do |status, new_attrs, line|
custom_codes_path = File.join(Rails.root, "config", "custom_codes.yml")
custom_codes_file_path = custom_codes_path if File.exist?(custom_codes_path)
FoodsoftArticleImport.parse(file, custom_file_path: custom_codes_file_path, type: type, options: options) do |new_attrs, status, line|
article = articles.undeleted.where(order_number: new_attrs[:order_number]).first
new_attrs[:article_category] = ArticleCategory.find_match(new_attrs[:article_category])
new_attrs[:tax] ||= FoodsoftConfig[:tax_default]