diff --git a/README.md b/README.md index 28b3972..73e3db6 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ python -m app.fill_consumable_doc --no-backup # 不生成 .doc.bak 备份 填写规则概要: +- 表头「日期」使用**填写当天**的日期(非发票开票日期) - 从 `规格型号` 解析品名、规格、单位、数量、单价;`价税合计` 写入金额列 - 单价/金额保留两位小数;表格内统一为 **宋体五号(10.5 磅)** - 存放地点取自 `consumable_storage`;购货人/领用人签字、备注保持空白 @@ -201,7 +202,6 @@ python web/app.py ## 注意事项 - 浏览器填报时会打开或使用 Chromium,请勿手动干扰自动化流程 -- 首次运行可能需要处理 SSO 登录(已保存会话时可跳过) - 调试截图保存在 `images/` 目录 - OCR 不会覆盖 CSV 中已有非空字段 - 项目根目录需保留 `易耗品、出库单.doc` 模板;Web 每次从模板复制到会话目录再填写,不修改原模板 diff --git a/app/fill_consumable_doc.py b/app/fill_consumable_doc.py index 38c2a0b..8a7495c 100644 --- a/app/fill_consumable_doc.py +++ b/app/fill_consumable_doc.py @@ -9,6 +9,7 @@ from __future__ import annotations import argparse import re import shutil +from datetime import date from pathlib import Path from . import get_logger @@ -79,14 +80,10 @@ def _format_money(value: str | float) -> str: return f"{num:.2f}" -def _format_cn_date(date_str: str) -> str: - if not date_str: - return "" - parts = date_str.replace("-", "/").split("/") - if len(parts) != 3: - return date_str - y, m, d = parts[0], str(int(parts[1])), str(int(parts[2])) - return f"{y}年{m}月{d}日" +def _today_cn_date() -> str: + """当前日期,格式:2026年5月26日""" + today = date.today() + return f"{today.year}年{today.month}月{today.day}日" def _apply_font(rng) -> None: @@ -159,9 +156,7 @@ def fill_consumable_doc( doc = word.Documents.Open(str(doc_path.resolve())) try: - if invoices: - cn_date = _format_cn_date(invoices[0].get("invoice_date", "")) - _replace_date_in_doc(doc, cn_date) + _replace_date_in_doc(doc, _today_cn_date()) tbl = doc.Tables(1) storage = config.get("consumable_storage", "躬行楼 C205") @@ -172,11 +167,16 @@ def fill_consumable_doc( break parsed = parse_spec_model(inv.get("spec_model", "")) - amount = _format_money(inv.get("total_amount", "")) - unit_price = _format_money(parsed["unit_price"]) - qty = parsed["qty"] - if qty and qty.isdigit(): - qty = str(int(qty)) + card_amount = inv.get("card_amount") or 0 + qty_str = parsed["qty"] + qty_val = int(qty_str) if qty_str and qty_str.isdigit() else 0 + + # 金额填写刷卡金额,单价由刷卡金额反算 + amount = _format_money(card_amount) + unit_price = _format_money(card_amount / qty_val) if qty_val > 0 else _format_money(card_amount) + + # 数量:去掉前导零 + qty = str(qty_val) if qty_val > 0 else "" values = [ str(inv.get("seq", i + 1)), diff --git a/易耗品、出库单.doc b/易耗品、出库单.doc index d683b75..25d541c 100644 Binary files a/易耗品、出库单.doc and b/易耗品、出库单.doc differ