Compare commits

..

5 Commits

Author SHA1 Message Date
b17adb1257 Merge pull request 'Resolve [YEAR] for template read vs write destinations' (#7) from cursor/year-placeholder-write-max into main
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
2026-10-25 06:50:37 +00:00
c2b10ac856 Resolve [YEAR] separately for template read and write destinations.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-25 10:16:57 +03:30
d3960cdbf7 Merge pull request #28 from s-diaco/cursor/enter-key-submit-26b5
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Fix Enter key to create QC datasheet
2026-09-27 11:39:02 +03:30
Cursor Agent
a9c31148e0 Fix Enter key to submit QC sheet form
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Wrap fields in a form with type=submit Create button so Enter in
serial (or closed combobox) creates the datasheet without a mouse click.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-09-27 07:59:59 +00:00
e4cdb540e9 Fix intermittent win32com CLSIDToPackageMap errors on Windows. (#27)
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Corrupt gen_py early-binding cache is cleared and EnsureDispatch retried
(with late-bound Dispatch fallback), matching the manual Temp\gen_py workaround.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-09-22 23:43:35 +03:30
6 changed files with 225 additions and 80 deletions

View File

@@ -39,10 +39,12 @@ To put a self-contained app on other PCs (build **on Windows**):
| Step | Action | | Step | Action |
|------|--------| |------|--------|
| 1 | Find the latest matching workbook in the product folder | | 1 | Resolve `[YEAR]` and find the latest matching workbook (template) in that product folder |
| 2 | Clear configured cells / blank notes | | 2 | Clear configured cells / blank notes |
| 3 | Write the batch serial | | 3 | Write the batch serial |
| 4 | Save as a new file using the `[SERIAL]` name pattern | | 4 | Save under the largest existing year folder using the `[SERIAL]` name pattern |
Year folders in `file_data.csv` use a `[YEAR]` placeholder. The template is read from the largest digit-named year directory that already contains matching sheets for that ink. The new workbook is written into the largest digit-named year directory under the same QC parent (existence only; the ink folder is created if missing).
### Excel backends ### Excel backends
@@ -133,7 +135,7 @@ Windows CLI helper: `src\xlsx_clean\new_xslx.bat`
| File | Purpose | | File | Purpose |
|------|---------| |------|---------|
| `config.toml` | Backend choice and root directory path for each set (auto-generated in `~/.xlsx-clean/` on first run) | | `config.toml` | Backend choice and root directory path for each set (auto-generated in `~/.xlsx-clean/` on first run) |
| `src/xlsx_clean/file_data.csv` | Relative product folders, filename patterns, cells to clear/set | | `src/xlsx_clean/file_data.csv` | Relative product folders (`[YEAR]` placeholder), filename patterns, cells to clear/set |
| `src/xlsx_clean/strings.txt` | UI prompts + Windows Excel add-in paths (`com` only) | | `src/xlsx_clean/strings.txt` | UI prompts + Windows Excel add-in paths (`com` only) |
## Project layout (launchers) ## Project layout (launchers)

View File

@@ -6,7 +6,6 @@ import csv
import shutil import shutil
import tempfile import tempfile
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime
from pathlib import Path from pathlib import Path
import tomllib import tomllib
@@ -33,6 +32,7 @@ backend = "com"
NEW_VALUE = "" NEW_VALUE = ""
YEAR_TOKEN = "[YEAR]"
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -49,15 +49,61 @@ def find_last_workbook(files: list[str]) -> str:
return sorted(files)[-1] return sorted(files)[-1]
def _split_year_placeholder(dir_with_placeholder: Path) -> tuple[Path, tuple[str, ...]] | None:
parts = dir_with_placeholder.parts
if YEAR_TOKEN not in parts:
return None
idx = parts.index(YEAR_TOKEN)
return Path(*parts[:idx]), parts[idx + 1 :]
def _digit_year_dirs(base: Path) -> list[Path]:
if not base.is_dir():
return []
return [c for c in base.iterdir() if c.is_dir() and c.name.isdigit()]
def resolve_year_dir(dir_with_placeholder: Path, pattern: str) -> Path:
"""Largest digit year dir that has matching template sheets for this ink."""
split = _split_year_placeholder(dir_with_placeholder)
if split is None:
return dir_with_placeholder
base, suffix = split
search_pattern = pattern.replace("[SERIAL]", "*")
years: list[int] = []
for child in _digit_year_dirs(base):
ink_dir = child.joinpath(*suffix) if suffix else child
if any(p.is_file() for p in ink_dir.glob(search_pattern)):
years.append(int(child.name))
if not years:
raise FileNotFoundError(
f"No year directory under {base} with workbooks matching {search_pattern!r}"
)
resolved = base / str(max(years))
return resolved.joinpath(*suffix) if suffix else resolved
def resolve_write_year_dir(dir_with_placeholder: Path) -> Path:
"""Largest digit year dir under the QC parent (existence only, no sheet check)."""
split = _split_year_placeholder(dir_with_placeholder)
if split is None:
return dir_with_placeholder
base, suffix = split
years = [int(c.name) for c in _digit_year_dirs(base)]
if not years:
raise FileNotFoundError(f"No year directory under {base}")
resolved = base / str(max(years))
return resolved.joinpath(*suffix) if suffix else resolved
def get_workbook_names( def get_workbook_names(
files: list[str], files: list[str],
batch_serial: str, batch_serial: str,
source_dir: Path, dest_dir: Path,
pattern: str, pattern: str,
) -> tuple[str, Path]: ) -> tuple[str, Path]:
last_workbook = find_last_workbook(files) last_workbook = find_last_workbook(files)
path_of_the_year = Path(str(source_dir).replace("2025", str(datetime.now().year))) return last_workbook, dest_dir / pattern.replace(
return last_workbook, path_of_the_year / pattern.replace(
"[SERIAL]", batch_serial.split("/")[0] "[SERIAL]", batch_serial.split("/")[0]
) )
@@ -159,13 +205,20 @@ def create_datasheet(
return CreateResult(ok=False, message=message) return CreateResult(ok=False, message=message)
row = matches[0] row = matches[0]
path_ = Path(row["dir"])
pattern = row["pattern"] pattern = row["pattern"]
placeholder_dir = Path(row["dir"])
try:
read_dir = resolve_year_dir(placeholder_dir, pattern)
write_dir = resolve_write_year_dir(placeholder_dir)
except FileNotFoundError as exc:
message = str(exc)
log.error("Create failed: %s (%s)", message, ctx)
return CreateResult(ok=False, message=message, backend=resolved_backend)
search_pattern = pattern.replace("[SERIAL]", "*") search_pattern = pattern.replace("[SERIAL]", "*")
files = [str(x) for x in path_.glob(search_pattern) if x.is_file()] files = [str(x) for x in read_dir.glob(search_pattern) if x.is_file()]
if not files: if not files:
message = f"No workbooks matching {search_pattern!r} in {path_}" message = f"No workbooks matching {search_pattern!r} in {read_dir}"
log.error("Create failed: %s (%s)", message, ctx) log.error("Create failed: %s (%s)", message, ctx)
return CreateResult( return CreateResult(
ok=False, ok=False,
@@ -174,7 +227,7 @@ def create_datasheet(
) )
ref_workbook_name, new_workbook_name = get_workbook_names( ref_workbook_name, new_workbook_name = get_workbook_names(
files, batch_serial, path_, pattern files, batch_serial, write_dir, pattern
) )
template = Path(ref_workbook_name) template = Path(ref_workbook_name)

View File

@@ -1,25 +1,25 @@
dir,pattern,set_name,cells_to_clear,serial_cell,notes_cell dir,pattern,set_name,cells_to_clear,serial_cell,notes_cell
Production\QC Datasheet\1403\KRCY1100T Blue,KRCY1100T Blue [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRCY1100T Blue,KRCY1100T Blue [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRBK1300T Black,KRBK1300T Black [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRBK1300T Black,KRBK1300T Black [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRBK1314T Black,KRBK1314T Black [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12:I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRBK1314T Black,KRBK1314T Black [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12:I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRBR1200T Brown,KRBR1200T Brown [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRBR1200T Brown,KRBR1200T Brown [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRBR1201T Brown,KRBR1201T Brown [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRBR1201T Brown,KRBR1201T Brown [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRYL1400T Yellow,KRYL1400T Yellow [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRYL1400T Yellow,KRYL1400T Yellow [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRYL1401T Yellow,KRYL1401T Yellow [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRYL1401T Yellow,KRYL1401T Yellow [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRBG1600T Beige,KRBG1600T Beige [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRBG1600T Beige,KRBG1600T Beige [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRPK1500T Pink,KRPK1500T Pink [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRPK1500T Pink,KRPK1500T Pink [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25
Production\QC Datasheet\1403\KRHN1700T Honey,KRHN1700T Honey [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25 Production\QC Datasheet\[YEAR]\KRHN1700T Honey,KRHN1700T Honey [SERIAL].xlsx,Kimia Razi,"Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11",Batch!D3,Batch!D25
Quality control data sheet\2025\ICJ108 Beige,ICJ_108 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ108 Beige,ICJ_108 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2026\ICJ610 Black,ICJ_610 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ610 Black,ICJ_610 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2026\ICJ308 Blue,ICJ_308 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ308 Blue,ICJ_308 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2026\ICJEH680 Black,ICJ_EH680 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJEH680 Black,ICJ_EH680 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2026\ICJEH630 Black,ICJ_EH630 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJEH630 Black,ICJ_EH630 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2025\ICJEH600 Black,ICJ_EH600 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJEH600 Black,ICJ_EH600 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2025\ICJ407 Brown,ICJ_407 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D24 Quality control data sheet\[YEAR]\ICJ407 Brown,ICJ_407 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D24
Quality control data sheet\2025\ICJ408 Brown,ICJ_408 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D24 Quality control data sheet\[YEAR]\ICJ408 Brown,ICJ_408 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D24
Quality control data sheet\2026\ICJ435 Beige,ICJ_435 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D24 Quality control data sheet\[YEAR]\ICJ435 Beige,ICJ_435 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D24
Quality control data sheet\2025\ICJ107 Yellow,ICJ_107 yellow op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ107 Yellow,ICJ_107 yellow op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2025\ICJ703 Pink,ICJ_703 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ703 Pink,ICJ_703 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2024\ICJ309 Cyan,ICJ_309 cyan op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ309 Cyan,ICJ_309 cyan op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2025\ICJ109 Golden Yellow,ICJ_109 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ109 Golden Yellow,ICJ_109 op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
Quality control data sheet\2026\ICJ152 Yellow,ICJ_152 yellow op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25 Quality control data sheet\[YEAR]\ICJ152 Yellow,ICJ_152 yellow op. [SERIAL].xlsx,inco,"Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11",Batch!D3,Batch!D25
1 dir pattern set_name cells_to_clear serial_cell notes_cell
2 Production\QC Datasheet\1403\KRCY1100T Blue Production\QC Datasheet\[YEAR]\KRCY1100T Blue KRCY1100T Blue [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11 Batch!D3 Batch!D25
3 Production\QC Datasheet\1403\KRBK1300T Black Production\QC Datasheet\[YEAR]\KRBK1300T Black KRBK1300T Black [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11 Batch!D3 Batch!D25
4 Production\QC Datasheet\1403\KRBK1314T Black Production\QC Datasheet\[YEAR]\KRBK1314T Black KRBK1314T Black [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!G12:I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11 Batch!D3 Batch!D25
5 Production\QC Datasheet\1403\KRBR1200T Brown Production\QC Datasheet\[YEAR]\KRBR1200T Brown KRBR1200T Brown [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11 Batch!D3 Batch!D25
6 Production\QC Datasheet\1403\KRBR1201T Brown Production\QC Datasheet\[YEAR]\KRBR1201T Brown KRBR1201T Brown [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11 Batch!D3 Batch!D25
7 Production\QC Datasheet\1403\KRYL1400T Yellow Production\QC Datasheet\[YEAR]\KRYL1400T Yellow KRYL1400T Yellow [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11 Batch!D3 Batch!D25
8 Production\QC Datasheet\1403\KRYL1401T Yellow Production\QC Datasheet\[YEAR]\KRYL1401T Yellow KRYL1401T Yellow [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11 Batch!D3 Batch!D25
9 Production\QC Datasheet\1403\KRBG1600T Beige Production\QC Datasheet\[YEAR]\KRBG1600T Beige KRBG1600T Beige [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11 Batch!D3 Batch!D25
10 Production\QC Datasheet\1403\KRPK1500T Pink Production\QC Datasheet\[YEAR]\KRPK1500T Pink KRPK1500T Pink [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11 Batch!D3 Batch!D25
11 Production\QC Datasheet\1403\KRHN1700T Honey Production\QC Datasheet\[YEAR]\KRHN1700T Honey KRHN1700T Honey [SERIAL].xlsx Kimia Razi Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11 Batch!D3 Batch!D25
12 Quality control data sheet\2025\ICJ108 Beige Quality control data sheet\[YEAR]\ICJ108 Beige ICJ_108 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
13 Quality control data sheet\2026\ICJ610 Black Quality control data sheet\[YEAR]\ICJ610 Black ICJ_610 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
14 Quality control data sheet\2026\ICJ308 Blue Quality control data sheet\[YEAR]\ICJ308 Blue ICJ_308 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
15 Quality control data sheet\2026\ICJEH680 Black Quality control data sheet\[YEAR]\ICJEH680 Black ICJ_EH680 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
16 Quality control data sheet\2026\ICJEH630 Black Quality control data sheet\[YEAR]\ICJEH630 Black ICJ_EH630 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
17 Quality control data sheet\2025\ICJEH600 Black Quality control data sheet\[YEAR]\ICJEH600 Black ICJ_EH600 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
18 Quality control data sheet\2025\ICJ407 Brown Quality control data sheet\[YEAR]\ICJ407 Brown ICJ_407 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D24
19 Quality control data sheet\2025\ICJ408 Brown Quality control data sheet\[YEAR]\ICJ408 Brown ICJ_408 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D24
20 Quality control data sheet\2026\ICJ435 Beige Quality control data sheet\[YEAR]\ICJ435 Beige ICJ_435 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D24
21 Quality control data sheet\2025\ICJ107 Yellow Quality control data sheet\[YEAR]\ICJ107 Yellow ICJ_107 yellow op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
22 Quality control data sheet\2025\ICJ703 Pink Quality control data sheet\[YEAR]\ICJ703 Pink ICJ_703 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
23 Quality control data sheet\2024\ICJ309 Cyan Quality control data sheet\[YEAR]\ICJ309 Cyan ICJ_309 cyan op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
24 Quality control data sheet\2025\ICJ109 Golden Yellow Quality control data sheet\[YEAR]\ICJ109 Golden Yellow ICJ_109 op. [SERIAL].xlsx inco Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25
25 Quality control data sheet\2026\ICJ152 Yellow Quality control data sheet\[YEAR]\ICJ152 Yellow ICJ_152 yellow op. [SERIAL].xlsx inco Batch!F2:F3,Batch!I12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11 Batch!D3 Batch!D25

View File

@@ -394,6 +394,7 @@
</div> </div>
<p class="subtitle">Create a new QC datasheet from the latest matching workbook.</p> <p class="subtitle">Create a new QC datasheet from the latest matching workbook.</p>
<form id="create-form">
<div class="fields"> <div class="fields">
<label class="field combobox" for="set-dropdown-input"> <label class="field combobox" for="set-dropdown-input">
<span id="set-label" class="field-label">Select Set</span> <span id="set-label" class="field-label">Select Set</span>
@@ -438,7 +439,8 @@
</div> </div>
<div class="divider"></div> <div class="divider"></div>
<button id="create-button" type="button">Create datasheet</button> <button id="create-button" type="submit">Create datasheet</button>
</form>
<div id="status" class="status status-ready" role="status">Loading configuration...</div> <div id="status" class="status status-ready" role="status">Loading configuration...</div>
<p id="version" class="version"></p> <p id="version" class="version"></p>
</section> </section>
@@ -452,6 +454,7 @@
const setPanel = document.getElementById("set-dropdown-panel"); const setPanel = document.getElementById("set-dropdown-panel");
const inkPanel = document.getElementById("ink-dropdown-panel"); const inkPanel = document.getElementById("ink-dropdown-panel");
const serialInput = document.getElementById("serial-input"); const serialInput = document.getElementById("serial-input");
const createForm = document.getElementById("create-form");
const createBtn = document.getElementById("create-button"); const createBtn = document.getElementById("create-button");
const status = document.getElementById("status"); const status = document.getElementById("status");
const themeToggle = document.getElementById("theme-toggle"); const themeToggle = document.getElementById("theme-toggle");
@@ -738,7 +741,7 @@
} }
}); });
createBtn.addEventListener("click", async () => { async function createDatasheet() {
createBtn.disabled = true; createBtn.disabled = true;
try { try {
const result = await window.pywebview.api.create( const result = await window.pywebview.api.create(
@@ -750,6 +753,11 @@
} finally { } finally {
createBtn.disabled = false; createBtn.disabled = false;
} }
}
createForm.addEventListener("submit", async (event) => {
event.preventDefault();
await createDatasheet();
}); });
window.addEventListener("pywebviewready", initialize); window.addEventListener("pywebviewready", initialize);

79
tests/test_core.py Normal file
View File

@@ -0,0 +1,79 @@
from pathlib import Path
import pytest
from xlsx_clean.core import resolve_write_year_dir, resolve_year_dir
def _touch(path: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(b"")
def test_resolve_year_picks_largest_dir_with_matching_sheet(tmp_path: Path):
pattern = "ICJ_108 op. [SERIAL].xlsx"
_touch(tmp_path / "2025" / "ICJ108 Beige" / "ICJ_108 op. 1.xlsx")
_touch(tmp_path / "2026" / "ICJ108 Beige" / "ICJ_108 op. 2.xlsx")
placeholder = tmp_path / "[YEAR]" / "ICJ108 Beige"
assert resolve_year_dir(placeholder, pattern) == tmp_path / "2026" / "ICJ108 Beige"
def test_resolve_year_ignores_larger_empty_year(tmp_path: Path):
pattern = "ICJ_108 op. [SERIAL].xlsx"
_touch(tmp_path / "2025" / "ICJ108 Beige" / "ICJ_108 op. 1.xlsx")
(tmp_path / "2026" / "ICJ108 Beige").mkdir(parents=True)
placeholder = tmp_path / "[YEAR]" / "ICJ108 Beige"
assert resolve_year_dir(placeholder, pattern) == tmp_path / "2025" / "ICJ108 Beige"
def test_resolve_year_jalali_style(tmp_path: Path):
pattern = "KRCY1100T Blue [SERIAL].xlsx"
_touch(tmp_path / "1402" / "KRCY1100T Blue" / "KRCY1100T Blue 1.xlsx")
_touch(tmp_path / "1403" / "KRCY1100T Blue" / "KRCY1100T Blue 2.xlsx")
placeholder = tmp_path / "[YEAR]" / "KRCY1100T Blue"
assert resolve_year_dir(placeholder, pattern) == tmp_path / "1403" / "KRCY1100T Blue"
def test_resolve_year_passthrough_without_token(tmp_path: Path):
path = tmp_path / "2025" / "ICJ108 Beige"
assert resolve_year_dir(path, "x [SERIAL].xlsx") == path
def test_resolve_year_fails_when_no_sheets(tmp_path: Path):
(tmp_path / "2026" / "ICJ108 Beige").mkdir(parents=True)
with pytest.raises(FileNotFoundError, match="No year directory"):
resolve_year_dir(tmp_path / "[YEAR]" / "ICJ108 Beige", "ICJ_108 op. [SERIAL].xlsx")
def test_resolve_write_year_picks_largest_even_if_empty(tmp_path: Path):
_touch(tmp_path / "2025" / "ICJ108 Beige" / "ICJ_108 op. 1.xlsx")
(tmp_path / "2026").mkdir()
placeholder = tmp_path / "[YEAR]" / "ICJ108 Beige"
assert resolve_write_year_dir(placeholder) == tmp_path / "2026" / "ICJ108 Beige"
def test_resolve_write_year_jalali_style(tmp_path: Path):
(tmp_path / "1402").mkdir()
(tmp_path / "1403").mkdir()
placeholder = tmp_path / "[YEAR]" / "KRCY1100T Blue"
assert resolve_write_year_dir(placeholder) == tmp_path / "1403" / "KRCY1100T Blue"
def test_resolve_write_year_passthrough_without_token(tmp_path: Path):
path = tmp_path / "2025" / "ICJ108 Beige"
assert resolve_write_year_dir(path) == path
def test_resolve_write_year_fails_when_no_digit_dirs(tmp_path: Path):
(tmp_path / "notes").mkdir()
with pytest.raises(FileNotFoundError, match="No year directory"):
resolve_write_year_dir(tmp_path / "[YEAR]" / "ICJ108 Beige")
def test_read_and_write_year_differ_when_sheets_only_in_older(tmp_path: Path):
pattern = "ICJ_108 op. [SERIAL].xlsx"
_touch(tmp_path / "2025" / "ICJ108 Beige" / "ICJ_108 op. 1.xlsx")
(tmp_path / "2026").mkdir()
placeholder = tmp_path / "[YEAR]" / "ICJ108 Beige"
assert resolve_year_dir(placeholder, pattern) == tmp_path / "2025" / "ICJ108 Beige"
assert resolve_write_year_dir(placeholder) == tmp_path / "2026" / "ICJ108 Beige"

View File

@@ -21,6 +21,8 @@ def test_ui_asset_exists_and_has_required_bridge_content():
'id="set-label"', 'id="set-label"',
'id="ink-label"', 'id="ink-label"',
'id="serial-label"', 'id="serial-label"',
'id="create-form"',
'id="create-button" type="submit"',
"Create datasheet", "Create datasheet",
"status-ready", "status-ready",
"status-success", "status-success",
@@ -31,6 +33,7 @@ def test_ui_asset_exists_and_has_required_bridge_content():
"get_initial_data()", "get_initial_data()",
"get_inks(setDropdown.value)", "get_inks(setDropdown.value)",
"api.create(", "api.create(",
'createForm.addEventListener("submit"',
"finally", "finally",
'inputEl.value = selectEl.value || ""', 'inputEl.value = selectEl.value || ""',
'inputEl.addEventListener("mousedown", () => {\n open();\n });', 'inputEl.addEventListener("mousedown", () => {\n open();\n });',