料池日期差异 D2:增加未经退回现货的只读对照,旧版断言缺陷仍可复现,新版断言跟随业务日期
对照单在两版走同样的业务日期往返但不选退回现货,只读取表单选中的料价日期,不提交、不改变账本。 旧版此时回到当天,证明钉在前一天是取消退回现货后的状态残留,而非业务规则。 实际开单步骤按版本断言:旧版 19 日料池 ¥625.00、利润 ¥596.75;新版 20 日料池 ¥1,017.86、利润 ¥203.89。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5700780a2c
commit
fdaa6afad5
1 file changed
+145
-37
+145
-37
@@ -235,7 +235,28 @@ export async function exerciseIssueReopen({ version, base, day, session, pageFor
|
|||||||
await page.waitForLoadState('networkidle');
|
await page.waitForLoadState('networkidle');
|
||||||
return saved;
|
return saved;
|
||||||
};
|
};
|
||||||
await ui.open(first, base);
|
const draftKeyFor = id => (version === 'old' ? 'mm-draft-' : 'mm-next-draft-') + id;
|
||||||
|
const ownerKey = draftKeyFor((await session.get('owner', '/api/session')).user.id);
|
||||||
|
const assistantKey = draftKeyFor((await session.get('assistant', '/api/session')).user.id);
|
||||||
|
const rawDraft = (page, key) => page.evaluate(k => localStorage.getItem(k), key);
|
||||||
|
const customerInput = page =>
|
||||||
|
page.locator(version === 'old' ? '#order-form input[name=customer]' : '#order-form [data-field=customer] input');
|
||||||
|
// 同一浏览器轮流登录两位用户,两份草稿共享 localStorage,能抓到误清整个存储的问题。
|
||||||
|
async function openAs(role) {
|
||||||
|
await first.context().addCookies([{ name: 'mm_session', value: session.cookies[role].slice(11), url: base }]);
|
||||||
|
await ui.open(first, base);
|
||||||
|
}
|
||||||
|
await openAs('assistant');
|
||||||
|
await fill(first, [
|
||||||
|
['customer', '店员未成交草稿'],
|
||||||
|
['line', 0, 'quantity', '0.625'],
|
||||||
|
]);
|
||||||
|
await first.waitForFunction(
|
||||||
|
key => JSON.parse(localStorage.getItem(key) || 'null')?.lines[0].quantity === '0.625',
|
||||||
|
assistantKey,
|
||||||
|
);
|
||||||
|
const assistantDraft = await rawDraft(first, assistantKey);
|
||||||
|
await openAs('owner');
|
||||||
await fill(first, [
|
await fill(first, [
|
||||||
['customer', '上一笔两件商品'],
|
['customer', '上一笔两件商品'],
|
||||||
['customerType', 'new'],
|
['customerType', 'new'],
|
||||||
@@ -244,13 +265,17 @@ export async function exerciseIssueReopen({ version, base, day, session, pageFor
|
|||||||
...line(1, '2', '900'),
|
...line(1, '2', '900'),
|
||||||
['internalNote', '上一笔普通开单'],
|
['internalNote', '上一笔普通开单'],
|
||||||
]);
|
]);
|
||||||
|
await first.reload();
|
||||||
|
await first.locator('#order-form').waitFor();
|
||||||
|
assert.equal(await customerInput(first).inputValue(), '上一笔两件商品');
|
||||||
|
assert.equal(JSON.parse(await rawDraft(first, ownerKey)).lines.length, 2);
|
||||||
await step('首笔普通两件商品完成销售', async () => {
|
await step('首笔普通两件商品完成销售', async () => {
|
||||||
const saved = await issue(first);
|
const saved = await issue(first);
|
||||||
assert.equal(saved.lines.length, 2);
|
assert.equal(saved.lines.length, 2);
|
||||||
assert.equal(saved.total, 269900);
|
assert.equal(saved.total, 269900);
|
||||||
});
|
});
|
||||||
const { user } = await session.get('owner', '/api/session');
|
assert.equal(await rawDraft(first, assistantKey), assistantDraft);
|
||||||
const draftKey = (version === 'old' ? 'mm-draft-' : 'mm-next-draft-') + user.id;
|
const draftKey = ownerKey;
|
||||||
const persisted = await first.evaluate(key => {
|
const persisted = await first.evaluate(key => {
|
||||||
const raw = localStorage.getItem(key);
|
const raw = localStorage.getItem(key);
|
||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
@@ -269,7 +294,39 @@ export async function exerciseIssueReopen({ version, base, day, session, pageFor
|
|||||||
['internalNote', '第二笔应只收一元'],
|
['internalNote', '第二笔应只收一元'],
|
||||||
]);
|
]);
|
||||||
await step('新标签页从首页录入第二笔销售', async () => {
|
await step('新标签页从首页录入第二笔销售', async () => {
|
||||||
const saved = await issue(next);
|
// 已真实入账、回应尚未到达时,在另一标签页填写第三笔。迟到的第二笔回执只能清第二笔。
|
||||||
|
await next.evaluate(() => {
|
||||||
|
const fetch = window.fetch.bind(window);
|
||||||
|
window.fetch = async (...args) => {
|
||||||
|
const res = await fetch(...args);
|
||||||
|
if (new URL(res.url).pathname === '/api/orders/issue') {
|
||||||
|
await new Promise(resolve => {
|
||||||
|
window.releaseIssuedReceipt = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const pending = issue(next);
|
||||||
|
const editThirdDraft = async () => {
|
||||||
|
await next.waitForFunction(() => typeof window.releaseIssuedReceipt === 'function');
|
||||||
|
const third = await pageFor('owner', { fresh: true });
|
||||||
|
await fill(third, [
|
||||||
|
['customer', '第三笔未成交草稿'],
|
||||||
|
['line', 0, 'quantity', '1.375'],
|
||||||
|
]);
|
||||||
|
await third.waitForFunction(
|
||||||
|
key => JSON.parse(localStorage.getItem(key) || 'null')?.lines[0].quantity === '1.375',
|
||||||
|
ownerKey,
|
||||||
|
);
|
||||||
|
const input = await rawDraft(third, ownerKey);
|
||||||
|
await next.evaluate(() => window.releaseIssuedReceipt());
|
||||||
|
return input;
|
||||||
|
};
|
||||||
|
const [saved, thirdDraft] = await Promise.all([pending, editThirdDraft()]);
|
||||||
|
if (version === 'new')
|
||||||
|
assert.equal(await rawDraft(next, ownerKey), thirdDraft, '第二笔回执清除了另一页填写的第三笔');
|
||||||
|
assert.equal(await rawDraft(next, assistantKey), assistantDraft, '第二笔回执清除了店员的草稿');
|
||||||
const evidence = JSON.stringify({
|
const evidence = JSON.stringify({
|
||||||
persisted,
|
persisted,
|
||||||
initialRows,
|
initialRows,
|
||||||
@@ -283,8 +340,19 @@ export async function exerciseIssueReopen({ version, base, day, session, pageFor
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 非滚动料池同时存在两天料价时,业务日期往返会实际改变所选批次的成本和利润。
|
// 已确认差异 D2(旧版缺陷登记,见 e2e/逐笔写入基线.md):
|
||||||
export async function exerciseIssuePoolDate({ version, base, day, session, pageFor, step }) {
|
// 料价日期默认跟随业务日期,只有手动选过料价日期才固定。旧版选中退回现货时把料价日期固定为批次日期,
|
||||||
|
// 取消选择只恢复输入值、不恢复「跟随业务日期」,之后业务日期往返会把订单钉在前一天的料池。
|
||||||
|
// 对照只读取表单:同样的日期往返但不经过退回现货,证明旧版自身的规则也是跟随业务日期。
|
||||||
|
export async function exerciseIssuePoolDate({
|
||||||
|
version,
|
||||||
|
base,
|
||||||
|
day,
|
||||||
|
session,
|
||||||
|
pageFor,
|
||||||
|
step,
|
||||||
|
selectOrderDatePool = false,
|
||||||
|
}) {
|
||||||
const yesterday = '2026-11-19',
|
const yesterday = '2026-11-19',
|
||||||
ui = version === 'old' ? oldUi : newUi;
|
ui = version === 'old' ? oldUi : newUi;
|
||||||
const { lot } = await seedReturnedLot(session, day);
|
const { lot } = await seedReturnedLot(session, day);
|
||||||
@@ -303,31 +371,30 @@ export async function exerciseIssuePoolDate({ version, base, day, session, pageF
|
|||||||
note: '当日购料',
|
note: '当日购料',
|
||||||
});
|
});
|
||||||
const page = await pageFor('owner');
|
const page = await pageFor('owner');
|
||||||
await ui.open(page, base);
|
const fillSale = async customer => {
|
||||||
for (const input of [
|
for (const input of [
|
||||||
['customer', '退回现货切换日期'],
|
['customer', customer],
|
||||||
['customerType', 'new'],
|
['customerType', 'new'],
|
||||||
['internalNote', '核实重新选用料池'],
|
['internalNote', '核实重新选用料池'],
|
||||||
['line', 0, 'quantity', '1.250'],
|
['line', 0, 'quantity', '1.250'],
|
||||||
['line', 0, 'goldPrice', '971.25'],
|
['line', 0, 'goldPrice', '971.25'],
|
||||||
['line', 0, 'laborRate', '8.50'],
|
['line', 0, 'laborRate', '8.50'],
|
||||||
['line', 0, 'cost-materialRate', '832.25'],
|
['line', 0, 'cost-materialRate', '832.25'],
|
||||||
['line', 0, 'cost-labor', '3.25'],
|
['line', 0, 'cost-labor', '3.25'],
|
||||||
])
|
])
|
||||||
await ui.step(page, input);
|
await ui.step(page, input);
|
||||||
const select = ui.line(page, 0).locator('[name=returnedStockId]');
|
};
|
||||||
await select.selectOption(lot.id);
|
const toggleDate = async () => {
|
||||||
await select.selectOption('');
|
const date = page
|
||||||
await ui.step(page, ['line', 0, 'materialSource', 'pool']);
|
.locator(version === 'old' ? '#order-form [name=date]' : '#order-form [data-field=date] input')
|
||||||
const date = page
|
.first();
|
||||||
.locator(version === 'old' ? '#order-form [name=date]' : '#order-form [data-field=date] input')
|
for (const d of [yesterday, day]) {
|
||||||
.first();
|
await date.fill(d);
|
||||||
for (const d of [yesterday, day]) {
|
await date.blur();
|
||||||
await date.fill(d);
|
await page.waitForLoadState('networkidle');
|
||||||
await date.blur();
|
}
|
||||||
await page.waitForLoadState('networkidle');
|
};
|
||||||
}
|
const issue = async () => {
|
||||||
await step('撤销退回现货选择并切换日期后按料池实际开单', async () => {
|
|
||||||
const [response, shown] = await Promise.all([
|
const [response, shown] = await Promise.all([
|
||||||
page.waitForResponse(r => r.request().method() === 'POST' && new URL(r.url()).pathname === '/api/orders/issue'),
|
page.waitForResponse(r => r.request().method() === 'POST' && new URL(r.url()).pathname === '/api/orders/issue'),
|
||||||
ui.submit(page),
|
ui.submit(page),
|
||||||
@@ -336,14 +403,55 @@ export async function exerciseIssuePoolDate({ version, base, day, session, pageF
|
|||||||
const { id } = await response.json(),
|
const { id } = await response.json(),
|
||||||
order = await session.get('owner', '/api/orders/' + id);
|
order = await session.get('owner', '/api/orders/' + id);
|
||||||
assert.equal(order.paper_number, shown.paper);
|
assert.equal(order.paper_number, shown.paper);
|
||||||
const evidence = JSON.stringify({
|
await page.waitForLoadState('networkidle');
|
||||||
|
return {
|
||||||
|
poolId: order.lines[0].costMaterial?.poolId,
|
||||||
sale: order.total,
|
sale: order.total,
|
||||||
pool: response.request().postDataJSON().lines[0].costMaterial,
|
|
||||||
material: order.lines[0].costParts.material,
|
material: order.lines[0].costParts.material,
|
||||||
profit: order.profit,
|
profit: order.profit,
|
||||||
});
|
};
|
||||||
assert.equal(order.lines[0].costMaterial.poolId, yesterday, '原选料池随业务日期切换:' + evidence);
|
};
|
||||||
assert.equal(order.lines[0].costParts.material, 62500, evidence);
|
|
||||||
assert.equal(order.profit, 59675, evidence);
|
// 对照:同样输入和日期往返,但不经过退回现货,只读取表单选中的料价日期,不提交,不改变账本。
|
||||||
|
// 旧版在这里跟随业务日期回到当天,证明 D2 是取消退回现货时的状态残留,而非旧版的业务规则。
|
||||||
|
const selectedPoolDate = async () => {
|
||||||
|
const field = ui.line(page, 0);
|
||||||
|
if (version === 'old') return field.locator('[name="cost-materialPoolId"]').inputValue();
|
||||||
|
const label = await field.locator('[data-field="materialPoolId"] .ant-select-selection-item').innerText();
|
||||||
|
return label.match(/\d{4}-\d{2}-\d{2}/)?.[0];
|
||||||
|
};
|
||||||
|
await ui.open(page, base);
|
||||||
|
await fillSale('料池日期对照');
|
||||||
|
await ui.step(page, ['line', 0, 'materialSource', 'pool']);
|
||||||
|
await toggleDate();
|
||||||
|
assert.equal(await selectedPoolDate(), day, version + ' 未经退回现货时料价日期应跟随业务日期');
|
||||||
|
await page.evaluate(() => {
|
||||||
|
for (const key of Object.keys(localStorage))
|
||||||
|
if (key.startsWith('mm-draft-') || key.startsWith('mm-next-draft-')) localStorage.removeItem(key);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 1.250g × 当日加权料价 814.29 元/克 = 1,017.86 元;前一天料池为 500 元/克,即 625.00 元。
|
||||||
|
await ui.open(page, base);
|
||||||
|
await fillSale('退回现货切换日期');
|
||||||
|
const select = ui.line(page, 0).locator('[name=returnedStockId]');
|
||||||
|
await select.selectOption(lot.id);
|
||||||
|
await select.selectOption('');
|
||||||
|
await ui.step(page, ['line', 0, 'materialSource', 'pool']);
|
||||||
|
await toggleDate();
|
||||||
|
await step('撤销退回现货选择并切换日期后按料池实际开单', async () => {
|
||||||
|
const result = await issue(),
|
||||||
|
evidence = JSON.stringify(result);
|
||||||
|
assert.equal(result.sale, 122500, evidence);
|
||||||
|
if (version === 'old') {
|
||||||
|
// 登记的旧版缺陷仍可复现:仅因选过又取消退回现货,订单被钉在前一天料池。
|
||||||
|
assert.equal(result.poolId, yesterday, '旧版缺陷 D2 未复现:' + evidence);
|
||||||
|
assert.equal(result.material, 62500, evidence);
|
||||||
|
assert.equal(result.profit, 59675, evidence);
|
||||||
|
} else {
|
||||||
|
// 已确认行为:取消退回现货后料价日期回到跟随业务日期。
|
||||||
|
assert.equal(result.poolId, day, '取消退回现货后料价日期应跟随业务日期:' + evidence);
|
||||||
|
assert.equal(result.material, 101786, evidence);
|
||||||
|
assert.equal(result.profit, 20389, evidence);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user