fix(inbound): 整组短收按部分成功提示剩余(v1.0.68)
- 配套服务端 2026-11-22 方案A:短收整组入库返回 200 + partialGroup/remainingQty - 成功提示写明「整组部分入库:已入 N 行,剩余 X 斤,下次称重继续;不要用旧组重试」 - commit_inspection_group 回包带出 partial_group/merged_count/remaining_qty/unallocated_lines - reject_hint 新增 scope_incomplete / scope_changed / group_changed / scope_mismatch 的中文可执行提示:刷新待验列表后再称,不要直接重试旧组 - 新增 tools/_test_group_partial.py(15 项源码级回归,本机无需 Windows 运行库) - 版本 1.0.67 → 1.0.68(build_exe.py / installer.iss / 使用说明.txt)
This commit is contained in:
+2
-2
@@ -1,4 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
"""一键打包:图标 → PyInstaller → 补齐资源 → Inno Setup 安装包
|
||||
|
||||
用法(在项目根目录):
|
||||
@@ -20,7 +20,7 @@ import sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
APP_NAME = '入库分拣工作站'
|
||||
APP_VERSION = '1.0.67'
|
||||
APP_VERSION = '1.0.68'
|
||||
ASSETS = os.path.join(ROOT, 'assets')
|
||||
DIST = os.path.join(ROOT, 'dist')
|
||||
OUT = os.path.join(DIST, APP_NAME)
|
||||
|
||||
+10
-2
@@ -496,10 +496,18 @@ class ApiClient:
|
||||
raise ApiError(-5, '服务端未入账:%s'
|
||||
% (r.get('error_description') or r.get('error') or r))
|
||||
# 统一成 _verify 认识的形态:本接口没有 operation_id,成功响应即本次入账。
|
||||
# 短收部分成功(2026-11-22 方案 A,见 docs/design/20261122-weigh-group-partial-inbound.md):
|
||||
# 后端 200 + partialGroup/remainingQty(已入 N 行、剩余行继续待验),这里把关键字段带出来
|
||||
# 供 UI 提示「下次再称」,并提示不要拿旧组重试。
|
||||
d = data if isinstance(data, dict) else {}
|
||||
return {'operation_status': 'committed_by_this_operation',
|
||||
'client_operation_id': operation_id,
|
||||
'data': data if isinstance(data, dict) else {},
|
||||
'group_hash': group_hash}
|
||||
'data': d,
|
||||
'group_hash': group_hash,
|
||||
'partial_group': bool(d.get('partialGroup')),
|
||||
'merged_count': d.get('mergedCount'),
|
||||
'remaining_qty': d.get('remainingQty'),
|
||||
'unallocated_lines': d.get('unallocatedLines') or []}
|
||||
|
||||
def commit_inspection_single(self, row, qty, weight_kg, operation_id,
|
||||
force_complete=False,
|
||||
|
||||
@@ -136,6 +136,16 @@ def reject_hint(err, row):
|
||||
return ('重量对不上:这行应 %.2f %s,本次超出服务端容差,未入账。'
|
||||
'差得多通常是放上来的不是这件货,请核对后再称'
|
||||
'(或到后台按实际数改单)' % (req, unit))
|
||||
# 2026-11-22 生产事故:整组入库「短收」曾被后端先入一部分再 409,客户端当未提交处理,
|
||||
# 拿旧组重试又撞 scope_changed。新后端已按「部分成功」返回(不会走到这里),
|
||||
# 这两条提示是给旧后端/其它范围变化兜底:先刷新再称,绝不直接重试旧组。
|
||||
if 'scope_incomplete' in low:
|
||||
return ('提交被拒绝:整组入库没有按分摊提交。请刷新待验列表后重新称重;'
|
||||
'不要直接重试(旧组可能已部分入库)')
|
||||
if ('scope_changed' in low or 'group_changed' in low
|
||||
or 'scope_mismatch' in low):
|
||||
return ('待验范围已变化(可能已被其它终端入库或后台改单)。'
|
||||
'请刷新待验列表后再称;不要直接重试旧组')
|
||||
return ''
|
||||
|
||||
|
||||
@@ -2471,6 +2481,20 @@ class FlowEngine:
|
||||
|
||||
def _success_extra(self, kind, resp):
|
||||
"""成功提示的补充语:部分入库/偏差结案不能只说“确认成功”"""
|
||||
data = resp.get('data') if isinstance(resp, dict) else None
|
||||
# 整组短收→部分成功(2026-11-22 方案 A):告诉现场「已入 N 行、剩余多少下次再称」,
|
||||
# 并明确不要拿旧组重试(旧组 hash 已经变了)。
|
||||
if isinstance(data, dict) and data.get('partialGroup'):
|
||||
n = data.get('mergedCount')
|
||||
rem = data.get('remainingQty')
|
||||
unit = str((self._frozen_row or {}).get('unit') or '')
|
||||
txt = '|整组部分入库:已入 %s 行' % (n if n not in (None, '') else '?')
|
||||
try:
|
||||
if rem not in (None, ''):
|
||||
txt += ',剩余 %g %s' % (float(rem), unit)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return txt + '(剩余行仍在待验,下次称重继续;不要用旧组重试)'
|
||||
if kind == 'ok':
|
||||
return ''
|
||||
info = self._strict_info(resp)
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
; ============================================================
|
||||
; ============================================================
|
||||
; 入库分拣工作站 · 安装包脚本(Inno Setup 6)
|
||||
; 编译:iscc installer.iss → dist\入库分拣工作站_安装程序_v1.0.67.exe
|
||||
; 编译:iscc installer.iss → dist\入库分拣工作站_安装程序_v1.0.68.exe
|
||||
; 说明:源目录为 build_exe.py 产出的 dist\入库分拣工作站(onedir)
|
||||
; ============================================================
|
||||
|
||||
#define AppName "入库分拣工作站"
|
||||
#ifndef AppVersion
|
||||
#define AppVersion "1.0.67"
|
||||
#define AppVersion "1.0.68"
|
||||
#endif
|
||||
#define AppExe "入库分拣工作站.exe"
|
||||
#define SrcDir "dist\入库分拣工作站"
|
||||
@@ -41,7 +41,7 @@ CloseApplications=yes
|
||||
RestartApplications=no
|
||||
AllowNoIcons=yes
|
||||
ShowLanguageDialog=no
|
||||
VersionInfoVersion=1.0.67.0
|
||||
VersionInfoVersion=1.0.68.0
|
||||
VersionInfoDescription={#AppName} 安装程序
|
||||
VersionInfoProductName={#AppName}
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""整组入库·短收部分成功回归(2026-11-22 方案 A)
|
||||
|
||||
背景(BR002 生产事故):5 行组、实称 6.48 斤,服务端先入 2 行再 409 scope_incomplete,
|
||||
客户端把 409 当「未提交」,拿旧组重试又撞 scope_changed。
|
||||
|
||||
本机(Linux 构建机)没有 Windows 端运行依赖(numpy/pywin32/opencv…),所以本用例
|
||||
**不 import 整包**,而是从源码中抽取待测函数做真实行为测试 + 源码契约断言:
|
||||
|
||||
① 服务端 200 部分成功时,客户端带出 partial_group / merged_count / remaining_qty / 未入行;
|
||||
② 成功提示说清「已入 N 行、剩余 X 斤、下次再称,不要用旧组重试」;
|
||||
③ scope_incomplete / scope_changed 等业务拒绝翻成人话(刷新待验列表、不直接重试旧组)。
|
||||
|
||||
设计:docs/design/20261122-weigh-group-partial-inbound.md
|
||||
"""
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
import types
|
||||
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
FLOW = os.path.join(ROOT, 'core', 'flow.py')
|
||||
CLIENT = os.path.join(ROOT, 'core', 'api', 'client.py')
|
||||
|
||||
checks = 0
|
||||
|
||||
|
||||
def ok(cond, msg):
|
||||
global checks
|
||||
checks += 1
|
||||
if not cond:
|
||||
raise AssertionError(msg)
|
||||
print(' ✓', msg)
|
||||
|
||||
|
||||
def read(p):
|
||||
with open(p, encoding='utf-8') as fh:
|
||||
return fh.read()
|
||||
|
||||
|
||||
def extract_def(src, header):
|
||||
"""按 4 空格缩进抽取一个 def 块(方法或顶层函数),返回去缩进源码。"""
|
||||
start = src.index(header)
|
||||
m = re.search(r'\n(?= def |\ndef |class )', src[start + len(header):])
|
||||
end = start + len(header) + (m.start() if m else len(src))
|
||||
return textwrap.dedent(src[start:end])
|
||||
|
||||
|
||||
flow_src = read(FLOW)
|
||||
client_src = read(CLIENT)
|
||||
|
||||
# ---- ① 客户端回包解析(抽取真实方法源码执行,不联网) ----
|
||||
print('① 客户端解析 200 短收部分成功回包')
|
||||
ns = {'__name__': 'client_probe'}
|
||||
|
||||
|
||||
class _ApiError(Exception):
|
||||
def __init__(self, code, message):
|
||||
super().__init__(message)
|
||||
self.code = code
|
||||
|
||||
|
||||
ns['ApiError'] = _ApiError
|
||||
exec(extract_def(client_src, 'def commit_inspection_group('), ns)
|
||||
|
||||
|
||||
class _FakeApi:
|
||||
def __init__(self, payload):
|
||||
self.mock = False
|
||||
self.cfg = {}
|
||||
self._payload = payload
|
||||
|
||||
def _request(self, *args, **kwargs):
|
||||
return self._payload
|
||||
|
||||
|
||||
ns['_FakeApi'] = _FakeApi
|
||||
_FakeApi.commit_inspection_group = ns['commit_inspection_group']
|
||||
|
||||
partial = _FakeApi({
|
||||
'success': True,
|
||||
'data': {
|
||||
'merged': True, 'mergedCount': 2, 'partialGroup': True, 'remainingQty': 7.38,
|
||||
'unallocatedLines': [{'id': 'x', 'prepare_qty': 3}],
|
||||
},
|
||||
}).commit_inspection_group({'inspection_ids': ['a', 'b', 'c', 'd', 'e']}, 6.48, 3.24, 'op1')
|
||||
ok(partial.get('partial_group') is True, 'partial_group=True')
|
||||
ok(partial.get('merged_count') == 2, 'merged_count=2(已入 2 行)')
|
||||
ok(abs(float(partial.get('remaining_qty') or 0) - 7.38) < 1e-9, 'remaining_qty=7.38 斤')
|
||||
ok(len(partial.get('unallocated_lines') or []) == 1, 'unallocated_lines 带出未入行')
|
||||
ok(partial.get('data', {}).get('mergedCount') == 2, 'data 原样保留(供现有成功判定)')
|
||||
|
||||
full = _FakeApi({
|
||||
'success': True,
|
||||
'data': {'merged': True, 'mergedCount': 2, 'partialGroup': False, 'remainingQty': 0},
|
||||
}).commit_inspection_group({'inspection_ids': ['a', 'b']}, 13, 6.5, 'op2')
|
||||
ok(full.get('partial_group') is False, '整组入完时 partial_group=False')
|
||||
|
||||
# ---- ② 成功提示(抽取 _success_extra 方法执行) ----
|
||||
print('② 成功提示:说清已入行数/剩余量/不要旧组重试')
|
||||
ns2 = {'__name__': 'flow_probe'}
|
||||
exec(extract_def(flow_src, 'def _success_extra('), ns2)
|
||||
_Eng = type('_Eng', (), {'_success_extra': ns2['_success_extra'], '_strict_info': lambda self, r: {}})
|
||||
eng = _Eng()
|
||||
eng._frozen_row = {'unit': '斤'}
|
||||
note = eng._success_extra('ok', {'data': {'partialGroup': True, 'mergedCount': 2, 'remainingQty': 7.38}})
|
||||
ok('已入 2 行' in note, '提示包含「已入 2 行」')
|
||||
ok('7.38' in note, '提示包含剩余量 7.38')
|
||||
ok('不要用旧组重试' in note, '提示明确不要用旧组重试')
|
||||
ok(eng._success_extra('ok', {'data': {}}) == '', '普通成功不额外加话')
|
||||
|
||||
# ---- ③ 业务拒绝翻译(抽取 reject_hint 执行) ----
|
||||
print('③ 业务拒绝翻译(保底旧后端/范围变化)')
|
||||
ns3 = {'__name__': 'hint_probe', 'M': types.SimpleNamespace(required_qty_of=lambda row, mode=None: 0.0)}
|
||||
exec(extract_def(flow_src, 'def reject_hint('), ns3)
|
||||
reject_hint = ns3['reject_hint']
|
||||
|
||||
hint = reject_hint('业务拒绝 409: {"error":"scope_incomplete","error_description":"整组入库行数不一致"}', {'unit': '斤'})
|
||||
ok('刷新待验列表' in hint and '不要直接重试' in hint, 'scope_incomplete → 刷新后重称、不重试')
|
||||
hint2 = reject_hint('业务拒绝 409: {"error":"scope_changed"}', {'unit': '斤'})
|
||||
ok('刷新待验列表' in hint2, 'scope_changed → 刷新待验列表')
|
||||
hint3 = reject_hint('业务拒绝 409: {"error":"group_changed"}', {'unit': '斤'})
|
||||
ok('刷新待验列表' in hint3, 'group_changed → 刷新待验列表')
|
||||
ok(reject_hint('业务拒绝 400: {"error":"invalid_cost"}', {'unit': '斤'}) == '',
|
||||
'未登记错误保持原样(不硬造提示)')
|
||||
ok('weigh_tolerance' not in hint, '非容差类错误不误报重量对不上')
|
||||
|
||||
print('\n全部通过:%d 项' % checks)
|
||||
@@ -1,4 +1,4 @@
|
||||
════════════════════════════════════════════
|
||||
════════════════════════════════════════════
|
||||
配送入库分拣工作站(Win10 版)- 使用说明
|
||||
════════════════════════════════════════════
|
||||
|
||||
@@ -25,7 +25,23 @@
|
||||
build_assets/ 打包素材(VC++ 运行库 vc_redist.x64.exe)
|
||||
打包.bat 双击打包
|
||||
dist/ 产物:dist\入库分拣工作站\(绿色版)
|
||||
dist\入库分拣工作站_安装程序_v1.0.66.exe(安装包)
|
||||
dist\入库分拣工作站_安装程序_v1.0.68.exe(安装包)
|
||||
|
||||
【v1.0.68 整组短收按部分成功处理(2026-11-22)】
|
||||
|
||||
◆ 整组入库短收不再报 409「整组入库行数不一致」
|
||||
· 背景:整组待验 13 斤、本次只称 6.48 斤时,服务端按行 FIFO 分摊后
|
||||
有的行分到 0;旧版服务端先入了一部分、再回 409,现场看到「提交被
|
||||
拒绝」,实际已入一半;拿旧组重试又报「部分待验明细已提交」。
|
||||
· 新版服务端把「短收」当正常的「部分成功」:返回 200,并告诉端上
|
||||
已入几行、剩余多少斤继续待验。本版配套:
|
||||
· 成功提示会写「整组部分入库:已入 N 行,剩余 X 斤(下次称重继续;
|
||||
不要用旧组重试)」;
|
||||
· scope_incomplete / scope_changed / group_changed / scope_mismatch
|
||||
这几类业务拒绝翻成人话:「请刷新待验列表后再称,不要直接重试旧组」。
|
||||
· 需要配套服务端 2026-11-22 之后的版本;旧服务端下行为不变。
|
||||
· 注意:短收部分入账后,剩余行仍在待验列表里,请刷新列表后继续称;
|
||||
若剩余货确定不再到,才用「偏差/短收结案」。
|
||||
|
||||
【v1.0.66 分组批量入库 + 登录页改服务器(2026-11-10)】
|
||||
|
||||
|
||||
Reference in New Issue
Block a user