Files

90 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""v1.0.43 回归(v1.0.61 已改写):数量按待办带出,0 不被兜成 1
原始 bug:AI 没认出(还没选商品、待办数量 0)时,提示写「数量按待办给 0」,
数量框里却显示 1 —— float(business or 1) 把 0 兜成了 1。
v1.0.61 把确认条整块撤掉后,数量框不再显示在屏幕上(数件的行点卡进
免称重核对页改数量),但「带出来的数量不许被兜成 1」这条仍然有效:
var_fqty 是确认时真正提交的数量,_on_focus 必须照实写。
"""
import json
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__))))
import tkinter as tk
import ui.app as A
FAILED = []
def check(name, cond, extra=''):
print((' ok ' if cond else ' FAIL') + ' ' + name +
('' if cond else ' ← %s' % (extra,)))
if not cond:
FAILED.append(name)
cfg = json.load(open('config.json', encoding='utf-8'))
cfg.setdefault('server', {})['mock'] = True
cfg['ui'] = {'mode': 'window', 'width': 1440, 'height': 900,
'borderless': True, 'todo_cols': 4}
A.load_config = lambda *a, **k: cfg
A.App._poll = lambda self: None
A.App._poll_preview = lambda self: None
root = tk.Tk()
app = A.App(root)
root.geometry('1440x900+0+0')
for w in root.winfo_children():
w.destroy()
app._build()
root.update_idletasks()
root.update()
def focus(business, row=None, mode='count'):
app._on_focus({'mode': mode, 'row_id': (row or {}).get('id'),
'row': row or {}, 'detected': '青椒', 'conf': 70,
'business': business, 'unit': '斤', 'weight': 0.0})
root.update_idletasks()
return str(app.var_fqty.get() or ''), str(app.lbl_hint.cget('text') or '')
print('[1] 待办数量 0:提示照实说 0,数量也必须是 0')
q, hint = focus(0.0, row=None)
check('数量是 0(不再被兜成 1)', q == '0', q)
check('提示行写「数量按待办 0」', '数量按待办 0' in hint, hint)
print('[2] 选中待办行:数量按待办带出来')
row = {'id': 'r1', 'item_name': '大青椒', 'unit': '斤',
'required_qty': 3, 'remaining_qty': 3, 'order_code': 'BR003_0001'}
q, hint = focus(3.0, row=row)
check('数量显示 3', q == '3', q)
q, _h = focus(0.5, row=row)
check('小数数量显示 0.5', q == '0.5', q)
print('[3] 提示行:标准名 + AI 结论 + 数量口径')
q, hint = focus(3.0, row=row)
check('以商品名开头', hint.startswith('大青椒 ·'), hint)
check('带 AI 结论', 'AI 认为「青椒」' in hint, hint)
check('带数量口径', '数量按待办 3 斤' in hint, hint)
check('带客户/供应商', 'BR003' not in hint and hint.count('·') >= 2, hint)
print('[4] 称重模式:数量行不出现,提示换成「秤读数 → 记账量」')
q, hint = focus(0.0, row=row, mode='weigh')
check('提示带称重换算', '0.00 kg → 记 0.00 斤' in hint, hint)
check('不再提示按待办给数量', '数量按待办' not in hint, hint)
root.destroy()
print('')
if FAILED:
print('FAILED %d 项: %s' % (len(FAILED), ', '.join(FAILED)))
sys.exit(1)
print('全部通过')