dodil/erp-brick-hr

src/brick_hr/domain/packs/__init__.py

"""Localisation packs: a country's legal fields, document types, steps, checks and holiday rows — code plus seed
rows, registered by country code. A country with no pack gets none of it, and the core works unchanged. A pack
RECORDS decisions and evidence; it never makes a legal determination."""
import functools

from brick_hr.domain.packs import gb

PACKS = {"gb": gb}


@functools.lru_cache(maxsize=None)
def _designed() -> dict:
    out = {}
    for mod in PACKS.values():
        for body in mod.starter_playbooks():
            for s in body["steps"]:
                out[(body["playbook_id"], int(s["step_no"]), s["title"])] = s["key"]
    return out


def designed_key(playbook_id: str, step_no: int, title: str):
    """The key a pack designed for a starter playbook's step — what a step stored before keys existed gets, when it
    is still the pack's step (same playbook, number and title). None otherwise."""
    return _designed().get((playbook_id, int(step_no), title))


__all__ = ["PACKS", "designed_key"]