"""The UN/ECE Recommendation 20 (units of measure) and Recommendation 21 (packaging, X-prefixed) code list, vendored as data.
Two uses, and nothing is fetched at run time:
- an e-invoice unit code (`einvoice_unit_code`, what a UBL / Peppol line's unitCode carries) must be one of these codes;
- a customer's own PACK code (PK24, PALLET80) must not shadow a MEASURING unit of Rec 20 (KGM as 25 pieces): every non-X code
except the few that count or pack things (C62 'one', EA, H87 piece, SET, PR, DZN …) is reserved.
"""
import json
import pathlib
_DATA = json.loads((pathlib.Path(__file__).with_name("unece_rec20_21.json")).read_text(encoding="utf-8"))
CODES: dict = _DATA["codes"]
COUNTING = frozenset(_DATA["counting_and_packaging_units"]["codes"])
RESERVED = frozenset(c for c in CODES if not c.startswith("X") and c not in COUNTING)
def is_einvoice_code(code: str) -> bool:
return code in CODES
def name_of(code: str) -> str:
return CODES.get(code, "")