2026-10-23 09:49:36 +08:00
|
|
|
|
'use strict';
|
2026-12-04 08:58:53 -08:00
|
|
|
|
const test = require('node:test'),
|
|
|
|
|
|
assert = require('node:assert/strict'),
|
|
|
|
|
|
fs = require('node:fs'),
|
|
|
|
|
|
path = require('node:path'),
|
|
|
|
|
|
vm = require('node:vm');
|
|
|
|
|
|
const { randomUUID } = require('node:crypto'),
|
|
|
|
|
|
Calc = require('../public/calculations');
|
|
|
|
|
|
const ID = '11111111-1111-4111-8111-111111111111',
|
|
|
|
|
|
RID = '22222222-2222-4222-8222-222222222222',
|
|
|
|
|
|
RELATED = '33333333-3333-4333-8333-333333333333',
|
|
|
|
|
|
D = '2026-10-22';
|
|
|
|
|
|
function order(extra = {}) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
id: ID,
|
|
|
|
|
|
revision: 7,
|
|
|
|
|
|
number: 'XS20261022001',
|
|
|
|
|
|
paper_number: '20261022001',
|
|
|
|
|
|
date: D,
|
|
|
|
|
|
status: 'delivered',
|
|
|
|
|
|
customer: '原客户',
|
|
|
|
|
|
salesperson: '助理',
|
|
|
|
|
|
payment_account: '助理微信',
|
|
|
|
|
|
total: 210000,
|
|
|
|
|
|
rounding_mode: 'cent',
|
|
|
|
|
|
discount: 0,
|
|
|
|
|
|
profit: 28000,
|
|
|
|
|
|
directCost: 2000,
|
|
|
|
|
|
goodsCost: 180000,
|
|
|
|
|
|
ownerCost: 180000,
|
|
|
|
|
|
netReceived: 210000,
|
|
|
|
|
|
balance: 0,
|
|
|
|
|
|
settlementDue: 208000,
|
|
|
|
|
|
costDue: 180000,
|
|
|
|
|
|
profitDue: 28000,
|
|
|
|
|
|
costTransferred: 0,
|
|
|
|
|
|
profitTransferred: 0,
|
|
|
|
|
|
ownerDirect: 0,
|
|
|
|
|
|
reviewed_revision: 0,
|
|
|
|
|
|
lines: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '足金999',
|
|
|
|
|
|
priceNote: '金价900+工费150',
|
|
|
|
|
|
unit: 'g',
|
|
|
|
|
|
quantity: 2000,
|
|
|
|
|
|
sale: 210000,
|
|
|
|
|
|
pocket: '现货',
|
|
|
|
|
|
cost: 180000,
|
|
|
|
|
|
payer: 'owner',
|
|
|
|
|
|
costParts: { material: 170000, labor: 10000, accessories: 0, other: 0 },
|
|
|
|
|
|
costPayers: { material: 'owner', labor: 'assistant' },
|
|
|
|
|
|
costMaterial: { mode: 'gram', rate: 85000 },
|
|
|
|
|
|
costLabor: { mode: 'total' },
|
|
|
|
|
|
charges: [{ name: '包装', amount: 1000 }],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
payments: [{ id: 'pay', date: D, kind: 'receipt', amount: 210000, account: '助理微信' }],
|
|
|
|
|
|
expenses: [{ id: 'fee', date: D, amount: 2000, payer: 'assistant', note: '快递' }],
|
|
|
|
|
|
settlements: [],
|
|
|
|
|
|
corrections: [],
|
|
|
|
|
|
pendingFees: [],
|
|
|
|
|
|
fee_items: [],
|
|
|
|
|
|
audit: [],
|
|
|
|
|
|
note: '原备注',
|
|
|
|
|
|
...extra,
|
|
|
|
|
|
};
|
2026-10-23 09:49:36 +08:00
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
function summary(o) {
|
|
|
|
|
|
return Object.fromEntries(
|
|
|
|
|
|
['total', 'netReceived', 'goodsCost', 'directCost', 'profit', 'settlementDue'].map(key => [key, o[key]]),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
function request(extra = {}) {
|
|
|
|
|
|
const before = order(),
|
|
|
|
|
|
after = order({
|
|
|
|
|
|
customer: '申请客户',
|
|
|
|
|
|
salesperson: '新开单人',
|
|
|
|
|
|
payment_account: '麦麦支付宝',
|
|
|
|
|
|
note: '申请备注',
|
|
|
|
|
|
date: '2026-10-21',
|
|
|
|
|
|
rounding_mode: 'yuan',
|
|
|
|
|
|
delivered_date: D,
|
|
|
|
|
|
total: 220000,
|
|
|
|
|
|
netReceived: 220000,
|
|
|
|
|
|
goodsCost: 190000,
|
|
|
|
|
|
directCost: 3000,
|
|
|
|
|
|
profit: 27000,
|
|
|
|
|
|
settlementDue: 27000,
|
|
|
|
|
|
lines: [
|
|
|
|
|
|
{
|
|
|
|
|
|
...before.lines[0],
|
|
|
|
|
|
code: '新商品编号',
|
|
|
|
|
|
quantity: 2500,
|
|
|
|
|
|
sale: 220000,
|
|
|
|
|
|
cost: 190000,
|
|
|
|
|
|
costParts: { material: 180000, labor: 10000, accessories: 0, other: 0 },
|
|
|
|
|
|
costPayers: { material: 'assistant', labor: 'owner' },
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
expenses: [{ id: 'newfee', date: '2026-10-21', amount: 3000, payer: 'owner', note: '更正快递' }],
|
|
|
|
|
|
payments: [{ id: 'newpay', date: '2026-10-21', kind: 'receipt', amount: 220000, account: '麦麦支付宝' }],
|
|
|
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
|
|
|
id: RID,
|
|
|
|
|
|
order_id: ID,
|
|
|
|
|
|
order_number: 'XS20261022001',
|
|
|
|
|
|
order_date: D,
|
|
|
|
|
|
order_status: 'delivered',
|
|
|
|
|
|
order_revision: 7,
|
|
|
|
|
|
reason: '实称克重和收款账户录错',
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
requester_name: '助理',
|
|
|
|
|
|
created: D + 'T08:00:00.000Z',
|
|
|
|
|
|
reviewer_name: null,
|
|
|
|
|
|
reviewed: null,
|
|
|
|
|
|
note: '',
|
|
|
|
|
|
stale: false,
|
|
|
|
|
|
canApprove: true,
|
|
|
|
|
|
before,
|
|
|
|
|
|
after,
|
|
|
|
|
|
summary: { before: summary(before), after: summary(after) },
|
|
|
|
|
|
relatedOrders: [],
|
|
|
|
|
|
...extra,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
function detail(pending = null, extra = {}) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
eligible: !pending,
|
|
|
|
|
|
reason: pending ? '已有待审修改' : '',
|
|
|
|
|
|
revision: 7,
|
|
|
|
|
|
pending,
|
|
|
|
|
|
requests: pending ? [pending] : [],
|
|
|
|
|
|
canApprove: true,
|
|
|
|
|
|
...extra,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
function node(extra = {}) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
innerHTML: '',
|
|
|
|
|
|
textContent: '',
|
|
|
|
|
|
hidden: false,
|
|
|
|
|
|
disabled: false,
|
|
|
|
|
|
dataset: {},
|
|
|
|
|
|
classList: { toggle() {} },
|
|
|
|
|
|
setAttribute() {},
|
|
|
|
|
|
scrollIntoView() {},
|
|
|
|
|
|
focus() {},
|
|
|
|
|
|
...extra,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
function harness(role = 'owner') {
|
|
|
|
|
|
const saved = new Map(),
|
|
|
|
|
|
nodes = new Map(),
|
|
|
|
|
|
calls = [],
|
|
|
|
|
|
handlers = {},
|
|
|
|
|
|
toasts = [];
|
|
|
|
|
|
for (const selector of [
|
|
|
|
|
|
'#main',
|
|
|
|
|
|
'#order-content',
|
|
|
|
|
|
'#detail-form',
|
|
|
|
|
|
'#detail-error',
|
|
|
|
|
|
'#order-change-error',
|
|
|
|
|
|
'#pending',
|
|
|
|
|
|
'#order-changes-entry',
|
|
|
|
|
|
])
|
|
|
|
|
|
nodes.set(selector, node());
|
|
|
|
|
|
nodes.set(
|
|
|
|
|
|
'#order-dialog',
|
|
|
|
|
|
node({
|
|
|
|
|
|
open: true,
|
|
|
|
|
|
showModal() {
|
|
|
|
|
|
this.open = true;
|
|
|
|
|
|
},
|
|
|
|
|
|
close() {
|
|
|
|
|
|
this.open = false;
|
|
|
|
|
|
},
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
|
|
|
|
|
const context = vm.createContext({
|
|
|
|
|
|
LedgerCalc: Calc,
|
|
|
|
|
|
crypto: { randomUUID },
|
|
|
|
|
|
URLSearchParams,
|
|
|
|
|
|
console,
|
|
|
|
|
|
setInterval() {},
|
|
|
|
|
|
setTimeout() {},
|
|
|
|
|
|
clearTimeout() {},
|
|
|
|
|
|
document: {
|
|
|
|
|
|
querySelector: selector => nodes.get(selector) || null,
|
|
|
|
|
|
querySelectorAll() {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
},
|
|
|
|
|
|
addEventListener(type, handler) {
|
|
|
|
|
|
(handlers[type] ??= []).push(handler);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
window: { scrollTo() {} },
|
|
|
|
|
|
localStorage: {
|
|
|
|
|
|
getItem: key => saved.get(key) ?? null,
|
|
|
|
|
|
setItem: (key, value) => saved.set(key, String(value)),
|
|
|
|
|
|
removeItem: key => saved.delete(key),
|
|
|
|
|
|
},
|
|
|
|
|
|
sessionStorage: {
|
|
|
|
|
|
getItem() {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
},
|
|
|
|
|
|
setItem() {},
|
|
|
|
|
|
},
|
|
|
|
|
|
__calls: calls,
|
|
|
|
|
|
__toasts: toasts,
|
|
|
|
|
|
__order: order(),
|
|
|
|
|
|
__detail: detail(),
|
|
|
|
|
|
__request: request(),
|
|
|
|
|
|
__form: null,
|
|
|
|
|
|
__finished: null,
|
|
|
|
|
|
});
|
|
|
|
|
|
const run = code => vm.runInContext(code, context),
|
|
|
|
|
|
json = code => JSON.parse(JSON.stringify(run(code)));
|
|
|
|
|
|
for (const file of ['order-cancellations-ui.js', 'order-changes-ui.js', 'app.js'])
|
|
|
|
|
|
run(fs.readFileSync(path.join(__dirname, '../public', file), 'utf8').replace(/\ninit\(\);\s*$/, ''));
|
|
|
|
|
|
run(`session={user:{id:'change-user',name:'${role === 'owner' ? '麦麦' : '助理'}',role:'${role}'}};state={user:session.user,today:'2026-10-23',pockets:['现货','金料']};tab='orders';currentOrder=__order;
|
2026-10-23 09:49:36 +08:00
|
|
|
|
api=async function(url,data,key){__calls.push({url,data,key});return __detail;};toast=function(message,error){__toasts.push({message,error});};
|
|
|
|
|
|
invalidateMaterialPools=function(){};invalidateReport=function(){};invalidatePriceLockViews=function(){};materialPoolOrderNoticeHTML=function(){return '';};materialPoolLineCostHTML=function(){return '';};priceLockInventoryCreditHTML=function(){return '';};
|
|
|
|
|
|
profitSummary=function(){return {title:'利润',value:'¥280.00',hint:''};};useOrderChangeDetail(currentOrder,__detail);`);
|
2026-12-04 08:58:53 -08:00
|
|
|
|
function prepare(pending = null, extra = {}) {
|
|
|
|
|
|
context.__detail = detail(pending, extra);
|
|
|
|
|
|
run('useOrderChangeDetail(currentOrder,__detail)');
|
|
|
|
|
|
}
|
|
|
|
|
|
function form(kind, values = {}) {
|
2026-10-23 09:49:36 +08:00
|
|
|
|
run(`showOrderChangeForm('${kind}')`);
|
2026-12-04 08:58:53 -08:00
|
|
|
|
const fields = Object.fromEntries(
|
|
|
|
|
|
Object.entries({ note: '', verified: false, ...values }).map(([name, value]) => [
|
|
|
|
|
|
name,
|
|
|
|
|
|
node({ name, value: typeof value === 'boolean' ? 'on' : value, checked: value === true }),
|
|
|
|
|
|
]),
|
|
|
|
|
|
);
|
|
|
|
|
|
const submit = node({ type: 'submit' }),
|
|
|
|
|
|
close = node({ dataset: { action: 'close-order-change-form' } }),
|
|
|
|
|
|
reload = node({ dataset: { action: 'reload-order-change' } }),
|
|
|
|
|
|
retry = node({ dataset: { action: 'retry' } }),
|
|
|
|
|
|
controls = [...Object.values(fields), submit, close, reload, retry];
|
|
|
|
|
|
const f = node({
|
|
|
|
|
|
id: 'order-change-form',
|
|
|
|
|
|
dataset: { kind },
|
|
|
|
|
|
querySelector(selector) {
|
|
|
|
|
|
const name = selector.match(/\[name="([^"]+)"\]/)?.[1];
|
|
|
|
|
|
return fields[name] || null;
|
|
|
|
|
|
},
|
|
|
|
|
|
querySelectorAll() {
|
|
|
|
|
|
return controls;
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
nodes.set('#order-change-form', f);
|
|
|
|
|
|
nodes.set('#order-change-form [name="verified"]', fields.verified);
|
|
|
|
|
|
context.__form = f;
|
|
|
|
|
|
return { form: f, fields, submit, close, reload, retry };
|
2026-10-23 09:49:36 +08:00
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
function actionForm(kind, values = {}) {
|
|
|
|
|
|
run('syncCostEditor=function(){};');
|
|
|
|
|
|
run(`showAction('${kind}')`);
|
|
|
|
|
|
const fields = Object.fromEntries(
|
|
|
|
|
|
Object.entries({ date: '2026-10-23', change_reason: '补充核对后的业务凭据', verified: true, ...values }).map(
|
|
|
|
|
|
([name, value]) => [
|
|
|
|
|
|
name,
|
|
|
|
|
|
node({ name, value: typeof value === 'boolean' ? 'on' : value, checked: value === true }),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
const submit = node({ type: 'submit' }),
|
|
|
|
|
|
reload = node({ dataset: { action: 'reload-order-change' } }),
|
|
|
|
|
|
retry = node({ dataset: { action: 'retry' } }),
|
|
|
|
|
|
controls = [...Object.values(fields), submit, reload, retry];
|
|
|
|
|
|
const title = node(),
|
|
|
|
|
|
f = node({
|
|
|
|
|
|
id: 'action-form',
|
|
|
|
|
|
dataset: { kind, orderChange: 'true', orderDirect: String(run(`!orderActionRequiresApproval('${kind}')`)) },
|
|
|
|
|
|
querySelector(selector) {
|
|
|
|
|
|
if (selector === 'h2') return title;
|
|
|
|
|
|
if (selector === '[data-order-action-submit]') return submit;
|
|
|
|
|
|
const name = selector.match(/\[name="([^"]+)"\]/)?.[1];
|
|
|
|
|
|
return fields[name] || null;
|
|
|
|
|
|
},
|
|
|
|
|
|
querySelectorAll() {
|
|
|
|
|
|
return controls;
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
nodes.set('#action-form', f);
|
|
|
|
|
|
nodes.set('#action-form[data-order-change="true"]', f);
|
|
|
|
|
|
nodes.set('#action-form[data-order-change="true"] [name="verified"]', fields.verified);
|
|
|
|
|
|
nodes.set('#order-action-change-error', node());
|
|
|
|
|
|
context.__form = f;
|
|
|
|
|
|
return { form: f, fields, submit, reload, retry };
|
2026-10-23 09:49:36 +08:00
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
async function click(action, attrs = {}) {
|
|
|
|
|
|
const b = node({
|
|
|
|
|
|
dataset: { action, ...attrs },
|
|
|
|
|
|
closest() {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
for (const handler of handlers.click)
|
|
|
|
|
|
await handler({
|
|
|
|
|
|
target: {
|
|
|
|
|
|
closest() {
|
|
|
|
|
|
return b;
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return { context, run, json, nodes, calls, saved, toasts, prepare, form, actionForm, click };
|
2026-10-23 09:49:36 +08:00
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
test('修改申请对照分列客户单备注与内部备注,内部原值新值均转义并保留换行', () => {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.context.__request = request({
|
|
|
|
|
|
before: order({ internal_note: '原内部备注\n<原尺寸>' }),
|
|
|
|
|
|
after: order({ internal_note: '新内部备注\n<新尺寸>' }),
|
|
|
|
|
|
});
|
|
|
|
|
|
const html = h.run('orderChangeComparisonHTML(__request)');
|
|
|
|
|
|
assert.match(html, /客户单备注/);
|
|
|
|
|
|
assert.match(html, /内部备注(客户不可见)/);
|
|
|
|
|
|
assert.match(html, /原内部备注<br><原尺寸>/);
|
|
|
|
|
|
assert.match(html, /新内部备注<br><新尺寸>/);
|
|
|
|
|
|
assert.doesNotMatch(html, /<原尺寸>|<新尺寸>/);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('订单修改复核附带同池锁价影响,关联订单不会重复渲染锁价清单', () => {
|
|
|
|
|
|
const h = harness(),
|
|
|
|
|
|
row = request(),
|
|
|
|
|
|
otherBefore = order({ id: RELATED }),
|
|
|
|
|
|
otherAfter = order({ id: RELATED, goodsCost: 190000, profit: 18000 });
|
|
|
|
|
|
row.relatedOrders = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: RELATED,
|
|
|
|
|
|
number: '合成关联订单',
|
|
|
|
|
|
before: otherBefore,
|
|
|
|
|
|
after: otherAfter,
|
|
|
|
|
|
summary: { before: summary(otherBefore), after: summary(otherAfter) },
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
row.relatedPriceLocks = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'synthetic-related-lock',
|
|
|
|
|
|
date: D,
|
|
|
|
|
|
number: '合成关联锁价',
|
|
|
|
|
|
customer: '合成<锁价客户>',
|
|
|
|
|
|
before: {
|
|
|
|
|
|
materialAmount: 85000,
|
|
|
|
|
|
usedMaterialAmount: 0,
|
|
|
|
|
|
leftoverCost: 0,
|
|
|
|
|
|
allocations: [{ payer: 'owner', amount: 85000 }],
|
|
|
|
|
|
},
|
|
|
|
|
|
after: {
|
|
|
|
|
|
materialAmount: 86000,
|
|
|
|
|
|
usedMaterialAmount: 0,
|
|
|
|
|
|
leftoverCost: 0,
|
|
|
|
|
|
allocations: [
|
|
|
|
|
|
{ payer: 'owner', amount: 80000 },
|
|
|
|
|
|
{ payer: 'assistant', amount: 6000 },
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
h.context.__request = row;
|
|
|
|
|
|
const html = h.run('orderChangeComparisonHTML(__request)');
|
|
|
|
|
|
assert.equal((html.match(/同时受影响的锁价单/g) || []).length, 1);
|
|
|
|
|
|
assert.match(html, /合成关联锁价/);
|
|
|
|
|
|
assert.match(html, /合成<锁价客户>/);
|
|
|
|
|
|
assert.match(html, /¥850\.00/);
|
|
|
|
|
|
assert.match(html, /¥860\.00/);
|
|
|
|
|
|
assert.match(html, /娜娜 ¥60\.00/);
|
|
|
|
|
|
row.relatedPriceLocks[0].after.allocations = [];
|
|
|
|
|
|
assert.throws(() => h.run('validateOrderChangeRequest(__request)'), /锁价单的成本影响未完整返回/);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('助理显示申请修改,不能审批;旧成本入口转为申请', () => {
|
|
|
|
|
|
const h = harness('assistant');
|
|
|
|
|
|
h.run('renderDetail()');
|
|
|
|
|
|
const html = h.nodes.get('#order-content').innerHTML;
|
|
|
|
|
|
assert.match(html, /申请修改/);
|
|
|
|
|
|
assert.ok(!html.includes('>修改订单<'));
|
|
|
|
|
|
h.prepare(request());
|
|
|
|
|
|
const pending = h.run('orderChangeDetailHTML(currentOrder)');
|
|
|
|
|
|
assert.match(pending, /申请尚未生效/);
|
|
|
|
|
|
assert.ok(!pending.includes('approve-order-change'));
|
|
|
|
|
|
assert.ok(!pending.includes('reject-order-change'));
|
|
|
|
|
|
assert.throws(() => h.run("showOrderChangeForm('approve')"), /店主账号/);
|
|
|
|
|
|
h.context.__order = order({ status: 'confirmed' });
|
|
|
|
|
|
h.run(
|
|
|
|
|
|
'currentOrder=__order;useOrderChangeDetail(currentOrder,{...__detail,eligible:true,pending:null,requests:[]});renderDetail()',
|
|
|
|
|
|
);
|
|
|
|
|
|
assert.match(h.nodes.get('#order-content').innerHTML, /申请补录货品成本/);
|
|
|
|
|
|
h.actionForm('cost');
|
|
|
|
|
|
assert.match(h.nodes.get('#detail-form').innerHTML, /提交变更申请/);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('麦麦批准前看到完整原值、新值和同批关联单;勾选后按原版本提交', async () => {
|
|
|
|
|
|
const h = harness(),
|
|
|
|
|
|
r = request(),
|
|
|
|
|
|
relatedBefore = order({ id: RELATED, number: 'XS关联单' }),
|
|
|
|
|
|
relatedAfter = order({ id: RELATED, number: 'XS关联单', profit: 30000, settlementDue: 200000 });
|
|
|
|
|
|
r.relatedOrders = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: RELATED,
|
|
|
|
|
|
number: 'XS关联单',
|
|
|
|
|
|
before: relatedBefore,
|
|
|
|
|
|
after: relatedAfter,
|
|
|
|
|
|
summary: { before: summary(relatedBefore), after: summary(relatedAfter) },
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
h.prepare(r);
|
|
|
|
|
|
const { fields } = h.form('approve');
|
|
|
|
|
|
const html = h.nodes.get('#detail-form').innerHTML;
|
|
|
|
|
|
for (const text of [
|
|
|
|
|
|
'原值(申请时)',
|
|
|
|
|
|
'申请值(同意后)',
|
|
|
|
|
|
'原客户',
|
|
|
|
|
|
'申请客户',
|
|
|
|
|
|
'新开单人',
|
|
|
|
|
|
'原备注',
|
|
|
|
|
|
'申请备注',
|
|
|
|
|
|
'娜娜微信',
|
|
|
|
|
|
'麦麦支付宝',
|
|
|
|
|
|
'2.000g',
|
|
|
|
|
|
'2.500g',
|
|
|
|
|
|
'商品编号',
|
|
|
|
|
|
'新商品编号',
|
|
|
|
|
|
'成交取整方式',
|
|
|
|
|
|
'四舍五入到整数元',
|
|
|
|
|
|
'保留到分',
|
|
|
|
|
|
'交付日期',
|
|
|
|
|
|
'新增费用默认支付日期',
|
|
|
|
|
|
'已修改',
|
|
|
|
|
|
'进货料价与料费',
|
|
|
|
|
|
'进货工费',
|
|
|
|
|
|
'成本付款人',
|
|
|
|
|
|
'已记实际费用/日期/付款人',
|
|
|
|
|
|
'更正快递',
|
|
|
|
|
|
'2026-10-21',
|
|
|
|
|
|
'XS关联单',
|
|
|
|
|
|
'同时受影响',
|
|
|
|
|
|
'关联订单的本次修改',
|
|
|
|
|
|
])
|
|
|
|
|
|
assert.ok(html.includes(text), text);
|
|
|
|
|
|
h.run('finishOrderChangeSave=async function(url,input,result){__finished={url,input,result};};');
|
|
|
|
|
|
await assert.rejects(h.run('submitOrderChange(__form)'), /勾选/);
|
|
|
|
|
|
assert.equal(h.calls.length, 0);
|
|
|
|
|
|
fields.verified.checked = true;
|
|
|
|
|
|
fields.note.value = '已核对凭据';
|
|
|
|
|
|
await h.run('submitOrderChange(__form)');
|
|
|
|
|
|
assert.equal(h.calls[0].url, '/api/order-changes/' + RID + '/approve');
|
|
|
|
|
|
assert.deepEqual(JSON.parse(JSON.stringify(h.calls[0].data)), { revision: 7, verified: true, note: '已核对凭据' });
|
|
|
|
|
|
});
|
|
|
|
|
|
test('过期申请只能驳回,意见必填;驳回历史保留申请人和复核人', async () => {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.prepare(request({ stale: true, canApprove: false }));
|
|
|
|
|
|
assert.ok(!h.run('orderChangeDetailHTML(currentOrder)').includes('approve-order-change'));
|
|
|
|
|
|
assert.throws(() => h.run("showOrderChangeForm('approve')"), /已有变动/);
|
|
|
|
|
|
const { fields } = h.form('reject');
|
|
|
|
|
|
h.run('finishOrderChangeSave=async function(){}');
|
|
|
|
|
|
await assert.rejects(h.run('submitOrderChange(__form)'), /驳回意见/);
|
|
|
|
|
|
fields.note.value = '请按最新克重重新核对';
|
|
|
|
|
|
await h.run('submitOrderChange(__form)');
|
|
|
|
|
|
assert.deepEqual(JSON.parse(JSON.stringify(h.calls[0].data)), { note: fields.note.value });
|
|
|
|
|
|
h.context.__request = request({
|
|
|
|
|
|
status: 'rejected',
|
|
|
|
|
|
reviewer_name: '麦麦',
|
|
|
|
|
|
reviewed: D + 'T09:00:00Z',
|
|
|
|
|
|
note: '请重核',
|
|
|
|
|
|
canApprove: false,
|
|
|
|
|
|
});
|
|
|
|
|
|
const html = h.run('orderChangeHistoryHTML(__request)');
|
|
|
|
|
|
for (const text of ['已驳回', '助理', '麦麦', '请重核', '原值']) assert.ok(html.includes(text), text);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('待审投影在独立读取失败时仍禁写,修改与取消互斥并保留打印', () => {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.context.__order = order({ changePending: { id: RID, status: 'pending' } });
|
|
|
|
|
|
h.run('currentOrder=__order;useOrderChangeDetail(currentOrder,null,new Error("读取失败"));renderDetail()');
|
|
|
|
|
|
const html = h.nodes.get('#order-content').innerHTML;
|
|
|
|
|
|
for (const action of [
|
|
|
|
|
|
'edit-order',
|
|
|
|
|
|
'show-expense',
|
|
|
|
|
|
'show-return',
|
|
|
|
|
|
'show-settlement',
|
|
|
|
|
|
'show-correct',
|
|
|
|
|
|
'show-review',
|
|
|
|
|
|
'request-order-cancellation',
|
|
|
|
|
|
])
|
|
|
|
|
|
assert.ok(!html.includes('data-action="' + action + '"'), action);
|
|
|
|
|
|
assert.ok(html.includes('data-action="print"'));
|
|
|
|
|
|
assert.match(html, /读取失败/);
|
|
|
|
|
|
assert.throws(() => h.run("showAction('return')"), /待店主复核/);
|
|
|
|
|
|
h.run('useOrderCancellationDetail(currentOrder,{eligible:true,canApprove:true,revision:7,pending:null,requests:[]})');
|
|
|
|
|
|
assert.equal(h.run('orderCancellationActionHTML(currentOrder)'), '');
|
|
|
|
|
|
assert.throws(() => h.run("showOrderCancellationForm('request')"), /修改申请待店主复核/);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('409清空修改确认、禁用旧提交并保持重新读取与恢复按钮可用', async () => {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.prepare(request());
|
|
|
|
|
|
const { fields, submit, reload, retry } = h.form('approve', { verified: true });
|
|
|
|
|
|
h.run(
|
|
|
|
|
|
"api=async function(){const err=new Error('订单或关联资料已变动');err.status=409;err.confirmed=true;throw err;};",
|
|
|
|
|
|
);
|
|
|
|
|
|
await h.run('submitOrderChange(__form)');
|
|
|
|
|
|
assert.equal(h.run('orderChangeFormEntry'), null);
|
|
|
|
|
|
assert.equal(fields.verified.checked, false);
|
|
|
|
|
|
assert.equal(submit.disabled, true);
|
|
|
|
|
|
assert.equal(reload.disabled, false);
|
|
|
|
|
|
assert.equal(retry.disabled, false);
|
|
|
|
|
|
assert.equal(h.saved.get('mm-pending-change-user'), undefined);
|
|
|
|
|
|
assert.match(h.nodes.get('#order-change-error').innerHTML, /重新读取订单并复核/);
|
|
|
|
|
|
await assert.rejects(h.run('submitOrderChange(__form)'), /重新读取/);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('修改申请和批准的断线恢复均复用原操作号,不重复新开单', async () => {
|
|
|
|
|
|
for (const url of ['/api/orders/' + ID + '/change', '/api/order-changes/' + RID + '/approve']) {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.context.__input = { revision: 7, reason: '原原因', verified: true, note: '核对' };
|
|
|
|
|
|
h.run("api=async function(url,data,key){__calls.push({url,data,key});throw new Error('响应丢失');};");
|
|
|
|
|
|
await assert.rejects(h.run(`mutate('${url}',__input)`), /恢复原操作/);
|
|
|
|
|
|
const saved = JSON.parse(h.saved.get('mm-pending-change-user'));
|
|
|
|
|
|
h.run(
|
|
|
|
|
|
"api=async function(url,data,key){__calls.push({url,data,key});return {id:'" +
|
|
|
|
|
|
ID +
|
|
|
|
|
|
"'};};finishOrderChangeSave=async function(url,input,result){__finished={url,input,result};};",
|
|
|
|
|
|
);
|
|
|
|
|
|
await h.click('retry');
|
|
|
|
|
|
assert.equal(h.calls.length, 2);
|
|
|
|
|
|
assert.equal(h.calls[1].key, saved.key);
|
|
|
|
|
|
assert.deepEqual(JSON.parse(JSON.stringify(h.calls[1].data)), saved.data);
|
|
|
|
|
|
assert.equal(h.json('__finished.url'), url);
|
|
|
|
|
|
assert.equal(h.saved.get('mm-pending-change-user'), undefined);
|
|
|
|
|
|
assert.ok(h.calls.every(call => !call.url.includes('/issue')));
|
2026-10-23 09:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-12-04 08:58:53 -08:00
|
|
|
|
test('操作成功而刷新失败只留重读入口,不恢复提交表单', async () => {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.prepare(request());
|
|
|
|
|
|
h.form('approve', { verified: true });
|
|
|
|
|
|
h.context.__savedResult = { id: ID };
|
|
|
|
|
|
h.run("refresh=async function(){throw new Error('刷新失败');};");
|
|
|
|
|
|
await h.run(`finishOrderChangeSave('/api/order-changes/${RID}/approve',{},__savedResult)`);
|
|
|
|
|
|
assert.equal(h.run('currentOrder'), null);
|
|
|
|
|
|
assert.equal(h.run('orderChangeFormEntry'), null);
|
|
|
|
|
|
const html = h.nodes.get('#order-content').innerHTML;
|
|
|
|
|
|
assert.match(html, /已同意修改/);
|
|
|
|
|
|
assert.match(html, /重新读取原订单/);
|
|
|
|
|
|
assert.ok(!html.includes('type="submit"'));
|
|
|
|
|
|
assert.equal(h.calls.length, 0);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('全局待变更数量跨日期查询,读取失败不显示0,助理列表只可查看', async () => {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.run(
|
|
|
|
|
|
"orderBookFilters={mode:'today',q:'当前客户'};api=async function(url){__calls.push({url});return {requests:[__request],counts:{pending:1,approved:2,rejected:3},canApprove:true};};",
|
|
|
|
|
|
);
|
|
|
|
|
|
await h.run('loadOrderChangeCount()');
|
|
|
|
|
|
assert.equal(h.calls[0].url, '/api/order-changes?status=pending');
|
|
|
|
|
|
assert.equal(h.nodes.get('#order-changes-entry').textContent, '待变更复核(1)');
|
|
|
|
|
|
h.run("api=async function(){throw new Error('断线');};");
|
|
|
|
|
|
await h.run('loadOrderChangeCount()');
|
|
|
|
|
|
assert.equal(h.nodes.get('#order-changes-entry').textContent, '待变更复核(读取失败)');
|
|
|
|
|
|
h.context.__list = {
|
|
|
|
|
|
requests: [request({ order_date: '2026-09-01' })],
|
|
|
|
|
|
counts: { pending: 1, approved: 0, rejected: 0 },
|
|
|
|
|
|
canApprove: true,
|
|
|
|
|
|
};
|
|
|
|
|
|
assert.match(h.run('orderChangeListHTML(__list)'), /2026-09-01/);
|
|
|
|
|
|
assert.match(h.run('orderChangeListHTML(__list)'), /查看并复核/);
|
|
|
|
|
|
h.run("state.user.role='assistant'");
|
|
|
|
|
|
assert.ok(!h.run('orderChangeListHTML(__list)').includes('查看并复核'));
|
|
|
|
|
|
});
|
|
|
|
|
|
test('不完整或版本不一致的资料不能审批;延迟读取不能覆盖后打开的订单', async () => {
|
|
|
|
|
|
const h = harness();
|
|
|
|
|
|
h.prepare(request(), { revision: 8 });
|
|
|
|
|
|
assert.equal(h.run('currentOrderChange().data'), null);
|
|
|
|
|
|
assert.throws(() => h.run("showOrderChangeForm('approve')"), /重新读取/);
|
|
|
|
|
|
h.context.__request = request({ after: null });
|
|
|
|
|
|
assert.throws(() => h.run('orderChangeComparisonHTML(__request)'), /未完整返回/);
|
|
|
|
|
|
const resolvers = new Map();
|
|
|
|
|
|
h.context.__api = url => new Promise(resolve => resolvers.set(url, resolve));
|
|
|
|
|
|
h.run('api=__api');
|
|
|
|
|
|
const first = h.run(`openOrder('${ID}')`),
|
|
|
|
|
|
next = h.run(`openOrder('${RELATED}')`);
|
|
|
|
|
|
resolvers.get('/api/orders/' + RELATED)(order({ id: RELATED }));
|
|
|
|
|
|
resolvers.get('/api/orders/' + RELATED + '/cancellation')({
|
|
|
|
|
|
eligible: true,
|
|
|
|
|
|
canApprove: true,
|
|
|
|
|
|
revision: 7,
|
|
|
|
|
|
pending: null,
|
|
|
|
|
|
requests: [],
|
|
|
|
|
|
});
|
|
|
|
|
|
resolvers.get('/api/orders/' + RELATED + '/change')(detail());
|
|
|
|
|
|
await next;
|
|
|
|
|
|
assert.equal(h.run('currentOrder.id'), RELATED);
|
|
|
|
|
|
resolvers.get('/api/orders/' + ID)(order());
|
|
|
|
|
|
resolvers.get('/api/orders/' + ID + '/cancellation')({
|
|
|
|
|
|
eligible: true,
|
|
|
|
|
|
canApprove: true,
|
|
|
|
|
|
revision: 7,
|
|
|
|
|
|
pending: null,
|
|
|
|
|
|
requests: [],
|
|
|
|
|
|
});
|
|
|
|
|
|
resolvers.get('/api/orders/' + ID + '/change')(detail(request()));
|
|
|
|
|
|
await first;
|
|
|
|
|
|
assert.equal(h.run('currentOrder.id'), RELATED);
|
2026-10-23 09:49:36 +08:00
|
|
|
|
});
|
2026-12-04 08:58:53 -08:00
|
|
|
|
test('对照保留缺失成本,转义客户、商品和备注,复核不执行任何写入', () => {
|
|
|
|
|
|
const h = harness(),
|
|
|
|
|
|
r = request();
|
|
|
|
|
|
r.before.customer = '<img src=x>';
|
|
|
|
|
|
r.after.note = '<script>改动</script>';
|
|
|
|
|
|
r.before.lines[0].cost = null;
|
|
|
|
|
|
r.summary.before.goodsCost = null;
|
|
|
|
|
|
r.summary.before.profit = null;
|
|
|
|
|
|
h.context.__request = r;
|
|
|
|
|
|
const html = h.run('orderChangeComparisonHTML(__request)');
|
|
|
|
|
|
assert.match(html, /待补齐/);
|
|
|
|
|
|
assert.match(html, /<img/);
|
|
|
|
|
|
assert.ok(!html.includes('<script>'));
|
|
|
|
|
|
assert.equal(h.calls.length, 0);
|
2026-10-23 09:49:36 +08:00
|
|
|
|
});
|
2026-12-04 08:58:53 -08:00
|
|
|
|
test('助理费用、旧费用、退款、退货和成本表单均提交申请原payload,麦麦原动作不转申请', async () => {
|
|
|
|
|
|
for (const kind of ['expense', 'fees', 'refund', 'return', 'cost']) {
|
|
|
|
|
|
const h = harness('assistant');
|
|
|
|
|
|
const { fields } = h.actionForm(kind);
|
|
|
|
|
|
h.context.__input = {
|
|
|
|
|
|
date: D,
|
|
|
|
|
|
amount: '30.00',
|
|
|
|
|
|
payer: 'owner',
|
|
|
|
|
|
account: '麦麦支付宝',
|
|
|
|
|
|
verified: true,
|
|
|
|
|
|
note: '补记快递',
|
|
|
|
|
|
returnPockets: ['金料'],
|
|
|
|
|
|
fee_items: [{ key: 'f', note: '快递', amount: '3.00', payer: 'assistant' }],
|
|
|
|
|
|
costs: [{ parts: { material: '1800.00' } }],
|
|
|
|
|
|
...(kind === 'return' ? { reason: '实物已退回' } : {}),
|
|
|
|
|
|
};
|
|
|
|
|
|
h.run('finishOrderChangeSave=async function(url,input,result){__finished={url,input,result};};');
|
|
|
|
|
|
await h.run('submitOrderActionChange(__form,__input)');
|
|
|
|
|
|
assert.equal(h.calls[0].url, '/api/orders/' + ID + '/change');
|
|
|
|
|
|
assert.equal(h.calls[0].data.action, kind);
|
|
|
|
|
|
assert.equal(h.calls[0].data.revision, 7);
|
|
|
|
|
|
assert.equal(h.calls[0].data.verified, true);
|
|
|
|
|
|
assert.equal(h.calls[0].data.amount, '30.00');
|
|
|
|
|
|
assert.equal(h.calls[0].data.reason, fields.change_reason.value);
|
|
|
|
|
|
assert.ok(!h.calls[0].url.endsWith('/' + kind));
|
|
|
|
|
|
}
|
|
|
|
|
|
const owner = harness();
|
|
|
|
|
|
owner.run("showAction('expense')");
|
|
|
|
|
|
assert.ok(!owner.nodes.get('#detail-form').innerHTML.includes('data-order-change="true"'));
|
|
|
|
|
|
assert.match(owner.nodes.get('#detail-form').innerHTML, /确认保存/);
|
|
|
|
|
|
assert.equal(owner.run("orderActionRequiresApproval('expense')"), false);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('动作申请原因及凭据确认必填,409禁旧提交并保留只读重取和原操作恢复', async () => {
|
|
|
|
|
|
const h = harness('assistant'),
|
|
|
|
|
|
{ fields, submit, reload, retry } = h.actionForm('refund', { change_reason: '' });
|
|
|
|
|
|
h.context.__input = { date: D, amount: '30.00', account: '助理微信', verified: true };
|
|
|
|
|
|
await assert.rejects(h.run('submitOrderActionChange(__form,__input)'), /申请原因/);
|
|
|
|
|
|
fields.change_reason.value = '退货后登记客户退款';
|
|
|
|
|
|
h.context.__input.verified = false;
|
|
|
|
|
|
await assert.rejects(h.run('submitOrderActionChange(__form,__input)'), /勾选/);
|
|
|
|
|
|
assert.equal(h.calls.length, 0);
|
|
|
|
|
|
h.context.__input.verified = true;
|
|
|
|
|
|
h.run("api=async function(){const err=new Error('版本已变动');err.status=409;err.confirmed=true;throw err;};");
|
|
|
|
|
|
await h.run('submitOrderActionChange(__form,__input)');
|
|
|
|
|
|
assert.equal(h.run('orderActionChangeEntry'), null);
|
|
|
|
|
|
assert.equal(fields.verified.checked, false);
|
|
|
|
|
|
assert.equal(submit.disabled, true);
|
|
|
|
|
|
assert.equal(reload.disabled, false);
|
|
|
|
|
|
assert.equal(retry.disabled, false);
|
|
|
|
|
|
assert.equal(h.saved.get('mm-pending-change-user'), undefined);
|
|
|
|
|
|
assert.match(h.nodes.get('#order-action-change-error').innerHTML, /重新读取订单后申请/);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('费用与退款复核明确显示动作金额日期付款人账户,退货展示去向及库存原值与净变', () => {
|
|
|
|
|
|
const h = harness(),
|
|
|
|
|
|
r = request({
|
|
|
|
|
|
action: 'refund',
|
|
|
|
|
|
action_label: '退款',
|
|
|
|
|
|
action_input: { date: '2026-10-21', amount: '300.00', account: '麦麦支付宝', reference: '凭据已核实' },
|
|
|
|
|
|
});
|
|
|
|
|
|
h.context.__request = r;
|
|
|
|
|
|
let html = h.run('orderChangeActionSummaryHTML(__request)');
|
|
|
|
|
|
for (const text of ['退款', '300.00', '2026-10-21', '麦麦支付宝', '凭据已核实']) assert.ok(html.includes(text), text);
|
|
|
|
|
|
r.action = 'expense';
|
|
|
|
|
|
r.action_label = '费用补记';
|
|
|
|
|
|
r.action_input = { date: D, amount: '30.00', payer: 'assistant', note: '快递实付' };
|
|
|
|
|
|
h.context.__request = r;
|
|
|
|
|
|
html = h.run('orderChangeActionSummaryHTML(__request)');
|
|
|
|
|
|
for (const text of ['费用补记', '30.00', '娜娜', '快递实付']) assert.ok(html.includes(text), text);
|
|
|
|
|
|
r.action = 'return';
|
|
|
|
|
|
r.action_label = '退货';
|
|
|
|
|
|
r.action_input = { date: D, returnPockets: ['金料'] };
|
|
|
|
|
|
r.summary.inventory = {
|
|
|
|
|
|
before: [{ date: D, pocket: '现货', kind: 'sale', mg: -2000 }],
|
|
|
|
|
|
after: [
|
|
|
|
|
|
{ date: D, pocket: '现货', kind: 'sale', mg: -2000 },
|
|
|
|
|
|
{ date: D, pocket: '金料', kind: 'return', mg: 2000 },
|
|
|
|
|
|
],
|
|
|
|
|
|
changes: [{ date: D, pocket: '金料', mg: 2000 }],
|
|
|
|
|
|
};
|
|
|
|
|
|
h.context.__request = r;
|
|
|
|
|
|
html = h.run('orderChangeActionSummaryHTML(__request)+orderChangeComparisonHTML(__request)');
|
|
|
|
|
|
for (const text of ['退货实物去向', '金料', '原库存记录', '同意后的库存记录', '本次库存净变化', '+2.000g', '-2.000g'])
|
|
|
|
|
|
assert.ok(html.includes(text), text);
|
2026-10-23 09:49:36 +08:00
|
|
|
|
});
|
2026-12-04 08:58:53 -08:00
|
|
|
|
test('旧单费用未批不能助理直接完成账务,动作资格不可用时不建立申请表单', () => {
|
|
|
|
|
|
const h = harness('assistant');
|
|
|
|
|
|
h.context.__order = order({
|
|
|
|
|
|
status: 'confirmed',
|
|
|
|
|
|
pendingFees: [{ key: 'shipping', note: '快递', amount: 600, payer: 'assistant' }],
|
|
|
|
|
|
});
|
|
|
|
|
|
h.run('currentOrder=__order');
|
|
|
|
|
|
h.prepare();
|
|
|
|
|
|
assert.throws(() => h.run("showAction('complete')"), /先申请补记旧单费用/);
|
|
|
|
|
|
h.prepare(null, { actions: { refund: { eligible: false, reason: '没有可退客户款' } } });
|
|
|
|
|
|
assert.throws(() => h.run("showAction('refund')"), /没有可退客户款/);
|
|
|
|
|
|
assert.equal(h.calls.length, 0);
|
2026-10-23 09:49:36 +08:00
|
|
|
|
});
|
2026-12-04 08:58:53 -08:00
|
|
|
|
test('助理仅凭服务器当天资格对费用、旧费用、退款和退货原路保存,原因版本与核实完整保留', async () => {
|
|
|
|
|
|
for (const kind of ['expense', 'fees', 'refund', 'return']) {
|
|
|
|
|
|
const h = harness('assistant');
|
|
|
|
|
|
h.run("currentOrder={...currentOrder,date:'2026-10-23'}");
|
|
|
|
|
|
h.prepare(null, { directActionDate: '2026-10-23', actions: { [kind]: { eligible: true, directToday: true } } });
|
|
|
|
|
|
const { fields } = h.actionForm(kind, { reason: kind === 'return' ? '客户整单退回' : '' });
|
|
|
|
|
|
assert.match(h.nodes.get('#detail-form').innerHTML, /核实并保存/);
|
|
|
|
|
|
assert.match(h.nodes.get('#detail-form').innerHTML, /无需店主审批/);
|
|
|
|
|
|
h.context.__input = {
|
|
|
|
|
|
date: '2026-10-23',
|
|
|
|
|
|
amount: '30.00',
|
|
|
|
|
|
payer: 'owner',
|
|
|
|
|
|
account: '助理微信',
|
|
|
|
|
|
verified: true,
|
|
|
|
|
|
note: '补寄快递',
|
|
|
|
|
|
returnPockets: ['金料'],
|
|
|
|
|
|
fee_items: [{ key: 'shipping', amount: '6.00', payer: 'assistant' }],
|
|
|
|
|
|
reason: fields.reason.value,
|
|
|
|
|
|
};
|
|
|
|
|
|
h.run('refreshOrderDetailAfterSave=async function(id){__finished={id};}');
|
|
|
|
|
|
await h.run('submitOrderActionChange(__form,__input)');
|
|
|
|
|
|
assert.equal(h.calls.length, 1);
|
|
|
|
|
|
assert.equal(h.calls[0].url, '/api/orders/' + ID + '/' + kind);
|
|
|
|
|
|
assert.equal(h.calls[0].data.revision, 7);
|
|
|
|
|
|
assert.equal(h.calls[0].data.verified, true);
|
|
|
|
|
|
assert.equal(h.calls[0].data.reason, fields.change_reason.value);
|
|
|
|
|
|
assert.equal(h.calls[0].data.action, undefined);
|
|
|
|
|
|
assert.equal(h.json('__finished.id'), ID);
|
2026-10-23 09:49:36 +08:00
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
const h = harness('assistant');
|
|
|
|
|
|
h.run("currentOrder={...currentOrder,date:'2026-10-23'}");
|
|
|
|
|
|
h.prepare(null, { directActionDate: '2026-10-23', actions: { cost: { eligible: true, directToday: true } } });
|
|
|
|
|
|
assert.equal(h.run("orderActionRequiresApproval('cost')"), true);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('当天动作资格缺失、原单旧日或改业务日期均走申请,切换日期清核实而不清输入', async () => {
|
|
|
|
|
|
const h = harness('assistant');
|
|
|
|
|
|
h.run("currentOrder={...currentOrder,date:'2026-10-23'}");
|
|
|
|
|
|
for (const extra of [
|
|
|
|
|
|
{},
|
|
|
|
|
|
{ directActionDate: '2026-10-23' },
|
|
|
|
|
|
{ directActionDate: '2026-10-23', actions: { expense: { eligible: true, directToday: false } } },
|
|
|
|
|
|
{ directActionDate: '2026-10-22', actions: { expense: { eligible: true, directToday: true } } },
|
|
|
|
|
|
]) {
|
|
|
|
|
|
h.prepare(null, extra);
|
|
|
|
|
|
assert.equal(h.run("orderActionRequiresApproval('expense')"), true);
|
2026-10-23 11:58:19 +08:00
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
h.prepare(null, { directActionDate: '2026-10-23', actions: { expense: { eligible: true, directToday: true } } });
|
|
|
|
|
|
const { form, fields, submit } = h.actionForm('expense', { amount: '8.50', note: '保留这笔费用' });
|
|
|
|
|
|
fields.date.value = D;
|
|
|
|
|
|
h.run('syncOrderActionChangeMode()');
|
|
|
|
|
|
assert.equal(form.dataset.orderDirect, 'false');
|
|
|
|
|
|
assert.equal(fields.verified.checked, false);
|
|
|
|
|
|
assert.equal(submit.textContent, '提交变更申请');
|
|
|
|
|
|
assert.equal(fields.amount.value, '8.50');
|
|
|
|
|
|
assert.equal(fields.note.value, '保留这笔费用');
|
|
|
|
|
|
h.context.__input = { date: D, amount: '8.50', payer: 'assistant', note: fields.note.value, verified: true };
|
|
|
|
|
|
await assert.rejects(h.run('submitOrderActionChange(__form,__input)'), /勾选/);
|
|
|
|
|
|
assert.equal(h.calls.length, 0);
|
|
|
|
|
|
fields.verified.checked = true;
|
|
|
|
|
|
h.run('finishOrderChangeSave=async function(url,input,result){__finished={url,input,result};};');
|
|
|
|
|
|
await h.run('submitOrderActionChange(__form,__input)');
|
|
|
|
|
|
assert.equal(h.calls[0].url, '/api/orders/' + ID + '/change');
|
|
|
|
|
|
assert.equal(h.calls[0].data.action, 'expense');
|
|
|
|
|
|
assert.equal(h.calls[0].data.date, D);
|
|
|
|
|
|
const old = harness('assistant');
|
|
|
|
|
|
old.prepare(null, { directActionDate: '2026-10-23', actions: { refund: { eligible: true, directToday: true } } });
|
|
|
|
|
|
assert.equal(old.run("orderActionRequiresApproval('refund')"), true);
|
|
|
|
|
|
});
|
|
|
|
|
|
test('当天直做403保留填写并清核实转申请,待恢复仍使用原endpoint和操作号', async () => {
|
|
|
|
|
|
const h = harness('assistant');
|
|
|
|
|
|
h.run("currentOrder={...currentOrder,date:'2026-10-23'}");
|
|
|
|
|
|
h.prepare(null, { directActionDate: '2026-10-23', actions: { expense: { eligible: true, directToday: true } } });
|
|
|
|
|
|
const { form, fields, submit } = h.actionForm('expense', { amount: '9.80', note: '凌晨保留费用' });
|
|
|
|
|
|
h.context.__input = {
|
|
|
|
|
|
date: '2026-10-23',
|
|
|
|
|
|
amount: '9.80',
|
|
|
|
|
|
payer: 'assistant',
|
|
|
|
|
|
note: fields.note.value,
|
|
|
|
|
|
verified: true,
|
|
|
|
|
|
};
|
|
|
|
|
|
h.run(
|
|
|
|
|
|
"api=async function(url,data,key){__calls.push({url,data,key});const err=new Error('已跨日,请提交申请');err.status=403;err.confirmed=true;throw err;}",
|
|
|
|
|
|
);
|
|
|
|
|
|
await h.run('submitOrderActionChange(__form,__input)');
|
|
|
|
|
|
assert.equal(h.calls.length, 1);
|
|
|
|
|
|
assert.equal(form.dataset.orderDirect, 'false');
|
|
|
|
|
|
assert.equal(submit.textContent, '提交变更申请');
|
|
|
|
|
|
assert.equal(fields.verified.checked, false);
|
|
|
|
|
|
assert.equal(fields.amount.value, '9.80');
|
|
|
|
|
|
assert.equal(fields.note.value, '凌晨保留费用');
|
|
|
|
|
|
assert.match(h.nodes.get('#order-action-change-error').innerHTML, /输入已保留/);
|
|
|
|
|
|
assert.equal(h.saved.get('mm-pending-change-user'), undefined);
|
|
|
|
|
|
await assert.rejects(h.run('submitOrderActionChange(__form,__input)'), /勾选/);
|
|
|
|
|
|
assert.equal(h.calls.length, 1);
|
|
|
|
|
|
fields.verified.checked = true;
|
|
|
|
|
|
h.run(
|
|
|
|
|
|
'api=async function(url,data,key){__calls.push({url,data,key});return {id:currentOrder.id};};finishOrderChangeSave=async function(){}',
|
|
|
|
|
|
);
|
|
|
|
|
|
await h.run('submitOrderActionChange(__form,__input)');
|
|
|
|
|
|
assert.equal(h.calls[1].url, '/api/orders/' + ID + '/change');
|
|
|
|
|
|
const lost = harness('assistant');
|
|
|
|
|
|
lost.run("currentOrder={...currentOrder,date:'2026-10-23'}");
|
|
|
|
|
|
lost.prepare(null, { directActionDate: '2026-10-23', actions: { refund: { eligible: true, directToday: true } } });
|
|
|
|
|
|
lost.actionForm('refund');
|
|
|
|
|
|
lost.context.__input = { date: '2026-10-23', amount: '10.00', account: '助理微信', verified: true };
|
|
|
|
|
|
lost.run("api=async function(url,data,key){__calls.push({url,data,key});throw new Error('响应丢失');}");
|
|
|
|
|
|
await lost.run('submitOrderActionChange(__form,__input)');
|
|
|
|
|
|
const pending = JSON.parse(lost.saved.get('mm-pending-change-user'));
|
|
|
|
|
|
assert.equal(pending.url, '/api/orders/' + ID + '/refund');
|
|
|
|
|
|
lost.run(
|
|
|
|
|
|
'api=async function(url,data,key){__calls.push({url,data,key});return {id:currentOrder.id};};refreshOrderDetailAfterSave=async function(){}',
|
|
|
|
|
|
);
|
|
|
|
|
|
await lost.click('retry');
|
|
|
|
|
|
assert.equal(lost.calls[1].key, pending.key);
|
|
|
|
|
|
assert.deepEqual(JSON.parse(JSON.stringify(lost.calls[1].data)), pending.data);
|
|
|
|
|
|
assert.equal(lost.saved.get('mm-pending-change-user'), undefined);
|
2026-10-23 11:58:19 +08:00
|
|
|
|
});
|