import assert from 'node:assert/strict'; export async function exerciseOrderReviews({ day, yesterday, session, open, field, action, legacyForm, submit, write, route, issue, order, post, }) { const past = []; await session.day(yesterday); for (const name of ['普通改单批准', '普通改单驳回', '申请取消批准', '申请取消驳回', '跨日原单售后']) past.push(await issue(name, yesterday)); const oldSale = await issue('历史分步售退', yesterday); const pendingFees = [{ key: 'shipping', note: '寄件费', amount: '4.50', payer: 'assistant', status: 'estimated' }]; const oldUnfinished = ( await post('assistant', '/api/orders', order('历史费用申请', yesterday, { fee_items: pendingFees })) ).id; await post('assistant', route(oldUnfinished) + '/confirm', { date: yesterday }); await session.day(day); async function edit(actor, id, period, label, reason, endpoint) { const page = await open(actor, id, period); await action(page, 'edit-order').click(); const form = page.locator('#order-form[data-order-edit=true]'); await field(form, 'customer').fill(label); await field(form, 'edit_reason').fill(reason); await field(form, 'edit_verified').check(); await submit(label, page, form, route(id) + '/' + endpoint); } async function decide(id, period, type, decision, label) { const page = await open('owner', id, period); const name = type === 'ownership' ? 'order-ownership-' + decision : decision + '-order-' + type; await action(page, name).click(); const form = page.locator('#order-' + type + '-form'); await field(form, 'note').fill(decision === 'approve' ? '凭据与原单已核对' : '请补足原凭据'); if (decision === 'approve') await field(form, 'verified').check(); const endpoints = { ownership: 'order-ownership-changes', change: 'order-changes', cancellation: 'order-cancellations', }; await submit(label, page, form, new RegExp('^/api/' + endpoints[type] + '/[^/]+/' + decision + '$')); } const direct = await issue('普通订单直接改'); await edit('assistant', direct, 'today', '助理同日直接修改普通订单', '复核客户称呼', 'edit'); for (const [i, decision] of ['approve', 'reject'].entries()) { const result = decision === 'approve' ? '批准' : '驳回'; await edit('assistant', past[i], 'yesterday', '助理申请修改普通订单待' + result, '补正昨日客户称呼', 'change'); await decide(past[i], 'yesterday', 'change', decision, '店主' + result + '普通改单'); } for (const [i, decision] of ['approve', 'reject'].entries()) { const result = decision === 'approve' ? '批准' : '驳回'; const id = past[i + 2]; const page = await open('assistant', id, 'yesterday'); await action(page, 'request-order-cancellation').click(); const form = page.locator('#order-cancellation-form'); await field(form, 'reason').fill('重复录入的昨日订单'); await submit('助理提交取消申请待' + result, page, form, route(id) + '/cancellation'); await decide(id, 'yesterday', 'cancellation', decision, '店主' + result + '取消订单'); } const cancelId = await issue('同日直接作废'); let page = await open('assistant', cancelId); await action(page, 'request-order-cancellation').click(); let form = page.locator('#order-cancellation-form'); assert.equal(await form.getAttribute('data-kind'), 'direct'); await field(form, 'reason').fill('同一交易重复登记'); await field(form, 'verified').check(); await submit('助理同日直接作废订单', page, form, route(cancelId) + '/canceltoday'); for (const [actor, decision] of [ ['owner', 'direct'], ['assistant', 'approve'], ['assistant', 'reject'], ]) { const label = { direct: '店主直接更正订单归属', approve: '助理申请改归属待批准', reject: '助理申请改归属待驳回' }[ decision ]; const id = await issue(label); page = await open(actor, id); await action(page, 'order-ownership-request').click(); form = page.locator('#order-ownership-form'); await field(form, 'member').selectOption('assistant2'); await field(form, 'reason').fill('核正接单员工'); await field(form, 'verified').check(); await submit(label, page, form, route(id) + '/ownership'); if (decision !== 'direct') await decide( id, 'today', 'ownership', decision, '店主' + (decision === 'approve' ? '批准' : '驳回') + '归属变更', ); } // 原单售后的跨日操作经订单变更复核,批准时才冲回库存与实际收入。 const id = past[4]; page = await open('assistant', id, 'yesterday'); await action(page, 'order-after-sale-open').click(); form = page.locator('#order-after-sale-form'); await field(form, 'reason').fill('跨日退货并核实货款'); await write( '助理跨日原单售后试算', page, route(id) + '/after-sale-preview', () => action(page, 'order-after-sale-preview').click(), () => form.getByText('预览已更新,请核对后勾选确认。').waitFor(), ); await field(form, 'verified').check(); await submit('助理提交跨日原单售后申请', page, form, route(id) + '/change'); await decide(id, 'yesterday', 'change', 'approve', '店主批准跨日原单售后'); // 旧版分步办理的费用、退货和退款各有不同的申请字段及落账时间。 for (const [kind, title, target] of [ ['fees', '补记旧单费用', oldUnfinished], ['expense', '额外费用', oldSale], ['return', '整单退货', oldSale], ['refund', '实际退款', oldSale], ]) { page = await open('assistant', target, 'yesterday'); form = await legacyForm(page, kind); if (kind === 'fees') await field(form, 'verifiedAmount').fill('5.60'); if (kind === 'expense') { await field(form, 'amount').fill('3.75'); await field(form, 'note').fill('补登实际支出'); } await field(form, kind === 'return' ? 'reason' : 'change_reason').fill('核实跨日' + title); await field(form, 'verified').check(); await submit('助理申请跨日' + title, page, form, route(target) + '/change'); await decide(target, 'yesterday', 'change', 'approve', '店主批准跨日' + title); } // 历史已确认订单中的货品成本由助理提请复核,尚未发生成交也可补齐。 const confirmed = (await post('assistant', '/api/orders', order('历史成本申请'))).id; await post('assistant', route(confirmed) + '/confirm', { date: day }); page = await open('assistant', confirmed); await action(page, 'show-cost').click(); form = page.locator('#action-form[data-kind=cost]'); await field(form, 'cost-0-labor').fill('61.50'); await field(form, 'change_reason').fill('补录历史进货工费'); await field(form, 'verified').check(); await submit('助理申请补录旧单货品成本', page, form, route(confirmed) + '/change'); await decide(confirmed, 'today', 'change', 'approve', '店主批准补录旧单成本'); }