Files
windows-fenjian/tools/_test_group_inbound.py

64 lines
2.8 KiB
Python

# -*- coding: utf-8 -*-
"""Windows 分组入库(v1.0.66):pending-grouped 行转换 + complete-merge-group 请求体。"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from core.api.client import ApiClient, ApiError
CFG = {'server': {'base_url': 'http://127.0.0.1:3001/api', 'mock': False},
'account': {'username': 'demo', 'password': 'x', 'role': 'inspector'},
'flow': {'group_inbound': True}}
def check(name, cond, detail=''):
print(('PASS' if cond else 'FAIL'), name, detail)
if not cond:
sys.exit(1)
api = ApiClient(CFG)
groups = [{
'group_key': 'BR003|-|purchase|order|SKU1|斤',
'group_hash': 'gh-1',
'branch_code': 'BR003',
'supplier_code': None,
'source_type': 'purchase',
'sku_code': 'SKU1',
'item_name': '土豆',
'unit': '斤',
'total_prepare_qty': 55,
'order_count': 2,
'inspection_ids': ['ins-1', 'ins-2'],
'requires_photo_inspection': False,
'lines': [
{'inspection_id': 'ins-1', 'order_code': 'O1', 'prepare_qty': 17},
{'inspection_id': 'ins-2', 'order_code': 'O2', 'prepare_qty': 38},
],
}]
flat = [{'id': 'ins-1', 'order_code': 'O1', 'customer_name': '客户A',
'prepare_qty': 17, 'unit': '斤', 'requires_photo_inspection': False},
{'id': 'ins-2', 'order_code': 'O2', 'customer_name': '客户B',
'prepare_qty': 38, 'unit': '斤', 'requires_photo_inspection': False}]
rows = api._preview_group_rows(groups, flat)
check('一组转成一行', len(rows) == 1, str(rows))
row = rows[0]
check('保存整组ID', row.get('inspection_ids') == ['ins-1', 'ins-2'])
check('组总量作为应量', row.get('required_qty') == 55 and row.get('prepare_qty') == 55)
check('组键/哈希带到行', row.get('group_key') and row.get('group_hash') == 'gh-1')
check('首行订单号/客户元数据保留', row.get('order_code') == 'O1' and row.get('customer_name') == '客户A')
check('组行标记', row.get('grouped_inbound') is True)
# mock request capture
calls = []
def fake_request(method, path, body=None, **kw):
calls.append((method, path, body))
return {'success': True, 'data': {'merged': True, 'mergedCount': 2}}
api._request = fake_request
resp = api.commit_inspection_group(row, 55, 27.5, 'op-1', force_complete=True)
check('走分组接口', calls and calls[0][1] == '/mobile/inspection/complete-merge-group', str(calls))
body = calls[0][2]
check('整组ID在请求体', body.get('inspection_ids') == ['ins-1', 'ins-2'])
check('批量实收一次传', body.get('actual_qty') == 55)
check('偏差入库 force_complete 透传', body.get('force_complete') is True)
check('质量中文', body.get('quality_rating') == '合格')
check('回包归一成功', resp.get('operation_status') == 'committed_by_this_operation')
print('ALL GROUP INBOUND CHECKS PASSED')