- VBS и Python: в итоговом CSV код КИЗ обрезается до первых 31 символа (код без криптохвоста: 01 + GTIN + 21 + серийный номер); более короткий код остаётся как есть, с замечанием в отчёте. Копия kiz_to_csv.py в портативном комплекте обновлена так же. - README.md: инструкция на русском, переписана проще и яснее; Инструкция_экспорт_CSV.docx пересобрана из того же текста, с настоящими заголовками и списками. - AGENTS.md, CLAUDE.md, .agents/ (скилл kiz-testing, папки plans и reports). - .gitignore для .DS_Store; .gitattributes хранит файлы без изменения концов строк (.bat и .vbs нужны CRLF). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
3.6 KiB
Markdown
63 lines
3.6 KiB
Markdown
---
|
|
name: kiz-testing
|
|
description: How to test the KIZ -> CSV scripts (VBS and Python) with fake invoice and KIZ files, and what to check in the resulting CSV and report.
|
|
---
|
|
|
|
# Testing the KIZ -> CSV scripts
|
|
|
|
There is no automated test suite. Test by generating fake input files, running the script, and checking the CSV and the report by eye and with a short script.
|
|
|
|
## Where things run
|
|
|
|
- **Python** (`obrabotka_kiz_python/kiz_to_csv.py`) runs on any OS. It needs `openpyxl`. If it is not installed, use the copy shipped in the portable kit:
|
|
`PYTHONPATH=obrabotka_kiz_python/KIZ_portable_Win7/python/Lib/site-packages python3 ...`
|
|
- **VBS** (`obrabotka_kiz_vb/xlsx_to_csv_utf8.vbs`) runs only on Windows with Excel installed (it drives Excel through COM). On Linux/Mac it cannot be run: test the Python version and give the user the same fake files and the expected CSV to compare on Windows.
|
|
|
|
Both scripts must produce the same CSV content for the same input (the VBS file starts with a UTF-8 BOM, the Python file does not). Any change to the algorithm goes into both, and into the copy `obrabotka_kiz_python/KIZ_portable_Win7/kiz_to_csv.py` (it must stay identical to `obrabotka_kiz_python/kiz_to_csv.py`).
|
|
|
|
## Fake input files
|
|
|
|
Put them in a temporary folder, never in the repo. The sample files in the repo root (`Куропятник.xlsx`, `Книга1.xlsx`) show the real layouts, but `Куропятник.xlsx` has no GTINs in column B, so nothing matches with it.
|
|
|
|
```python
|
|
import openpyxl, sys
|
|
d = sys.argv[1]
|
|
# invoice (file 1): goods from row 19, B = "name GTIN", K = qty, L = price, N = VAT
|
|
wb = openpyxl.Workbook(); ws = wb.active
|
|
rows = [("Мишка с сердцем 22см 04640720990098", 3, 358.18, 10),
|
|
("Кролик в шарфе 4640720990111", 1, 436.37, 20)]
|
|
for i, (b, k, l, n) in enumerate(rows, start=19):
|
|
ws.cell(i, 1, i - 18); ws.cell(i, 2, b); ws.cell(i, 11, k); ws.cell(i, 12, l); ws.cell(i, 14, n)
|
|
wb.save(d + "/nakl.xlsx")
|
|
# KIZ file (file 2): codes in the last filled column (H), text format
|
|
wb = openpyxl.Workbook(); ws = wb.active
|
|
kiz = ["01046407209900982151B+-h6cMAOOb91EE1292vCB/qXHt4iD3Rilqesef3ITNwAAaBVALGwGuFASGU+E=",
|
|
'01046407209900982154Jcb6ZtF"NPK91EE1292fUJhZxhh7qKJZaHjU+Em+7hIA4u4Ei64ilySLnpMyDc=',
|
|
"0104640720990098215KK,kKKkKkKKK91EE1292abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGH=",
|
|
"0104640720990111215ZZZZZZZZZZZZ91EE1292zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=",
|
|
"01046407209901112155HORT"]
|
|
for i, k in enumerate(kiz, start=1):
|
|
ws.cell(i, 1, i); ws.cell(i, 8, k).number_format = "@"
|
|
wb.save(d + "/kiz.xlsx")
|
|
```
|
|
|
|
The set covers: a normal code, a code with a `"` in the serial, a code with a `,` in the serial, a second product with a quantity mismatch, and a code shorter than 31 characters.
|
|
|
|
Run: `python3 obrabotka_kiz_python/kiz_to_csv.py <dir>/nakl.xlsx <dir>/kiz.xlsx` (two arguments = no file dialogs).
|
|
|
|
## What to check
|
|
|
|
- `<dir>/kiz.csv`: UTF-8, CRLF line ends, comma separator; B..G filled (name, price with a dot, `1`, `796`, VAT with `%`, `КИЗ`).
|
|
- Last column: each KIZ is cut to its first 31 characters (`01` + 14-digit GTIN + `21` + 13-character serial); a code with a comma is wrapped in double quotes; a shorter code is left unchanged.
|
|
- `<dir>/kiz_report.txt`: an OK line for the matching product, a "НЕ СОВПАДАЕТ" (quantity mismatch) line for the other, and a "КИЗ короче 31 символов" line for the short code.
|
|
|
|
Quick length check:
|
|
|
|
```bash
|
|
python3 -c "import csv; print([len(r[-1]) for r in csv.reader(open('<dir>/kiz.csv', encoding='utf-8'))])"
|
|
```
|
|
|
|
Expected for the set above: `[31, 31, 31, 31, 24]`.
|
|
|
|
Delete the temporary folder when done.
|