dy-dashboard/services/planning_order_flag.py
2026-10-28 11:14:17 +08:00

21 lines
953 B
Python

"""Manual new/old choice, independent of the calculated product-age field."""
from services.db import query
def normalize_new_old(value, default='旧品'):
"""Return the canonical labels used by planning and overseas orders.
``是/否`` was the original storage format. Keep accepting it while old
rows are being migrated so historical pending/order records remain usable.
"""
value = str(value or '').strip()
return {'是': '新品', '否': '旧品', '新品': '新品', '旧品': '旧品'}.get(value, default)
def snapshot_new_old(product_code, saved_value=None):
"""Preserve an existing pending snapshot during quantity/remark edits."""
if saved_value in ('是', '否', '新品', '旧品'):
return normalize_new_old(saved_value)
rows = query('SELECT planning_new_old FROM products WHERE product_code=%s', (product_code,))
return normalize_new_old(rows[0].get('planning_new_old') if rows else '')