Skip to content

Commit

Permalink
On #35: Adapted list of default units
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Apr 12, 2024
1 parent 6ce48cd commit b41b5ca
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
9 changes: 2 additions & 7 deletions db/migrate/20240316190959_create_article_units.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(%{
Expand Down
3 changes: 1 addition & 2 deletions db/seeds/hackathon.seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions db/seeds/hackathon_de.seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/article_units_lib.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit b41b5ca

Please sign in to comment.