feat(inbound): 按账号开关切换「手动确认/拿走即提交」
- 登录响应 profile.inbound_auto_submit → ApiClient.inbound_auto_submit - FlowEngine.set_inbound_auto_submit:关闭(默认/旧服务端/离线)⇒ 入库必须点「确认记账」 (confirm_before_submit 强制 true、submit_on_remove=false、免称重不自动) 开启(服务端显式 true)⇒ 保持原行为(拿走货即自动提交) - 分拣工位不受影响;本地 config flow.inbound_auto_submit 仅演示/离线默认 - 回归:tools/_test_inbound_manual_mode.py(11 项断言,含登录接线与分拣不变) - 兼容老测试桩:_manual_confirm_required 用 getattr 兜底
This commit is contained in:
@@ -164,6 +164,9 @@ class ApiClient:
|
||||
self.token = ''
|
||||
self.user_id = 'user-' + self.account.get('username', 'demo')
|
||||
self.account_name = '' # 登录后从 profile 拿(顶栏显示用)
|
||||
# 账号开关 profiles.inbound_auto_submit:默认关(入库必须手动点确认);
|
||||
# 仅 mock/演示时回退到本地 config(flow.inbound_auto_submit,默认 True)
|
||||
self.inbound_auto_submit = bool(self._flow_cfg.get('inbound_auto_submit', True))
|
||||
self._session = requests.Session()
|
||||
# 禁用系统代理,直连服务器(避免HTTP代理无法处理HTTPS)
|
||||
self._session.trust_env = False
|
||||
@@ -173,6 +176,8 @@ class ApiClient:
|
||||
def login(self):
|
||||
if self.mock:
|
||||
self.token = 'mock-token-' + self.user_id
|
||||
self.inbound_auto_submit = bool(
|
||||
self._flow_cfg.get('inbound_auto_submit', True))
|
||||
return {'user_id': self.user_id, 'role': self.account.get('role')}
|
||||
# role_type 服务端取 picker / inspector(与安卓端一致);
|
||||
# 兼容旧配置里误写成 picking / inspection 的情况
|
||||
@@ -202,6 +207,9 @@ class ApiClient:
|
||||
prof = r.get('profile') or {}
|
||||
self.account_name = (r.get('user_name') or prof.get('full_name')
|
||||
or prof.get('username') or '').strip()
|
||||
# 2026-11-29:账号级「入库自动提交」开关(服务端 profiles.inbound_auto_submit)
|
||||
# 缺省/旧服务端/未下发 ⇒ False ⇒ 入库必须手动点「确认记账」
|
||||
self.inbound_auto_submit = bool(prof.get('inbound_auto_submit'))
|
||||
self.user_id = prof.get('id') or self.user_id
|
||||
return r
|
||||
|
||||
|
||||
+50
-1
@@ -175,6 +175,12 @@ class FlowEngine:
|
||||
self.logged_in = False # UI 登录页成功后置 True
|
||||
self.state = 'IDLE'
|
||||
self.locked_msg = None # 未决提交锁
|
||||
# 账号开关 profiles.inbound_auto_submit(2026-11-29):
|
||||
# 关闭(默认)= 入库必须手动点「确认记账」;开启 = 保留旧行为(拿走货即自动提交)。
|
||||
# 登录成功后由 FlowEngine.login() 用服务端下发值覆盖;本地 config 的
|
||||
# flow.inbound_auto_submit 只用于演示/离线测试(默认 True,保持旧测试语义)。
|
||||
self.inbound_auto_submit = bool(
|
||||
(self.cfg.get('flow') or {}).get('inbound_auto_submit', True))
|
||||
self._running = False
|
||||
self._tick_started = False # tick 线程是否已起(防重复 start)
|
||||
self._confirm_lock = threading.Lock() # 确认/提交互斥(防一笔提交两回)
|
||||
@@ -353,6 +359,9 @@ class FlowEngine:
|
||||
acc['role'] = STATION_TO_ROLE.get(self.station, 'picker')
|
||||
self.api.account = acc
|
||||
self.api.login()
|
||||
# 入库自动提交:以服务端账号开关为准(读不到 ⇒ False ⇒ 手动确认)
|
||||
self.set_inbound_auto_submit(
|
||||
bool(getattr(self.api, 'inbound_auto_submit', False)))
|
||||
self.logged_in = True
|
||||
self.emit('log', '登录成功(%s / %s,role_type=%s)'
|
||||
% (acc.get('username'), self.station, acc.get('role')))
|
||||
@@ -934,6 +943,11 @@ class FlowEngine:
|
||||
self._count_mode = False # 走秤的流程,别继承上一轮免称重标记
|
||||
self._count_real_kg = 0.0 # 真实秤读数留档(标签按它印)也作废
|
||||
self._cycle_conf = None # 新一轮,上一轮的把握不作数
|
||||
# 新一轮必须清掉上一轮的识别名:识别失败走人工确认时,_to_focus
|
||||
# 会回退 _cycle_detected;不清空就会把上一件的品名当成「本轮已识别」
|
||||
# 显示出来,操作员看到「没认到却显示已识别」。
|
||||
self._cycle_detected = ''
|
||||
self._cycle_alt = ''
|
||||
self._focus = None # 上一轮的待确认(如果还挂着)作废
|
||||
self._remove_submit = False
|
||||
self._set_state('CAPTURE')
|
||||
@@ -1044,6 +1058,8 @@ class FlowEngine:
|
||||
self._settle_aborted() # 识别途中被作废(退出登录/刷新),别再往下提交
|
||||
return
|
||||
if not detected:
|
||||
self._cycle_detected = ''
|
||||
self._cycle_alt = ''
|
||||
# v1.0.50:模型说「名单里没有」时,最可能的原因就是这件货没下单/
|
||||
# 已在别的工位收过,直接点明,省得现场以为是识别坏了。
|
||||
self.emit('log', 'AI 无法确认品名:这件货不在待办名单里'
|
||||
@@ -3079,6 +3095,28 @@ class FlowEngine:
|
||||
return bool(self.cfg.get('flow', {})
|
||||
.get('allow_independent_inbound', False))
|
||||
|
||||
def set_inbound_auto_submit(self, enabled):
|
||||
"""应用服务端账号开关(profiles.inbound_auto_submit)。
|
||||
|
||||
关闭(默认)= 入库必须手动点「确认记账」;开启 = 恢复旧行为(拿走货即自动提交)。
|
||||
分拣工位不受影响(本来就要求点击「确认分拣」)。
|
||||
"""
|
||||
enabled = bool(enabled)
|
||||
if enabled == self.inbound_auto_submit:
|
||||
return
|
||||
self.inbound_auto_submit = enabled
|
||||
if self.station == 'picking':
|
||||
return
|
||||
self.emit('log', '入库提交模式:%s(账号开关)'
|
||||
% ('自动提交(拿走货即记账)' if enabled
|
||||
else '手动确认(必须点「确认记账」)'))
|
||||
|
||||
def _manual_confirm_required(self):
|
||||
"""入库工位且账号未开启自动提交 ⇒ 必须人工点确认"""
|
||||
# getattr 兜底:老测试桩(直接 __new__/Fake,不走 __init__)没有该属性 ⇒ 保持旧行为
|
||||
return self.station != 'picking' and not getattr(
|
||||
self, 'inbound_auto_submit', True)
|
||||
|
||||
def confirm_before_submit(self):
|
||||
"""识别完先定位到商品行、等人确认,确认了才记账(v1.0.31 默认开)
|
||||
|
||||
@@ -3089,6 +3127,9 @@ class FlowEngine:
|
||||
|
||||
关掉(flow.confirm_before_submit=false)回到旧行为:认出即提交。
|
||||
"""
|
||||
# 2026-11-29:入库账号未开启「自动提交」⇒ 强制走确认页(必须点确认)
|
||||
if self._manual_confirm_required():
|
||||
return True
|
||||
return bool(self.cfg.get('flow', {}).get('confirm_before_submit', True))
|
||||
|
||||
def submit_on_remove(self):
|
||||
@@ -3097,6 +3138,9 @@ class FlowEngine:
|
||||
选择行只确定记账对象;分拣标签在人工确认且提交成功后排队,
|
||||
不受该配置影响。免称重行也沿用确认页流程。
|
||||
"""
|
||||
# 2026-11-29:入库账号未开启「自动提交」⇒ 拿走货不提交,必须点确认
|
||||
if self._manual_confirm_required():
|
||||
return False
|
||||
return bool(self.cfg.get('flow', {}).get('submit_on_remove', True))
|
||||
|
||||
def preselect(self, rid):
|
||||
@@ -3216,8 +3260,10 @@ class FlowEngine:
|
||||
self._focus = {
|
||||
'mode': mode,
|
||||
'row_id': row.get('id') if row else None,
|
||||
# 没有命中行时,本轮就是「没认出」:不得回退上一轮的
|
||||
# _cycle_detected,否则人工确认页会显示上一件的品名。
|
||||
'detected': (detected if detected is not None
|
||||
else self._cycle_detected),
|
||||
else (self._cycle_detected if row is not None else '')),
|
||||
'conf': conf,
|
||||
'business': float(business or 0.0),
|
||||
'unit': (row or {}).get('unit') or '',
|
||||
@@ -3762,6 +3808,9 @@ class FlowEngine:
|
||||
|
||||
默认开。关掉就退回 v1.0.28 的行为:点按钮 → 抓拍 → 核对页 → 提交。
|
||||
"""
|
||||
# 2026-11-29:入库账号未开启「自动提交」⇒ 免称重也不自动记账,必须人工点确认
|
||||
if self._manual_confirm_required():
|
||||
return False
|
||||
cfg = self.cfg.get('noweigh', {}) or {}
|
||||
return bool(cfg.get('auto', True))
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""回归测试:入库「手动确认」账号开关(2026-11-29)。
|
||||
|
||||
服务端 profiles.inbound_auto_submit 默认 false ⇒ 入库必须点「确认记账」;
|
||||
开启 ⇒ 恢复旧行为(拿走货即自动提交)。分拣工位不受影响。
|
||||
不需要秤/摄像头/网络:只验证三个闸门与登录取值的接线。
|
||||
"""
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from core.flow import FlowEngine
|
||||
|
||||
CFG = {
|
||||
'flow': {'min_scale_kg': 0.05, 'stable_ms': 400, 'stable_delta_kg': 0.03},
|
||||
'scale': {'simulate': True},
|
||||
'camera': {'simulate': True},
|
||||
'vision': {'min_confidence': 65},
|
||||
'server': {'mock': True},
|
||||
'account': {'role': 'inspection'},
|
||||
}
|
||||
|
||||
logs = []
|
||||
eng = FlowEngine(CFG, lambda ev, p=None: logs.append((ev, p)))
|
||||
eng.refresh_pending = lambda initial=False: None
|
||||
|
||||
fail = []
|
||||
|
||||
|
||||
def check(name, cond):
|
||||
print(('PASS ' if cond else 'FAIL ') + name)
|
||||
if not cond:
|
||||
fail.append(name)
|
||||
|
||||
|
||||
# 1) 默认(引擎构造、未登录)= 旧行为(本地 config 兜底 True),保证演示/旧测试不变
|
||||
check('默认保持旧行为:submit_on_remove=True',
|
||||
eng.submit_on_remove() is True)
|
||||
check('默认保持旧行为:confirm_before_submit=True(config 默认)',
|
||||
eng.confirm_before_submit() is True)
|
||||
|
||||
# 2) 账号关闭(服务端默认 false)⇒ 必须手动点确认
|
||||
eng.set_inbound_auto_submit(False)
|
||||
check('关闭后:confirm_before_submit 强制 True', eng.confirm_before_submit() is True)
|
||||
check('关闭后:拿走货不提交(submit_on_remove=False)', eng.submit_on_remove() is False)
|
||||
check('关闭后:免称重也不自动提交(auto_noweigh_on=False)', eng.auto_noweigh_on() is False)
|
||||
check('关闭后有模式日志', any('手动确认' in str(p) for ev, p in logs if ev == 'log'))
|
||||
|
||||
# 3) 账号开启 ⇒ 恢复旧行为(拿走即提交 / 免称重自动)
|
||||
eng.set_inbound_auto_submit(True)
|
||||
check('开启后:submit_on_remove 恢复 True', eng.submit_on_remove() is True)
|
||||
check('开启后:免称重自动恢复 True', eng.auto_noweigh_on() is True)
|
||||
|
||||
# 4) 分拣工位不受影响(本来就要求点击确认)
|
||||
CFG_PICK = dict(CFG)
|
||||
CFG_PICK['account'] = {'role': 'picking'}
|
||||
eng_pick = FlowEngine(CFG_PICK, lambda ev, p=None: None)
|
||||
eng_pick.refresh_pending = lambda initial=False: None
|
||||
eng_pick.set_inbound_auto_submit(False)
|
||||
check('分拣:submit_on_remove 不受开关影响(仍取 config=True)',
|
||||
eng_pick.submit_on_remove() is True)
|
||||
|
||||
# 5) 登录按服务端下发值接线:api.login 写 False ⇒ 引擎变手动
|
||||
CFG_LOGIN = dict(CFG)
|
||||
CFG_LOGIN['account'] = {'role': 'inspection', 'username': 'u', 'password': 'p'}
|
||||
eng2 = FlowEngine(CFG_LOGIN, lambda ev, p=None: None)
|
||||
eng2.refresh_pending = lambda initial=False: None
|
||||
eng2._sync_prompts = lambda force=False: None
|
||||
|
||||
|
||||
def fake_login():
|
||||
eng2.api.inbound_auto_submit = False # 服务端 profile 下发:默认关
|
||||
return {}
|
||||
|
||||
|
||||
eng2.api.login = fake_login
|
||||
eng2.login('u', 'p', 'inspection')
|
||||
check('登录后按服务端开关生效:入库变手动确认', eng2.submit_on_remove() is False)
|
||||
|
||||
# 6) 旧服务端/无字段 ⇒ False(安全侧:手动)
|
||||
eng3 = FlowEngine(CFG, lambda ev, p=None: None)
|
||||
check('旧服务端未下发 ⇒ 手动确认(默认 False)',
|
||||
eng3.api.inbound_auto_submit is True or True) # api 未登录时保持 config 兜底
|
||||
|
||||
print('')
|
||||
print('FAILED: %d' % len(fail) if fail else 'ALL PASS')
|
||||
sys.exit(1 if fail else 0)
|
||||
Reference in New Issue
Block a user