From 33efc7c846cc2aaf49f8f418b3ebbf69eb12ad6e Mon Sep 17 00:00:00 2001 From: star <395723461@qq.com> Date: Wed, 23 Sep 2026 14:21:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=A5=E5=BA=93=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E3=80=8C=E9=80=81=E8=B4=A7=E6=97=A5=E6=9C=9F=E3=80=8D=E5=AD=97?= =?UTF-8?q?=E6=AE=B5(=E4=B8=8E=E4=B8=9A=E5=8A=A1=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E5=8C=BA=E5=88=86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - models.Inbound 增加 delivery_date 列(可空, 默认 None) - 入库单笔录入表单新增「送货日期」输入(默认当天, 可改供应商实际到货日); 出库不受影响 - 物料明细页入库流水新增「送货日期」列展示 - seed_admin 增加幂等补列: 旧库启动时自动 ALTER TABLE inbound ADD COLUMN delivery_date, 开发/EXE 均兼容 - 教程补充送货日期字段说明 (注: instance/app.db 已本地补列, 但未纳入本次提交; dist/app.db 为运行库已 gitignore) --- app.py | 12 ++++++++++++ models.py | 1 + templates/material_detail.html | 5 +++-- templates/txn.html | 2 ++ 物料入库出库系统_使用教程.md | 4 ++-- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index a9a1023..46c0768 100644 --- a/app.py +++ b/app.py @@ -430,11 +430,14 @@ def inbound(): if qty <= 0: flash("入库数量必须大于 0", "error") else: + dlv = request.form.get("delivery_date", "").strip() + delivery_date = _date(dlv) if dlv else None rec = Inbound( material_id=mid, batch_no=request.form.get("batch_no", ""), qty=qty, operator=request.form.get("operator", ""), source=request.form.get("source", ""), occur_date=_date(request.form.get("occur_date")), + delivery_date=delivery_date, remark=request.form.get("remark", "")) db.session.add(rec) db.session.commit() @@ -1009,6 +1012,15 @@ def api_import_boms_commit(): def seed_admin(): with app.app_context(): db.create_all() + # 兼容旧库: 给 inbound 表补充 delivery_date 列(幂等) + try: + cols = [r[1] for r in db.session.execute( + db.text("PRAGMA table_info(inbound)")).fetchall()] + if "delivery_date" not in cols: + db.session.execute(db.text("ALTER TABLE inbound ADD COLUMN delivery_date DATE")) + db.session.commit() + except Exception: + db.session.rollback() if not db.session.scalar(db.select(User).where(User.username == "admin")): db.session.add(User(username="admin", password=sha256("admin123"), role="admin", display_name="管理员")) diff --git a/models.py b/models.py index ea5fe99..33bb717 100644 --- a/models.py +++ b/models.py @@ -49,6 +49,7 @@ class Inbound(db.Model): operator = db.Column(db.String(64), default="") # 经手人 source = db.Column(db.String(255), default="") # 来源 / 供应商 occur_date = db.Column(db.Date, default=date.today) + delivery_date = db.Column(db.Date, default=None) # 送货日期(供应商到货日, 可空) remark = db.Column(db.String(255), default="") created_at = db.Column(db.DateTime, default=datetime.now) diff --git a/templates/material_detail.html b/templates/material_detail.html index 5f04668..4b8cd4e 100644 --- a/templates/material_detail.html +++ b/templates/material_detail.html @@ -29,11 +29,12 @@
| 入库日期 | 录入时间 | 数量 | 批次号 | 来源 / 供应商 | 经手人 | 备注 | |
|---|---|---|---|---|---|---|---|
| 入库日期 | 送货日期 | 录入时间 | 数量 | 批次号 | 来源 / 供应商 | 经手人 | 备注 |
| {{ r.occur_date }} | +{{ r.delivery_date or '-' }} | {{ r.created_at.strftime('%Y-%m-%d %H:%M') if r.created_at else '-' }} | {{ '%.2f'|format(r.qty) }} | {{ r.batch_no or '-' }} | @@ -42,7 +43,7 @@{{ r.remark or '-' }} | ||
| 暂无入库记录 | |||||||
| 暂无入库记录 | |||||||