317 lines
11 KiB
Python
317 lines
11 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""v1.0.56 回归:手动选择的标签按秤印 + 名单滑动不卡
|
|
|
|
现场两条反馈:
|
|
①「手动选择的时候没有按照称的重量进行打印标签」
|
|
—— 免称重那一轮 AI 没认出来,操作员自己在右边点了名单里的某一行。
|
|
原来这条路只给「行应量」(5.00 斤),秤上其实是 5.62 斤:记账按
|
|
应量、标签按秤,同一件货两个数。另外界面在数件一行上总会把输入框
|
|
的值传回来,哪怕一个字没改 —— 只要点「确认记账」就被当成人工填数,
|
|
秤上读数又被丢掉。
|
|
②「滑动商品的时候不流畅」
|
|
—— 点一下卡片要遍历整张名单改高亮(120 行 35ms,现场 100ms+),
|
|
确认条一弹出右列高度变、canvas Configure 又把 120 张卡重排一遍
|
|
(168ms);滚轮一格只走 3px(内容 5595px 的 0.1%),滚十几下才动
|
|
一屏。
|
|
|
|
本文件锁死:
|
|
A. 免称重手点行 → 记账量与标签量都按秤(5.62 斤),不再用行应量
|
|
B. 界面把「没改过的数量」传回来,不算人工填数(仍按秤)
|
|
C. 真的改了数字 → 就按人填的(这是人的明确指定,不能又被秤盖回去)
|
|
D. 秤上没货 / 按件计量 → 仍按待办数量(不许把 0.00 印上去)
|
|
E. 称重路径的「人工确认弹窗选行」一直就是按秤的(防回归)
|
|
F. 点卡片只重画变化的那两张(不遍历全名单)
|
|
G. 拖动滚名单时松手不把手指停住的那张卡选中
|
|
H. 滚轮一格走约四分之一屏(不再是 3px)
|
|
I. 列数没变时 _layout_cards 不做第二次重排(确认条弹出/滚动不再卡)
|
|
"""
|
|
import io
|
|
import json
|
|
import os
|
|
import queue
|
|
import sys
|
|
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 core import flow as F # noqa: E402
|
|
from core.matching import engine as M # noqa: E402
|
|
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))
|
|
|
|
|
|
# ---------------------------------------------------------------- 引擎侧
|
|
CFG = {
|
|
'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},
|
|
'scale': {'simulate': True},
|
|
'camera': {'simulate': True},
|
|
'vision': {'min_confidence': 60, 'auto_over_pct': 30,
|
|
'same_kind_guard': False},
|
|
'server': {'mock': True},
|
|
'printer': {'enabled': True, 'printer_name': '测试机'},
|
|
'noweigh': {'picking_allow_weight_unit': True},
|
|
}
|
|
|
|
REAL_KG = 2.81
|
|
REAL_JIN = 5.62
|
|
ASKED = 5.00
|
|
|
|
|
|
def new_eng(unit='斤', weight=REAL_KG):
|
|
ev = []
|
|
e = F.FlowEngine(CFG, lambda k, p=None: ev.append((k, p)))
|
|
e.refresh_pending = lambda initial=False: None
|
|
e.station = 'picking'
|
|
e.logged_in = True
|
|
e._running = True
|
|
e.server_config = {'weigh_match_tolerance_mode': 'percent',
|
|
'weigh_match_tolerance_value': 0}
|
|
e._print_enabled = lambda: True
|
|
e.rows = [{'id': 'ROW1', 'item_name': '香菇', 'unit': unit,
|
|
'required_qty': ASKED, 'remaining_qty': ASKED,
|
|
'order_code': 'ORD1',
|
|
'container_code': 'CT-TEST-1056'}]
|
|
e._last_st = {'present': weight > 0, 'fresh': True, 'weight': weight}
|
|
e.confirm_before_submit = lambda: True
|
|
e.submit_on_remove = lambda: False
|
|
e._start_submit = lambda row, biz, src: setattr(
|
|
e, '_caught', (row, biz, src))
|
|
return e
|
|
|
|
|
|
def label_qty(e, row, business):
|
|
e._print_q = queue.Queue()
|
|
e._print_async(row, business)
|
|
it = e._print_q.get_nowait()
|
|
return e._label_qty(row, it['business'], it['kg'], row.get('unit'))
|
|
|
|
|
|
print('A 免称重·AI 认不出 → 操作员手点名单某行')
|
|
e = new_eng()
|
|
row = e.rows[0]
|
|
e._count_mode = True
|
|
e._frozen_kg = 0.0
|
|
e._to_focus(None, 0.0, detected=None, conf=None, mode='count',
|
|
candidates=[], auto=False)
|
|
e.state = 'CONFIRM'
|
|
e.pick_focus('ROW1')
|
|
f = e._focus or {}
|
|
check('选中行后数量取秤上实际重量', abs(float(f.get('business') or 0) - REAL_JIN) < 0.01,
|
|
f.get('business'))
|
|
check('标记为「按秤上实际重量」', bool(f.get('from_scale')), f.get('from_scale'))
|
|
e.confirm_focus(None)
|
|
_, biz, _ = e._caught
|
|
check('提交量也是秤上实际重量', abs(biz - REAL_JIN) < 0.01, biz)
|
|
check('标签量是秤上实际重量', abs(label_qty(e, row, biz) - REAL_JIN) < 0.01)
|
|
|
|
print('B 界面把没改过的数量传回来(不是人工填数)')
|
|
e = new_eng()
|
|
row = e.rows[0]
|
|
e._count_mode = True
|
|
e._frozen_kg = 0.0
|
|
e._to_focus(row, ASKED, detected='香菇', conf=90, mode='count',
|
|
candidates=[row], auto=True)
|
|
e.state = 'CONFIRM'
|
|
e.confirm_focus(float((e._focus or {}).get('business') or 0)) # UI 原样回传
|
|
_, biz, _ = e._caught
|
|
check('原样回传仍按秤记账', abs(biz - REAL_JIN) < 0.01, biz)
|
|
check('秤读数字段没被清掉', float(getattr(e, '_count_real_kg', 0) or 0) > 0.1,
|
|
getattr(e, '_count_real_kg', None))
|
|
check('标签也按秤', abs(label_qty(e, row, biz) - REAL_JIN) < 0.01)
|
|
|
|
print('C 真的改了数字 → 按人填的')
|
|
e = new_eng()
|
|
row = e.rows[0]
|
|
e._count_mode = True
|
|
e._frozen_kg = 0.0
|
|
e._to_focus(row, ASKED, detected='香菇', conf=90, mode='count',
|
|
candidates=[row], auto=True)
|
|
e.state = 'CONFIRM'
|
|
e.confirm_focus(3.0)
|
|
_, biz, _ = e._caught
|
|
check('提交量按人填的 3.00', abs(biz - 3.0) < 0.01, biz)
|
|
check('标签也按人填的 3.00', abs(label_qty(e, row, biz) - 3.0) < 0.01)
|
|
check('人填数时不再用秤读数', float(getattr(e, '_count_real_kg', 0) or 0) == 0.0,
|
|
getattr(e, '_count_real_kg', None))
|
|
|
|
print('D 秤上没货 / 按件计量 → 仍按待办数量')
|
|
e = new_eng(weight=0)
|
|
row = e.rows[0]
|
|
e._count_mode = True
|
|
e._frozen_kg = 0.0
|
|
e._to_focus(None, 0.0, detected=None, conf=None, mode='count',
|
|
candidates=[], auto=False)
|
|
e.state = 'CONFIRM'
|
|
e.pick_focus('ROW1') # 秤上是空的
|
|
f = e._focus or {}
|
|
check('空秤时数量仍按待办 5.00', abs(float(f.get('business') or 0) - ASKED) < 0.01,
|
|
f.get('business'))
|
|
check('空秤时不算「按秤」', not bool(f.get('from_scale')))
|
|
|
|
e = new_eng(unit='包', weight=0)
|
|
row = e.rows[0]
|
|
e._count_mode = True
|
|
e._to_focus(row, 8.0, detected='香菇', conf=90, mode='count',
|
|
candidates=[row], auto=True)
|
|
e.state = 'CONFIRM'
|
|
e.pick_focus('ROW1')
|
|
f = e._focus or {}
|
|
# 改判到按包的行:数量按这一行的待办量(5.00 包),秤读数不该插手
|
|
check('按包的行不被秤读数改写', abs(float(f.get('business') or 0) - ASKED) < 0.01,
|
|
f.get('business'))
|
|
|
|
print('E 称重路径·人工确认弹窗选行(分拣已改为必须点确认,这里测入库弹窗)')
|
|
e = new_eng()
|
|
row = e.rows[0]
|
|
e.station = 'inspection' # 分拣 manual_submit 已按设计拒绝,入库才走弹窗
|
|
e._count_mode = False
|
|
e._frozen_kg = REAL_KG
|
|
e.state = 'MANUAL'
|
|
e.manual_submit(row)
|
|
_, biz, _ = e._caught
|
|
check('弹窗选行按秤记账', abs(biz - REAL_JIN) < 0.01, biz)
|
|
check('标签也按秤', abs(label_qty(e, row, biz) - REAL_JIN) < 0.01)
|
|
|
|
# ---------------------------------------------------------------- 界面侧
|
|
BASE = json.load(open('config.json', encoding='utf-8'))
|
|
BASE.setdefault('ui', {})
|
|
BASE['ui'].update({'mode': 'window', 'fit_screen': False,
|
|
'borderless': False, 'todo_thumb': False,
|
|
'width': 1440, 'height': 900})
|
|
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()
|
|
|
|
rws = [{'id': 'R%03d' % i, 'item_name': '商品%d' % i, 'unit': '斤',
|
|
'required_qty': 10.0 + i, 'remaining_qty': 10.0 + i,
|
|
'spec': '20斤/件', 'customer_name': '客户%d' % i,
|
|
'order_code': 'ORD%03d' % i} for i in range(60)]
|
|
app._fill_todo(rws)
|
|
root.update_idletasks()
|
|
root.update()
|
|
check('60 行都建了卡片', len(app.todo_cards) == 60, len(app.todo_cards))
|
|
|
|
print('F 点卡片只重画变化的那两张')
|
|
calls = []
|
|
for k, c in app.todo_cards.items():
|
|
orig = c.configure
|
|
|
|
def spy(**kw):
|
|
calls.append(kw)
|
|
return None
|
|
try:
|
|
c.configure = spy
|
|
except Exception:
|
|
pass
|
|
calls[:] = []
|
|
app._select_card('R000')
|
|
root.update_idletasks()
|
|
n_first = len(calls)
|
|
app._select_card('R001')
|
|
n_second = len(calls) - n_first
|
|
check('首次选中只 configure ≤2 次', n_first <= 2, n_first)
|
|
check('换一行也只 configure ≤2 次', n_second <= 2, n_second)
|
|
for k, c in app.todo_cards.items():
|
|
try:
|
|
del c.configure
|
|
except Exception:
|
|
pass
|
|
|
|
print('G 名单不再拖动滚动(v1.0.58 起分页),误选防护交给 TapGate')
|
|
check('待办区不再挂 TouchScroll', app._todo_scroll is None)
|
|
app._sel_rid = 'R000'
|
|
app._select_card('R005')
|
|
check('正常点击仍能选中', app._sel_rid == 'R005', app._sel_rid)
|
|
|
|
print('H 滚轮 = 翻页(v1.0.58 起名单不滚动)')
|
|
app._page = 0
|
|
app._layout_key = None
|
|
app._layout_cards()
|
|
for _ in range(10):
|
|
root.update()
|
|
n_pages = app._page_count
|
|
check('60 行名单超过一页', n_pages > 1, n_pages)
|
|
|
|
|
|
class _E:
|
|
delta = -120
|
|
|
|
|
|
app._page_wheel(_E())
|
|
root.update()
|
|
check('滚轮向下 → 翻到第 2 页', app._page == 1, app._page)
|
|
app._page_wheel(type('E2', (), {'delta': 120})())
|
|
root.update()
|
|
check('滚轮向上 → 回到第 1 页', app._page == 0, app._page)
|
|
|
|
print('I 列数没变时第二次 _layout_cards 不重排')
|
|
n_col = [0]
|
|
orig_cc = app.todo_grid.columnconfigure
|
|
|
|
|
|
def spy_cc(*a, **k):
|
|
n_col[0] += 1
|
|
return orig_cc(*a, **k)
|
|
|
|
|
|
app.todo_grid.columnconfigure = spy_cc
|
|
app._layout_key = None
|
|
app._layout_cards()
|
|
root.update_idletasks()
|
|
first = n_col[0]
|
|
n_col[0] = 0
|
|
app._layout_cards()
|
|
root.update_idletasks()
|
|
second = n_col[0]
|
|
app.todo_grid.columnconfigure = orig_cc
|
|
check('首次重排会设列(>0 次)', first > 0, first)
|
|
check('再调一次 0 次列设置(直接跳过)', second == 0, second)
|
|
|
|
print('J 全量重建后仍能正确重排')
|
|
app._layout_key = ('stale',)
|
|
app._fill_todo(rws)
|
|
root.update_idletasks()
|
|
root.update()
|
|
info = app.todo_cards['R000'].grid_info()
|
|
check('重建后卡片有 grid 位置', bool(info), info)
|
|
check('重建后列宽已写入', int(app.todo_cards['R000'].cget('width')) > 40,
|
|
app.todo_cards['R000'].cget('width'))
|
|
|
|
try:
|
|
root.destroy()
|
|
except Exception:
|
|
pass
|
|
|
|
print('\n通过 %d 项,失败 %d 项' % (ok, fail))
|
|
sys.exit(1 if fail else 0)
|