96 lines
4.9 KiB
JavaScript
96 lines
4.9 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
|
|
// 以 f1a4e69 中 server/routes/orders.routes.js:141 的通用路由和
|
|
// core/ledger.js:1949 的业务分支为底册。具体的 /edit、/canceltoday 等由独立路由先匹配。
|
|
export const orderActionCoverage = {
|
|
receipt: { step: '旧单信用卡收款并计入手续费' },
|
|
refund: { step: '助理同日直接登记全额退款' },
|
|
expense: { step: '助理同日直接登记额外费用' },
|
|
fees: { step: '旧单补记实际费用及付款人' },
|
|
cost: { step: '旧单补齐多行料费和工费' },
|
|
complete: { step: '补齐旧单账务并扣库存' },
|
|
return: { step: '助理同日整单退回按对货盘', afterSaleStep: '原单售后登记退款和退货' },
|
|
correct: { step: '店主更正旧单收款流水' },
|
|
review: { step: '店主复核旧单' },
|
|
print: { step: '打开订单客户打印预览并登记审计' },
|
|
confirm: {
|
|
reason:
|
|
'旧草稿点「继续填写并开单」后通过 /api/orders/issue 提交,开单事务内执行 confirm。详情没有独立确认草稿按钮。',
|
|
sources: ['public/app.js:4091', 'public/app.js:7290', 'core/ledger.js:1485'],
|
|
},
|
|
deliver: {
|
|
reason: '已确认旧单点「补齐旧单账务」提交 complete,由该事务内部执行 deliver。详情没有单独的 deliver 按钮。',
|
|
sources: ['public/app.js:4099', 'core/ledger.js:2162'],
|
|
},
|
|
cancel: {
|
|
reason: '旧 cancel 操作直接返回 409。当前入口依据业务日期提交 canceltoday 或 cancellation。',
|
|
sources: ['core/ledger.js:1961', 'public/order-cancellations-ui.js:182', 'public/order-cancellations-ui.js:331'],
|
|
},
|
|
material: {
|
|
reason: '服务端保留订单料费重新分配操作。旧详情料费待补的入口打开「每日购料」,详情动作列表没有提交该接口的控件。',
|
|
sources: ['core/ledger.js:2276', 'public/app.js:4065', 'public/material-pools-ui.js:1649'],
|
|
},
|
|
settlement: {
|
|
reason:
|
|
'历史双人模式有单笔交款控件,仅在 !teamMode() 显示。正式和演示服务启动时均启用团队模式,个人余额和转账在团队账目、每日对账登记。',
|
|
sources: ['public/app.js:583', 'public/app.js:4124', 'server/app.js:31', 'core/ledger.js:1959'],
|
|
},
|
|
};
|
|
|
|
// 普通改单和锁价改单均省略 action,后端按 edit 处理。
|
|
// 旧版整单退货与原单售后均提交 action=return,由 afterSale 的存在区分。
|
|
// 对照 public/order-edit-ui.js:1071、public/order-changes-ui.js:529、
|
|
// public/order-after-sales-ui.js:371 和 domains/orders/order-changes.js:670。
|
|
export const orderChangeCoverage = {
|
|
edit: { steps: ['助理申请修改普通订单待批准', '助理申请修改普通订单待驳回', '助理申请修改跨日已交付料池锁价单'] },
|
|
expense: { steps: ['助理申请跨日额外费用', '跨过营业日保留原输入转为审批'] },
|
|
fees: { steps: ['助理申请跨日补记旧单费用'] },
|
|
refund: { steps: ['助理申请跨日实际退款'] },
|
|
return: { steps: ['助理申请跨日整单退货'], afterSaleSteps: ['助理提交跨日原单售后申请'] },
|
|
cost: { steps: ['助理申请补录旧单货品成本'] },
|
|
};
|
|
|
|
export function assertOrderChangeBody(step, body) {
|
|
const [action, record] =
|
|
Object.entries(orderChangeCoverage).find(([, entry]) =>
|
|
[...entry.steps, ...(entry.afterSaleSteps || [])].includes(step),
|
|
) || [];
|
|
assert.ok(action, '订单变更申请缺少场景映射 ' + step);
|
|
assert.ok(Number.isSafeInteger(body.revision));
|
|
assert.ok(body.reason.trim());
|
|
assert.equal(body.verified, true);
|
|
assert.match(body.date, /^\d{4}-\d{2}-\d{2}$/);
|
|
if (action === 'edit') {
|
|
assert.equal(Object.hasOwn(body, 'action'), false);
|
|
assert.ok(body.lines.length > 0);
|
|
if (step === '助理申请修改跨日已交付料池锁价单') assert.ok(body.price_lock_material);
|
|
return;
|
|
}
|
|
assert.equal(body.action, action);
|
|
if (action === 'return') {
|
|
if (record.afterSaleSteps.includes(step)) {
|
|
assert.ok(body.afterSale.lines.length > 0);
|
|
assert.ok(body.afterSale.refund.account);
|
|
assert.ok(Object.hasOwn(body.afterSale.refund, 'amount'));
|
|
assert.ok(Array.isArray(body.afterSale.expenses));
|
|
} else {
|
|
assert.equal(Object.hasOwn(body, 'afterSale'), false);
|
|
assert.ok(body.returnPockets.length > 0);
|
|
assert.equal(body.returnCounts.length, body.returnPockets.length);
|
|
}
|
|
return;
|
|
}
|
|
assert.equal(body.reason, body.change_reason.trim());
|
|
if (action === 'fees') {
|
|
assert.ok(body.fee_items.length > 0);
|
|
assert.ok(body.fee_items.every(f => f.payer && Object.hasOwn(f, 'amount')));
|
|
} else if (action === 'cost') {
|
|
assert.ok(body.costs.length > 0);
|
|
assert.ok(body.costs.every(c => c.parts && c.costMaterial && c.costLabor && c.costPayers && c.payer));
|
|
} else {
|
|
assert.ok(body.amount);
|
|
if (action === 'refund') assert.ok(body.account && body.payment_method);
|
|
if (action === 'expense') assert.ok(body.note && body.payer);
|
|
}
|
|
}
|