Add consumables CSV report plugin
This commit is contained in:
parent
7d428f71d9
commit
b8cc88e4af
|
|
@ -7,6 +7,7 @@ layout. Plugins share graphical elements and themes in `visual/`.
|
|||
```bash
|
||||
./build.sh render report examples/example-report.yaml --output report.pdf
|
||||
./build.sh render diagnostic plugins/diagnostics/tests/fixtures/legacy/windiagnostics-v1.json --output diagnostic.pdf
|
||||
./build.sh render consumables plugins/consumables/tests/fixtures/sample.csv --output consumables.pdf
|
||||
./tests/test.sh
|
||||
```
|
||||
|
||||
|
|
|
|||
7
build.sh
7
build.sh
|
|
@ -6,8 +6,8 @@ root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
|
|||
usage() {
|
||||
cat >&2 <<'EOF'
|
||||
Usage:
|
||||
build.sh render report|diagnostic INPUT --output PDF [--force] [--author NAME] [--theme NAME]
|
||||
build.sh render-all report|diagnostic INPUT_DIR --output-dir DIR [--force] [--author NAME] [--theme NAME]
|
||||
build.sh render report|diagnostic|consumables INPUT --output PDF [--force] [--author NAME] [--theme NAME]
|
||||
build.sh render-all report|diagnostic|consumables INPUT_DIR --output-dir DIR [--force] [--author NAME] [--theme NAME]
|
||||
build.sh analyze INPUT --evidence-root DIR --output JSON --reference-time TIME --producer-version VERSION [--force]
|
||||
build.sh analyze-all INPUT_DIR --evidence-root DIR --output-dir DIR --reference-time TIME --producer-version VERSION [--force]
|
||||
build.sh validate report|diagnostic INPUT [--evidence-root DIR]
|
||||
|
|
@ -21,6 +21,7 @@ kind_command() {
|
|||
case ${1:-} in
|
||||
report) printf '%s\n' "$root/render.sh" ;;
|
||||
diagnostic) printf '%s\n' "$root/plugins/diagnostics/render.sh" ;;
|
||||
consumables) printf '%s\n' "$root/plugins/consumables/render.sh" ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
}
|
||||
|
|
@ -76,7 +77,7 @@ case "$command_name" in
|
|||
while IFS= read -r -d '' input; do
|
||||
relative=${input#"$input_dir/"}
|
||||
case "$kind:$input" in
|
||||
report:*.yaml | report:*.yml | report:*.json | diagnostic:*.json) ;;
|
||||
report:*.yaml | report:*.yml | report:*.json | diagnostic:*.json | consumables:*.csv) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
output="$output_dir/${relative%.*}.pdf"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ Invalid input or a failed render exits nonzero. A successful command exits 0.
|
|||
|
||||
`render report INPUT --output PDF` accepts authored `.yaml`, `.yml`, or `.json`.
|
||||
`render diagnostic INPUT --output PDF` accepts raw WinDiagnostics JSON v1/v2.
|
||||
`render consumables INPUT --output PDF` accepts a Snipe-IT consumables `.csv`
|
||||
export. It supports `--theme` and uses the shared Reportist palettes.
|
||||
Each plugin keeps its own Typst document model. Both commands refuse to replace
|
||||
an existing output unless `--force` is supplied. They compile into a temporary
|
||||
directory and move the completed PDF into place.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
# Consumables CSV plugin
|
||||
|
||||
Renders a French stock inventory from a Snipe-IT consumables CSV export. The
|
||||
input must have `Name`, `Category`, `Supplier`, `Model No.`, `Remaining`,
|
||||
`Min. QTY`, and `Location` columns. `Remaining` and `Min. QTY` must contain
|
||||
nonnegative integers for named rows. Unnamed totals rows are skipped.
|
||||
|
||||
```sh
|
||||
./build.sh render consumables plugins/consumables/tests/fixtures/sample.csv --output /tmp/consumables.pdf
|
||||
./build.sh render-all consumables /path/to/exports --output-dir /tmp/consumables-pdfs
|
||||
```
|
||||
|
||||
Run these commands from the Reportist root. `--force` permits replacement;
|
||||
`--theme NAME` selects a palette from `visual/themes.yaml`. The output is A4
|
||||
landscape with repeating table headers, stock status, and summary metrics.
|
||||
Stock at or below the minimum is critical; up to 1.5 times the minimum is low.
|
||||
The `Bureaux` location is displayed as `BUREAU REGIE`, matching the POC.
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
# Render a Snipe-IT consumables CSV as a stock report.
|
||||
set -euo pipefail
|
||||
root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
|
||||
source "$root/../../tools/render-common.sh"
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 INPUT.csv --output PDF [--theme NAME] [--force]" >&2
|
||||
exit 2
|
||||
}
|
||||
input=${1:-}
|
||||
[[ -n "$input" ]] || usage
|
||||
shift
|
||||
theme=default
|
||||
options=()
|
||||
while (($#)); do
|
||||
case $1 in
|
||||
--theme) (($# >= 2)) || usage; theme=$2; shift 2 ;;
|
||||
--output | --force) options+=("$1"); if [[ $1 == --output ]]; then (($# >= 2)) || usage; options+=("$2"); shift 2; else shift; fi ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
reportist_parse_render_options consumables "${options[@]}" || usage
|
||||
[[ -n $RENDER_OUTPUT_OPTION ]] || usage
|
||||
[[ $input == *.csv && ! -L $input ]] || { echo 'Input must be a regular .csv file' >&2; exit 1; }
|
||||
reportist_prepare_render_paths "$input" "$RENDER_OUTPUT_OPTION" "$RENDER_FORCE"
|
||||
input=$RENDER_INPUT output=$RENDER_OUTPUT
|
||||
reportist_make_render_stage consumables
|
||||
stage=$RENDER_STAGE
|
||||
mkdir -p "$stage/consumables" "$stage/config"
|
||||
cp -- "$root/renderer/render.typ" "$stage/consumables.typ"
|
||||
cp -- "$root/../../visual/themes.yaml" "$stage/config/themes.yaml"
|
||||
cp -- "$input" "$stage/consumables/input.csv"
|
||||
typst compile --root "$stage" --input consumables=consumables/input.csv \
|
||||
--input "theme=$theme" "$stage/consumables.typ" "$stage/output.pdf"
|
||||
mv -f -- "$stage/output.pdf" "$output"
|
||||
echo "Rendered PDF: $output"
|
||||
|
|
@ -0,0 +1,610 @@
|
|||
// poc2.typ
|
||||
//
|
||||
// Usage:
|
||||
// typst compile poc2.typ poc2.pdf
|
||||
//
|
||||
// Expects:
|
||||
// export-consumables-2026-09-15.csv
|
||||
|
||||
#let csv-path = sys.inputs.at("consumables", default: "")
|
||||
#let theme-name = sys.inputs.at("theme", default: "default")
|
||||
#let themes = yaml("config/themes.yaml")
|
||||
#assert(theme-name in themes, message: "Unknown theme: " + theme-name)
|
||||
#let theme = themes.at(theme-name)
|
||||
|
||||
// =============================================================================
|
||||
// Theme
|
||||
// =============================================================================
|
||||
|
||||
#let ink = rgb(theme.ink)
|
||||
#let muted = rgb(theme.muted)
|
||||
#let faint = rgb("#94a0ad")
|
||||
|
||||
#let accent = rgb(theme.accent)
|
||||
#let accent-soft = rgb(theme.paper_soft)
|
||||
#let accent-dark = rgb(theme.accent)
|
||||
|
||||
#let surface = rgb("#ffffff")
|
||||
#let surface-alt = rgb(theme.paper_soft)
|
||||
#let surface-strong = rgb(theme.paper_soft)
|
||||
#let border = rgb(theme.line)
|
||||
|
||||
#let good = rgb(theme.success)
|
||||
#let good-soft = rgb("#e9f3ed")
|
||||
|
||||
#let warning = rgb(theme.warning)
|
||||
#let warning-soft = rgb("#f7f0e3")
|
||||
|
||||
#let danger = rgb(theme.critical)
|
||||
#let danger-soft = rgb("#f8eaea")
|
||||
|
||||
// Category colors are independent of the stock-status colors.
|
||||
#let category-style(category) = {
|
||||
let key = lower(category.trim())
|
||||
if key in ("pile", "piles") {
|
||||
(color: rgb("#71501c"), soft: rgb("#f6e9c9"))
|
||||
} else if key in ("ruban", "rubans", "rubalise") {
|
||||
(color: rgb("#216b64"), soft: rgb("#def1eb"))
|
||||
} else if key == "tape" {
|
||||
(color: rgb("#68458c"), soft: rgb("#eee4f6"))
|
||||
} else {
|
||||
(color: accent-dark, soft: accent-soft)
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Components
|
||||
// =============================================================================
|
||||
|
||||
// Generic compact corporate pill.
|
||||
#let pill(
|
||||
body,
|
||||
fill: accent-soft,
|
||||
color: accent-dark,
|
||||
border-color: none,
|
||||
size: 6.8pt,
|
||||
weight: "semibold",
|
||||
) = {
|
||||
box(
|
||||
fill: fill,
|
||||
stroke: if border-color == none { none } else { 0.5pt + border-color },
|
||||
radius: 10pt,
|
||||
inset: (x: 6pt, y: 2.2pt),
|
||||
text(
|
||||
size: size,
|
||||
weight: weight,
|
||||
fill: color,
|
||||
body,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Convert CSV string values safely to integers.
|
||||
#let as-int(value) = {
|
||||
let value = str(value).trim()
|
||||
if value == "" {
|
||||
0
|
||||
} else {
|
||||
int(value)
|
||||
}
|
||||
}
|
||||
|
||||
// Stock status.
|
||||
//
|
||||
// We treat:
|
||||
// stock <= minimum -> critical
|
||||
// stock <= minimum * 1.5 -> warning
|
||||
// otherwise -> healthy
|
||||
#let stock-status(stock, minimum) = {
|
||||
let stock = as-int(stock)
|
||||
let minimum = as-int(minimum)
|
||||
|
||||
if stock <= minimum {
|
||||
(
|
||||
label: "Critique",
|
||||
color: danger,
|
||||
soft: danger-soft,
|
||||
)
|
||||
} else if stock <= minimum * 1.5 {
|
||||
(
|
||||
label: "Bas",
|
||||
color: warning,
|
||||
soft: warning-soft,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
label: "OK",
|
||||
color: good,
|
||||
soft: good-soft,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Stock bar.
|
||||
//
|
||||
// 100% means we have at least twice the minimum stock.
|
||||
// This makes the minimum threshold land around 50%,
|
||||
// which is much more informative than simply doing stock/minimum.
|
||||
#let stock-progress(stock, minimum) = {
|
||||
let stock = as-int(stock)
|
||||
let minimum = as-int(minimum)
|
||||
|
||||
let ratio = if minimum <= 0 {
|
||||
1
|
||||
} else {
|
||||
calc.min(stock / (minimum * 2), 1)
|
||||
}
|
||||
|
||||
let status = stock-status(stock, minimum)
|
||||
|
||||
block(
|
||||
width: 100%,
|
||||
height: 2.5pt,
|
||||
fill: surface-strong,
|
||||
radius: 2pt,
|
||||
)[
|
||||
#block(
|
||||
width: 100% * ratio,
|
||||
height: 100%,
|
||||
fill: status.color,
|
||||
radius: 2pt,
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
#let stock-cell(stock, minimum) = {
|
||||
let status = stock-status(stock, minimum)
|
||||
|
||||
block(width: 100%, breakable: false)[
|
||||
#set par(spacing: 0pt)
|
||||
#grid(
|
||||
columns: (1fr, auto),
|
||||
align: (left + horizon, right + horizon),
|
||||
|
||||
text(
|
||||
size: 7.5pt,
|
||||
weight: "regular",
|
||||
fill: ink,
|
||||
)[
|
||||
#stock
|
||||
],
|
||||
|
||||
pill(
|
||||
status.label,
|
||||
fill: status.soft,
|
||||
color: status.color,
|
||||
size: 6.4pt,
|
||||
weight: "medium",
|
||||
),
|
||||
)
|
||||
|
||||
#v(1.5pt)
|
||||
|
||||
#stock-progress(stock, minimum)
|
||||
]
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Load Snipe-IT CSV
|
||||
// =============================================================================
|
||||
|
||||
#let raw = csv(
|
||||
csv-path,
|
||||
delimiter: ",",
|
||||
row-type: dictionary,
|
||||
)
|
||||
#let required-columns = ("Name", "Category", "Supplier", "Model No.", "Remaining", "Min. QTY", "Location")
|
||||
#assert(raw.len() > 0, message: "CSV has no data rows")
|
||||
#for column in required-columns {
|
||||
assert(column in raw.first(), message: "Missing CSV column: " + column)
|
||||
}
|
||||
|
||||
// Snipe-IT adds a final totals row.
|
||||
// Ignore rows without a name.
|
||||
#let consumables = raw.filter(
|
||||
row => row.at("Name", default: "").trim() != ""
|
||||
)
|
||||
#assert(consumables.len() > 0, message: "CSV has no named consumables")
|
||||
#for row in consumables {
|
||||
for column in ("Remaining", "Min. QTY") {
|
||||
let value = row.at(column).trim()
|
||||
assert(value != "", message: "Missing " + column + " for " + row.at("Name"))
|
||||
let parsed = int(value)
|
||||
assert(parsed >= 0, message: "Negative " + column + " for " + row.at("Name"))
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Mapping
|
||||
// =============================================================================
|
||||
|
||||
#let location-name(location) = {
|
||||
if location == "Bureaux" {
|
||||
"BUREAU REGIE"
|
||||
} else {
|
||||
location.upper()
|
||||
}
|
||||
}
|
||||
|
||||
#let normalize(row) = (
|
||||
lieu: location-name(row.at("Location", default: "")),
|
||||
categorie: row.at("Category", default: ""),
|
||||
nom: row.at("Name", default: ""),
|
||||
fournisseur: row.at("Supplier", default: ""),
|
||||
reference: row.at("Model No.", default: ""),
|
||||
stock: row.at("Remaining", default: ""),
|
||||
minimum: row.at("Min. QTY", default: ""),
|
||||
)
|
||||
|
||||
#let data = consumables.map(normalize)
|
||||
|
||||
// =============================================================================
|
||||
// Statistics
|
||||
// =============================================================================
|
||||
|
||||
#let total-references = data.len()
|
||||
|
||||
#let total-stock = data.fold(
|
||||
0,
|
||||
(sum, row) => sum + as-int(row.stock),
|
||||
)
|
||||
|
||||
#let critical-count = data.filter(
|
||||
row => as-int(row.stock) <= as-int(row.minimum)
|
||||
).len()
|
||||
|
||||
#let low-count = data.filter(row => {
|
||||
let stock = as-int(row.stock)
|
||||
let minimum = as-int(row.minimum)
|
||||
|
||||
stock > minimum and stock <= minimum * 1.5
|
||||
}).len()
|
||||
|
||||
// =============================================================================
|
||||
// Table cells
|
||||
// =============================================================================
|
||||
|
||||
// Merge each consecutive run of rows sharing a location.
|
||||
#let cells = {
|
||||
let result = ()
|
||||
|
||||
for (index, row) in data.enumerate() {
|
||||
let category = category-style(row.categorie)
|
||||
if index > 0 and data.at(index - 1).categorie != row.categorie {
|
||||
result.push(table.hline(
|
||||
y: index + 1,
|
||||
start: 1,
|
||||
stroke: 1pt + accent,
|
||||
))
|
||||
}
|
||||
|
||||
if index == 0 or data.at(index - 1).lieu != row.lieu {
|
||||
let count = 1
|
||||
|
||||
for next in data.slice(index + 1) {
|
||||
if next.lieu != row.lieu {
|
||||
break
|
||||
}
|
||||
|
||||
count += 1
|
||||
}
|
||||
|
||||
result.push(
|
||||
table.cell(
|
||||
rowspan: count,
|
||||
align: center + horizon,
|
||||
fill: accent-dark,
|
||||
inset: 4pt,
|
||||
|
||||
rotate(
|
||||
-90deg,
|
||||
reflow: true,
|
||||
text(
|
||||
size: 7pt,
|
||||
weight: "bold",
|
||||
fill: white,
|
||||
tracking: 0.06em,
|
||||
row.lieu,
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
result += (
|
||||
[
|
||||
#pill(
|
||||
row.categorie,
|
||||
fill: category.soft,
|
||||
color: category.color,
|
||||
size: 6.4pt,
|
||||
weight: "medium",
|
||||
)
|
||||
],
|
||||
|
||||
[
|
||||
#text(size: 7.8pt, weight: "regular", fill: ink)[
|
||||
#row.nom
|
||||
]
|
||||
],
|
||||
|
||||
[
|
||||
#if row.fournisseur != "" {
|
||||
pill(
|
||||
row.fournisseur,
|
||||
fill: surface-strong,
|
||||
color: muted,
|
||||
size: 6.4pt,
|
||||
weight: "medium",
|
||||
)
|
||||
} else {
|
||||
text(fill: faint)[—]
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
#if row.reference != "" {
|
||||
text(
|
||||
font: "DejaVu Sans Mono",
|
||||
size: 6.8pt,
|
||||
fill: muted,
|
||||
row.reference,
|
||||
)
|
||||
} else {
|
||||
text(fill: faint)[—]
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
#stock-cell(row.stock, row.minimum)
|
||||
],
|
||||
|
||||
[
|
||||
#align(center + horizon)[
|
||||
#text(
|
||||
size: 7.5pt,
|
||||
weight: "regular",
|
||||
fill: muted,
|
||||
)[
|
||||
#row.minimum
|
||||
]
|
||||
]
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Document
|
||||
// =============================================================================
|
||||
|
||||
#set page(
|
||||
paper: "a4",
|
||||
flipped: true,
|
||||
margin: (
|
||||
x: 12mm,
|
||||
top: 11mm,
|
||||
bottom: 10mm,
|
||||
),
|
||||
|
||||
footer: context {
|
||||
grid(
|
||||
columns: (1fr, auto),
|
||||
align: (left, right),
|
||||
|
||||
text(
|
||||
size: 6.5pt,
|
||||
fill: faint,
|
||||
)[
|
||||
BEFFROI · INVENTAIRE CONSOMMABLES
|
||||
],
|
||||
|
||||
text(
|
||||
size: 6.5pt,
|
||||
fill: faint,
|
||||
)[
|
||||
#counter(page).display("1 / 1", both: true)
|
||||
],
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
#set text(
|
||||
font: theme.font,
|
||||
size: 8.5pt,
|
||||
fill: ink,
|
||||
lang: "fr",
|
||||
)
|
||||
|
||||
#set par(leading: 0.55em, spacing: 2pt)
|
||||
|
||||
// =============================================================================
|
||||
// Header
|
||||
// =============================================================================
|
||||
|
||||
#grid(
|
||||
columns: (1fr, auto),
|
||||
align: (left + horizon, right + horizon),
|
||||
|
||||
[
|
||||
#text(
|
||||
size: 7pt,
|
||||
weight: "bold",
|
||||
tracking: 0.12em,
|
||||
fill: accent,
|
||||
)[
|
||||
BEFFROI / INVENTAIRE
|
||||
]
|
||||
|
||||
#v(2pt)
|
||||
|
||||
#text(
|
||||
size: 18pt,
|
||||
weight: "bold",
|
||||
fill: ink,
|
||||
)[
|
||||
Liste des consommables
|
||||
]
|
||||
|
||||
#v(2pt)
|
||||
|
||||
#text(size: 8pt, fill: muted)[
|
||||
État consolidé du stock depuis Snipe-IT
|
||||
]
|
||||
],
|
||||
|
||||
[
|
||||
#pill(
|
||||
"SNIPE-IT",
|
||||
fill: accent-soft,
|
||||
color: accent-dark,
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
#v(8pt)
|
||||
|
||||
// =============================================================================
|
||||
// KPI strip
|
||||
// =============================================================================
|
||||
|
||||
#let metric(label, value, note: none, color: accent) = {
|
||||
block(
|
||||
width: 100%,
|
||||
fill: surface-alt,
|
||||
stroke: 0.5pt + border,
|
||||
radius: 4pt,
|
||||
inset: 7pt,
|
||||
)[
|
||||
#text(
|
||||
size: 6.5pt,
|
||||
weight: "bold",
|
||||
tracking: 0.08em,
|
||||
fill: muted,
|
||||
)[
|
||||
#label
|
||||
]
|
||||
|
||||
#v(2pt)
|
||||
|
||||
#text(
|
||||
size: 15pt,
|
||||
weight: "bold",
|
||||
fill: color,
|
||||
)[
|
||||
#value
|
||||
]
|
||||
|
||||
#if note != none {
|
||||
v(1pt)
|
||||
text(size: 6.5pt, fill: faint)[#note]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
#grid(
|
||||
columns: (1fr,) * 4,
|
||||
gutter: 6pt,
|
||||
|
||||
metric(
|
||||
"RÉFÉRENCES",
|
||||
str(total-references),
|
||||
note: "consommables suivis",
|
||||
),
|
||||
|
||||
metric(
|
||||
"UNITÉS EN STOCK",
|
||||
str(total-stock),
|
||||
note: "stock disponible",
|
||||
),
|
||||
|
||||
metric(
|
||||
"STOCK BAS",
|
||||
str(low-count),
|
||||
note: "proche du minimum",
|
||||
color: warning,
|
||||
),
|
||||
|
||||
metric(
|
||||
"CRITIQUES",
|
||||
str(critical-count),
|
||||
note: "au seuil ou en dessous",
|
||||
color: danger,
|
||||
),
|
||||
)
|
||||
|
||||
#v(8pt)
|
||||
|
||||
// =============================================================================
|
||||
// Table
|
||||
// =============================================================================
|
||||
|
||||
#table(
|
||||
columns: (
|
||||
0.35fr, // Lieu
|
||||
1.15fr, // Catégorie
|
||||
2.45fr, // Nom
|
||||
1.25fr, // Fournisseur
|
||||
1.65fr, // Référence
|
||||
1.55fr, // Stock
|
||||
0.55fr, // Mini
|
||||
),
|
||||
|
||||
inset: (x: 5pt, y: 2.5pt),
|
||||
|
||||
stroke: (x, y) => (
|
||||
if y == 0 {
|
||||
0pt
|
||||
} else {
|
||||
0.45pt + border
|
||||
}
|
||||
),
|
||||
|
||||
align: (
|
||||
center,
|
||||
left + horizon,
|
||||
left + horizon,
|
||||
left + horizon,
|
||||
left + horizon,
|
||||
left + horizon,
|
||||
center + horizon,
|
||||
),
|
||||
|
||||
fill: (x, y) => {
|
||||
if y == 0 {
|
||||
ink
|
||||
} else if calc.even(y) {
|
||||
surface-alt
|
||||
} else {
|
||||
surface
|
||||
}
|
||||
},
|
||||
|
||||
table.header(
|
||||
repeat: true,
|
||||
|
||||
table.cell(
|
||||
fill: ink,
|
||||
align: center + horizon,
|
||||
)[
|
||||
#text(size: 6.5pt, weight: "bold", fill: white)[LIEU]
|
||||
],
|
||||
|
||||
[#text(size: 6.5pt, weight: "bold", fill: white)[CATÉGORIE]],
|
||||
[#text(size: 6.5pt, weight: "bold", fill: white)[CONSOMMABLE]],
|
||||
[#text(size: 6.5pt, weight: "bold", fill: white)[FOURNISSEUR]],
|
||||
[#text(size: 6.5pt, weight: "bold", fill: white)[RÉFÉRENCE]],
|
||||
[#text(size: 6.5pt, weight: "bold", fill: white)[STOCK]],
|
||||
[#text(size: 6.5pt, weight: "bold", fill: white)[MIN.]],
|
||||
),
|
||||
|
||||
..cells,
|
||||
|
||||
// Match the outer frame to the category separators.
|
||||
table.hline(y: 0, stroke: 1pt + accent),
|
||||
table.hline(y: data.len() + 1, stroke: 1pt + accent),
|
||||
table.vline(x: 0, stroke: 1pt + accent),
|
||||
table.vline(x: 7, stroke: 1pt + accent),
|
||||
)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Name,Category,Supplier,"Model No.",Total,Remaining,"Min. QTY",Location,"Updated at"
|
||||
"Pile AA",Pile,,LR06-ALCA-10-EN,95,95,50,Bureaux,"2026-09-15 05:37 PM"
|
||||
"Pile AAA",Pile,,LR03-ALCA-10-EN,210,210,50,Bureaux,"2026-09-15 05:37 PM"
|
||||
Pile,Pile,"La BS",9V-ALCA-12-EN,25,25,10,Bureaux,"2026-09-15 05:37 PM"
|
||||
"Pile rechargeable LR06 AA",Pile,"La BS",LR06-2850MA-4-AN,50,50,12,Bureaux,"2026-09-15 05:37 PM"
|
||||
"Pile recheargeable LR03 AAA",Pile,"La BS",LR03-1100MA-4-AN,12,12,12,Bureaux,"2026-09-15 05:37 PM"
|
||||
"Ruban de signalisation",Ruban,"La BS",SECULINE-NJ,6,6,2,Bureaux,"2026-09-15 05:38 PM"
|
||||
"Ruban de signalisation",Ruban,"La BS",SECULINE-RB,5,5,2,Bureaux,"2026-09-15 05:38 PM"
|
||||
"Gaffer blanc",Tape,"La BS",ATN159B-50,9,9,6,Bureaux,"2026-09-15 05:38 PM"
|
||||
"Scotch tapis de danse noir",Tape,,AT5N-N50,44,44,12,Bureaux,"2026-09-15 05:38 PM"
|
||||
"Scotch tapis de danse blanc",Tape,,AT5N-B50,14,14,12,Bureaux,"2026-09-15 05:38 PM"
|
||||
"Gaffer noir",Tape,"La BS",ATN159-N50,10,10,10,Bureaux,"2026-09-15 05:38 PM"
|
||||
"Gaffer alu",Tape,"La BS",ALU-BS50,3,3,2,Bureaux,"2026-09-15 05:39 PM"
|
||||
"Ruban adhesive balisage",Tape,"La BS",SECUGAF-NJ,2,2,1,Bureaux,"2026-09-15 05:39 PM"
|
||||
"Scotch double face",Tape,"La BS",AT327-50,4,4,2,Bureaux,"2026-09-15 05:39 PM"
|
||||
"Scotch tapis danse transparent",Tape,"La BS",DANSE-T50,1,1,1,Bureaux,"2026-09-15 05:39 PM"
|
||||
,,,,490,490,,,
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
FIXTURE = Path(__file__).parent / "fixtures/sample.csv"
|
||||
|
||||
|
||||
class ConsumablesPluginTests(unittest.TestCase):
|
||||
def run_render(self, source, output, *options):
|
||||
return subprocess.run(
|
||||
[str(ROOT / "build.sh"), "render", "consumables", str(source),
|
||||
"--output", str(output), *options],
|
||||
text=True, capture_output=True,
|
||||
)
|
||||
|
||||
def test_standalone_render_and_overwrite(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
output = Path(directory) / "stock.pdf"
|
||||
result = self.run_render(FIXTURE, output)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
original = output.read_bytes()
|
||||
self.assertTrue(original.startswith(b"%PDF-"))
|
||||
self.assertGreater(len(original), 1024)
|
||||
result = self.run_render(FIXTURE, output)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(output.read_bytes(), original)
|
||||
self.assertEqual(self.run_render(FIXTURE, output, "--force").returncode, 0)
|
||||
|
||||
def test_invalid_csv_fails_without_publishing(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory) / "bad.csv"
|
||||
output = Path(directory) / "bad.pdf"
|
||||
source.write_text("Name,Category\nItem,Pile\n")
|
||||
result = self.run_render(source, output)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("Missing CSV column", result.stderr)
|
||||
self.assertFalse(output.exists())
|
||||
|
||||
def test_batch_preserves_paths(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
work = Path(directory)
|
||||
source = work / "inputs/nested/stock.csv"
|
||||
source.parent.mkdir(parents=True)
|
||||
source.write_bytes(FIXTURE.read_bytes())
|
||||
result = subprocess.run(
|
||||
[str(ROOT / "build.sh"), "render-all", "consumables", str(work / "inputs"),
|
||||
"--output-dir", str(work / "outputs")], text=True, capture_output=True,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertTrue((work / "outputs/nested/stock.pdf").read_bytes().startswith(b"%PDF-"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
@ -2,4 +2,5 @@
|
|||
set -euo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
python3 -m unittest discover -s tests -p 'test_plugin.py' -v
|
||||
python3 -m unittest discover -s plugins/consumables/tests -p 'test_plugin.py' -v
|
||||
plugins/diagnostics/tests/test.sh
|
||||
|
|
|
|||
Loading…
Reference in New Issue