127 lines
4.7 KiB
Python
127 lines
4.7 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""v1.0.37 回归:短收在容差内直接结案(不再留「差一点点」的续收行)
|
||
|
||
现场 11-05 13:25:青笋 应 10.00 斤 / 实 9.88 斤,服务端判 partial,
|
||
生成了 0.12 斤的续收行挂在待办里;21.00 / 20.50 同样。操作员看到的就是
|
||
「已经入库了,界面上还有这一行」。
|
||
|
||
规则:入库站短收差额 ≤ short_close_pct(默认 20%)且 ≤ short_close_max_qty
|
||
(默认 3,0=不限,只对重量单位生效)→ 带 force_complete 提交,库存仍按
|
||
实收写,差额由服务端记短少结案。分拣站不适用(少拣是缺货凭据)。
|
||
"""
|
||
import os
|
||
import sys
|
||
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
from core.api.client import ApiClient
|
||
from core.flow import FlowEngine
|
||
|
||
ok = fail = 0
|
||
|
||
|
||
def check(name, cond, extra=''):
|
||
global ok, fail
|
||
if cond:
|
||
ok += 1
|
||
print(' ✓', name)
|
||
else:
|
||
fail += 1
|
||
print(' ✗', name, extra)
|
||
|
||
|
||
class Fake(FlowEngine):
|
||
"""只搭 _short_close_gap 需要的属性(不连设备、不起线程)"""
|
||
|
||
def __init__(self, flow_cfg=None, station='inspection'):
|
||
self.cfg = {'flow': dict(flow_cfg or {})}
|
||
self.station = station
|
||
|
||
|
||
def row(qty, unit='斤'):
|
||
return {'id': 'r1', 'item_name': '青笋', 'unit': unit,
|
||
'prepare_qty': qty, 'required_qty': qty}
|
||
|
||
|
||
def gap_of(flow_cfg, req, actual, unit='斤', station='inspection'):
|
||
return Fake(flow_cfg, station)._short_close_gap(row(req, unit), actual)
|
||
|
||
|
||
print('一、现场两笔真实数据')
|
||
f, gap, pct = gap_of({}, 10.0, 9.88)
|
||
check('应10实9.88 → 结案', f is True, (f, gap, pct))
|
||
check('差额 0.12 / 1.2%', abs(gap - 0.12) < 1e-6 and abs(pct - 1.2) < 0.05,
|
||
(gap, pct))
|
||
f, gap, pct = gap_of({}, 21.0, 20.5)
|
||
check('应21实20.5 → 结案', f is True, (f, gap, pct))
|
||
check('差额 0.5 / 2.38%', abs(gap - 0.5) < 1e-6 and abs(pct - 2.38) < 0.05,
|
||
(gap, pct))
|
||
|
||
print('二、容差边界')
|
||
f, _, pct = gap_of({}, 10.0, 8.0)
|
||
check('正好差 20% → 结案', f is True, (f, pct))
|
||
f, _, pct = gap_of({}, 10.0, 7.9)
|
||
check('差 21% → 不结案(照旧走部分入库)', f is False, (f, pct))
|
||
f, _, _ = gap_of({}, 10.0, 10.0)
|
||
check('不少收 → 不结案', f is False)
|
||
f, _, _ = gap_of({}, 10.0, 10.4)
|
||
check('超收 → 不结案(超收本来就 complete)', f is False)
|
||
f, _, _ = gap_of({}, 0, 3.0)
|
||
check('无应量 → 不结案', f is False)
|
||
|
||
print('三、绝对上限(防止 70 斤的货差 14 斤也被抹平)')
|
||
f, gap, pct = gap_of({}, 70.0, 58.0) # 差 12 斤 = 17%
|
||
check('差 12 斤 > 3 斤上限 → 不结案', f is False, (f, gap, pct))
|
||
f, gap, pct = gap_of({'short_close_max_qty': 0}, 70.0, 58.0)
|
||
check('上限设 0(不限)→ 结案', f is True, (f, gap, pct))
|
||
f, _, _ = gap_of({'short_close_max_qty': 15}, 70.0, 58.0)
|
||
check('上限调到 15 斤 → 结案', f is True)
|
||
|
||
print('四、关掉 / 分拣站不适用')
|
||
f, _, _ = gap_of({'short_close_pct': 0}, 10.0, 9.88)
|
||
check('short_close_pct=0 → 关闭', f is False)
|
||
f, _, _ = gap_of({}, 10.0, 9.88, station='picking')
|
||
check('分拣站不自动结案', f is False)
|
||
|
||
print('五、非重量单位(件/箱)只看百分比')
|
||
f, gap, pct = gap_of({}, 5.0, 4.6, unit='件')
|
||
check('件:差 8% → 结案', f is True, (f, gap, pct))
|
||
f, _, _ = gap_of({}, 5.0, 3.9, unit='箱')
|
||
check('箱:差 22% → 不结案', f is False)
|
||
|
||
print('六、提交请求体确实带 force_complete')
|
||
api = ApiClient.__new__(ApiClient)
|
||
api.mock = False
|
||
api.cfg = {'inspection_quality_rating': '合格'}
|
||
|
||
|
||
def _fake_request(method, path, body=None):
|
||
_fake_request.body = body
|
||
return {'success': True}
|
||
|
||
|
||
api._request = _fake_request
|
||
api.commit_inspection([row(10.0, '斤')], 9.88, 4.94, 'op-x',
|
||
scope_token='tok-1', force_complete=True)
|
||
b = getattr(_fake_request, 'body', {}) or {}
|
||
check('force_complete=True 已发送', b.get('force_complete') is True, b)
|
||
check('实收数量仍是真实 9.88', float(b.get('actual_qty') or 0) == 9.88, b)
|
||
api.commit_inspection([row(10.0, '斤')], 9.88, 4.94, 'op-y',
|
||
scope_token='tok-2')
|
||
b = getattr(_fake_request, 'body', {}) or {}
|
||
check('默认不带 force(旧行为不变)', b.get('force_complete') is False, b)
|
||
|
||
print('七、成功提示带上短收说明')
|
||
fake = Fake()
|
||
fake._force_note = '|短收 0.12 斤(1.2%),已按完整结案'
|
||
check('force 提示语沿用短收说明',
|
||
'短收 0.12' in fake._success_extra('force', {}))
|
||
fake2 = Fake()
|
||
check('无短收说明时回退原提示',
|
||
'偏差结案' in fake2._success_extra('force', {}))
|
||
check('普通成功不加尾巴', fake2._success_extra('ok', {}) == '')
|
||
|
||
print('\n结果:%d 通过 / %d 失败' % (ok, fail))
|
||
sys.exit(1 if fail else 0)
|