Files

148 lines
5.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""v1.0.59 回归:称重/确认界面显示标准商品名(不再是下单写法)
现场反馈:称重选项卡显示的商品名应该是标准商品名,不是下单的名字。
服务端分拣待办行一直带着 standard_name(COALESCE(sku_name, catalog.name)),
客户端没用它 —— 确认条/免称重核对页/人工确认页全显示 item_name
(客户下单写法,如「上海青(小棠菜)」)。现在大字报标准名,
下单名与标准名不同时小字对照;搜索两个名字都能命中;
记账/标签仍按下单名提交(口径不变)。
本文件锁死:
A. _std_name:有 standard_name 用它;空了退 item_name;再空 '—'
B. 确认条标题 = 标准名;下单名不同 → meta 里带「下单名「…」」
C. 下单名 = 标准名时不加对照(不重复占行)
D. 提交口径不变:记录里的 name 仍是 item_name(显示层才换)
E. 免称重核对/人工确认列表的搜索:标准名、下单名都命中
"""
import io
import os
import sys
import time
import tkinter as tk
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
sys.path.insert(0, ROOT)
os.chdir(ROOT)
from ui import app as A # noqa: E402
A.App._poll = lambda self: None
A.App._poll_preview = lambda self: None
ok = fail = 0
def check(name, cond, extra=''):
global ok, fail
if cond:
ok += 1
print(' ✔ %s' % name)
else:
fail += 1
print(' ✘ %s %s' % (name, extra))
print('A _std_name:标准名优先,退回下单名')
S = A.App._std_name
check('带 standard_name → 用标准名',
S({'item_name': '上海青(小棠菜)', 'standard_name': '上海青'})
== '上海青')
check('没有 standard_name → 退下单名',
S({'item_name': '大白菜'}) == '大白菜')
check('standard_name 是空白 → 退下单名',
S({'item_name': '大白菜', 'standard_name': ' '}) == '大白菜')
check('两个都没有 → —', S({}) == '—')
check('空行 → —', S(None) == '—')
BASE = {
'flow': {'min_scale_kg': 0.05, 'stable_ms': 400, 'settle_ms': 650,
'stable_delta_kg': 0.03, 'done_timeout_s': 12,
'done_lift_off_kg': 0.2, 'confirm_before_submit': True,
'auto_submit': True, 'same_name_auto': True,
'merge_same_name': True, 'over_receipt_ratio': 3,
'weight_pick_pct': 40, 'stocked_block_s': 300},
'scale': {'simulate': True},
'camera': {'simulate': True},
'vision': {'min_confidence': 60, 'auto_over_pct': 30,
'prompt_source': 'local'},
'noweigh': {'picking_allow_weight_unit': True},
'ui': {'mode': 'window', 'fit_screen': False, 'borderless': False,
'todo_thumb': False, 'width': 1440, 'height': 900,
'todo_group': 'none'},
}
A.load_config = lambda path='config.json', _c=BASE: _c
root = tk.Tk()
app = A.App(root)
root.geometry('1440x900+0+0')
for c in root.winfo_children():
c.destroy()
app._build()
root.update_idletasks()
root.update()
def row(rid, name, std, who, qty=10.0, unit='斤'):
r = {'id': rid, 'item_name': name, 'unit': unit,
'required_qty': qty, 'remaining_qty': qty,
'customer_name': who, 'order_code': 'ORD_' + rid}
if std is not None:
r['standard_name'] = std
return r
rws = [row('R01', '上海青(小棠菜)', '上海青', '客户A', 10.0),
row('R02', '大白菜', None, '客户A', 12.0)]
app._fill_todo(rws)
for _ in range(20):
root.update()
time.sleep(0.01)
root.update_idletasks()
root.update()
print('B/C 待确认提示行:标准名在前,下单名放对照')
app._on_focus({'row_id': 'R01', 'row': rws[0], 'mode': 'weigh',
'detected': '上海青(小棠菜)', 'conf': 92,
'weight': 4.4, 'business': 8.8, 'unit': '斤'})
root.update_idletasks()
hint = str(app.lbl_hint.cget('text') or '')
check('提示行用标准名「上海青」', hint.startswith('上海青 ·'), hint)
check('提示行带下单名对照', '下单名「上海青(小棠菜)」' in hint, hint)
app._on_focus({'row_id': 'R02', 'row': rws[1], 'mode': 'weigh',
'detected': '大白菜', 'conf': 95,
'weight': 5.0, 'business': 10.0, 'unit': '斤'})
root.update_idletasks()
hint2 = str(app.lbl_hint.cget('text') or '')
check('下单名与标准名一致 → 不加对照行', '下单名' not in hint2, hint2)
app._on_focus({'row_id': None, 'row': {}, 'mode': 'weigh',
'detected': '', 'weight': 0, 'business': 0, 'unit': '斤'})
root.update_idletasks()
check('没选商品仍提示待点行',
'没认出' in str(app.lbl_hint.cget('text') or ''),
app.lbl_hint.cget('text'))
app._on_focus_clear()
root.update_idletasks()
print('D 提交口径不变:行上的 item_name 原样进记录')
rec_row = dict(rws[0])
app._focus_p = {'row_id': 'R01', 'row': rec_row, 'mode': 'weigh'}
check('行对象没被改(item_name 仍是下单名)',
rec_row['item_name'] == '上海青(小棠菜)')
check('显示层才换:todo 卡上的名字不变',
app.todo_cards['R01']._name_lbl.cget('text') == '上海青(小棠菜)')
print('E 两个名字都能搜到(核对页过滤逻辑同款)')
hay = lambda r: ' '.join([str(r.get('item_name') or ''),
str(r.get('standard_name') or '')]).lower()
check('搜下单名命中', '小棠菜' in hay(rws[0]))
check('搜标准名命中', '上海青' in hay(rws[0]))
check('搜别的名不命中', '土豆' not in hay(rws[0]))
root.destroy()
print('\n%d 过 / %d 挂' % (ok, fail))
sys.exit(1 if fail else 0)