diff --git a/db/migrate/20240316190959_create_article_units.rb b/db/migrate/20240316190959_create_article_units.rb index 4e2bf96d..bf19288c 100644 --- a/db/migrate/20240316190959_create_article_units.rb +++ b/db/migrate/20240316190959_create_article_units.rb @@ -8,14 +8,9 @@ def up add_index :article_units, :unit, unique: true - piece_unit_codes = %w[XCU XCN XSH X43 XST XOK XVA XBX XBH XBE XCX XBJ XUN XOS XDH XBA XFI XBO XBQ XFB XFT XJR XGR XOW X8B XCV XWA XEI XJT XGY XJY XBD XCR XAI XPA XBK XBI XOV XNT XPK XPC XPX X5M XPR XEC X6H X44 XBR XCW XBT XSA XBM XSX XDN XAE XSC XLU X5L XPP XBG XP2 XCK XGI XTU XPU XPT PTN STC] - scalar_unit_codes = %w[DMT CMT 4H MMT HMT KMT A45 MTK DAA KMK CMK DMK H16 H18 MMK ARE HAR YDK KGM HGM KTN DJ DG CGM DTN MGM 2U MC GRM TNE M86 SEC MIN HUR DAY C26 WEE MON ANN MTQ LTR MAL DLT 4G K6 A44 MMQ CMQ DMQ MLT HLT CLT DMA H19 H20 M70 YDQ G26 G21 G24 G25 JOU J75 K51 J55 WHR KWH GWH WTT KWT MAW] + unit_codes = ArticleUnitsLib::DEFAULT_PIECE_UNIT_CODES + ArticleUnitsLib::DEFAULT_METRIC_SCALAR_UNIT_CODES - imperial_scalar_unit_codes = %w[INH FOT YRD SMI 5I 77 M47 INK FTK MIK ACR LBR GRN ONZ CWI CWA LTN STI STN APZ F13 M67 M68 M69 INQ FTQ GLI GLL PTI QTI PTL QTL PTD OZI J57 L43 L84 L86 OZA BUI BUA BLL BLD GLD QTD G23] - - unit_codes = piece_unit_codes + scalar_unit_codes - - unit_codes += imperial_scalar_unit_codes if imperial_plain_text_units_exist? + unit_codes += ArticleUnitsLib::DEFAULT_IMPERIAL_SCALAR_UNIT_CODES if imperial_plain_text_units_exist? unit_codes.each do |unit_code| insert(%{ diff --git a/db/seeds/hackathon.seeds.rb b/db/seeds/hackathon.seeds.rb index 81d88fd3..6a3b4827 100644 --- a/db/seeds/hackathon.seeds.rb +++ b/db/seeds/hackathon.seeds.rb @@ -7,8 +7,7 @@ ## Article units -# TODO: - make this depend on locale - see https://github.com/foodcoopsat/foodsoft_hackathon/issues/35 -unit_codes = %w[GRM HGM KGM LTR MLT PTN STC XPP XCR XBO XBH XGR XPK XSA XPU XPT] +unit_codes = ArticleUnitsLib::DEFAULT_PIECE_UNIT_CODES + ArticleUnitsLib::DEFAULT_METRIC_SCALAR_UNIT_CODES + ArticleUnitsLib::DEFAULT_IMPERIAL_SCALAR_UNIT_CODES unit_codes.each { |unit_code| ArticleUnit.create!(unit: unit_code) } ## Suppliers & articles diff --git a/db/seeds/hackathon_de.seeds.rb b/db/seeds/hackathon_de.seeds.rb index 3e645e47..52ce78fe 100644 --- a/db/seeds/hackathon_de.seeds.rb +++ b/db/seeds/hackathon_de.seeds.rb @@ -7,8 +7,7 @@ ## Article units -# TODO: - make this depend on locale - see https://github.com/foodcoopsat/foodsoft_hackathon/issues/35 -unit_codes = %w[GRM HGM KGM LTR MLT PTN STC XPP XCR XBO XBH XGR XPK XSA XPU XPT] +unit_codes = ArticleUnitsLib::DEFAULT_PIECE_UNIT_CODES + ArticleUnitsLib::DEFAULT_METRIC_SCALAR_UNIT_CODES unit_codes.each { |unit_code| ArticleUnit.create!(unit: unit_code) } ## Suppliers & articles diff --git a/lib/article_units_lib.rb b/lib/article_units_lib.rb index 12c81e5a..53cfc308 100644 --- a/lib/article_units_lib.rb +++ b/lib/article_units_lib.rb @@ -1,4 +1,8 @@ class ArticleUnitsLib + DEFAULT_PIECE_UNIT_CODES = %w[PTN STC XCU XCN XSH X43 XST XOK XVA XBX XBH XBE XCX XBJ XUN XOS XDH XBA XFI XBO XBQ XFB XFT XJR XGR XOW X8B XCV XWA XEI XJT XGY XJY XBD XCR XAI XPA XBK XBI XOV XNT XPK XPC XPX X5M XPR XEC X6H X44 XBR XCW XBT XSA XBM XSX XDN XAE XSC XLU X5L XPP XPU XBG XP2 XCK XPT XGI XTU] + DEFAULT_METRIC_SCALAR_UNIT_CODES = %w[KGM HGM DJ LTR DLT CLT MLT] + DEFAULT_IMPERIAL_SCALAR_UNIT_CODES = %w[LBR ONZ GLL QTI PTI] + @un_ece_20_units = YAML.safe_load(ERB.new(File.read(File.expand_path( 'config/units-of-measure/un-ece-20-remastered.yml', Rails.root ))).result)