diff --git a/core/flow.py b/core/flow.py index 07b8130..a443cfb 100644 --- a/core/flow.py +++ b/core/flow.py @@ -3804,13 +3804,14 @@ class FlowEngine: # ------------------------------------------------ AI 自动免称重(v1.0.29) def auto_noweigh_on(self): - """不称重商品是否由 AI 自动识别、自动入库/分拣(不用点屏幕) + """不称重商品是否由 AI **自动识别**(放上去就认,不用点屏幕) 默认开。关掉就退回 v1.0.28 的行为:点按钮 → 抓拍 → 核对页 → 提交。 + + 2026-11-29 的账号「手动确认」开关**不影响这里**:识别照旧自动跑, + 只是认出后由 `confirm_before_submit()` 强制进确认页,点了才算记账。 + 以前这里跟着一起关,袋/包/桶连自动识别都没了,每件都要手点一下。 """ - # 2026-11-29:入库账号未开启「自动提交」⇒ 免称重也不自动记账,必须人工点确认 - if self._manual_confirm_required(): - return False cfg = self.cfg.get('noweigh', {}) or {} return bool(cfg.get('auto', True)) diff --git a/tools/_test_inbound_manual_mode.py b/tools/_test_inbound_manual_mode.py index 832fcb6..531f3ba 100644 --- a/tools/_test_inbound_manual_mode.py +++ b/tools/_test_inbound_manual_mode.py @@ -3,7 +3,10 @@ 服务端 profiles.inbound_auto_submit 默认 false ⇒ 入库必须点「确认记账」; 开启 ⇒ 恢复旧行为(拿走货即自动提交)。分拣工位不受影响。 -不需要秤/摄像头/网络:只验证三个闸门与登录取值的接线。 + +**识别不受影响**:免称重(袋/包/桶)照旧自动抓拍识别,只是认出后 +由 confirm_before_submit() 强制进确认页,点了才记账。 +不需要秤/摄像头/网络:只验证闸门、登录取值与分页接口的接线。 """ import sys import io @@ -30,8 +33,9 @@ eng.refresh_pending = lambda initial=False: None fail = [] -def check(name, cond): - print(('PASS ' if cond else 'FAIL ') + name) +def check(name, cond, extra=''): + print(('PASS ' if cond else 'FAIL ') + name + + ('' if cond else ' %r' % (extra,))) if not cond: fail.append(name) @@ -46,13 +50,24 @@ check('默认保持旧行为:confirm_before_submit=True(config 默认)', 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('关闭后:免称重仍自动识别(auto_noweigh_on=True)', + eng.auto_noweigh_on() is True) check('关闭后有模式日志', any('手动确认' in str(p) for ev, p in logs if ev == 'log')) -# 3) 账号开启 ⇒ 恢复旧行为(拿走即提交 / 免称重自动) + +# 2b) 免称重认出后必须进确认页(不是直接记账) +seen = [] +eng._to_focus = lambda *a, **k: seen.append((a, k)) +eng._auto_round = True +_one = {'id': 'x1', 'item_name': '土豆', 'unit': '袋', + 'required_qty': 3, 'remaining_qty': 3} +eng._to_count_confirm('土豆', _one, [_one]) +check('免称重认出后进确认页(不直接提交)', len(seen) == 1, ) + +# 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) +check('开启后:免称重自动识别仍为 True', eng.auto_noweigh_on() is True) # 4) 分拣工位不受影响(本来就要求点击确认) CFG_PICK = dict(CFG) @@ -80,10 +95,24 @@ 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 兜底 +# 6) 登录返回的 profile 里没这个字段 ⇒ False(安全侧:手动) +from core.api.client import ApiClient # noqa: E402 + + +def client_with(profile): + c = ApiClient({'server': {'base_url': 'https://x/api', 'mock': False}, + 'account': {'username': 'u', 'password': 'p'}, + 'flow': {}}) + c._request = lambda *a, **k: {'access_token': 't', 'profile': profile} + c.login() + return c + + +check('服务端未下发该字段 ⇒ 手动(False)', + client_with({'id': 1}).inbound_auto_submit is False) +check('服务端下发 true ⇒ 自动提交(True)', + client_with({'id': 1, 'inbound_auto_submit': True}) + .inbound_auto_submit is True) print('') print('FAILED: %d' % len(fail) if fail else 'ALL PASS')