补齐固定旧版的浏览器逐笔写入对照并记录账务差异
This commit is contained in:
1 parent
e77588b337
commit
7d2007955f
39 files changed
+3653
-41
No files matched your search
@@ -0,0 +1,268 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { action, postFrom, section } from './operations-helpers.mjs';
|
||||
|
||||
const api = '/api/recoveries';
|
||||
const field = (form, name) => form.locator('[name="' + name + '"]');
|
||||
const submit = form => form.locator('button[type=submit]');
|
||||
const detail = page => page.locator('#recovery-dialog[open]');
|
||||
|
||||
async function openRecord(ctx, page, id, date) {
|
||||
await section(page, ctx, 'recoveries');
|
||||
const f = page.locator('#recovery-filter-form');
|
||||
await field(f, 'from').fill(date);
|
||||
await submit(f).click();
|
||||
await page
|
||||
.locator('[data-action=recovery-open][data-id="' + id + '"]')
|
||||
.first()
|
||||
.click();
|
||||
await detail(page).locator('[data-action=recovery-print]').waitFor();
|
||||
}
|
||||
|
||||
async function quoteAndSave(page, path) {
|
||||
const f = page.locator('#recovery-form');
|
||||
await field(f, 'verified').check();
|
||||
await page
|
||||
.locator('#recovery-quote-status')
|
||||
.getByText(/结算已核对/)
|
||||
.waitFor();
|
||||
return postFrom(page, path, () => submit(f).click());
|
||||
}
|
||||
|
||||
async function printRecovery(page, id, dialog = detail(page)) {
|
||||
const [popup] = await Promise.all([page.waitForEvent('popup'), action(dialog, 'recovery-print').click()]);
|
||||
assert.equal(new URL(popup.url()).pathname, '/print/recoveries/' + id);
|
||||
try {
|
||||
await popup.evaluate(() => {
|
||||
window.print = () => {};
|
||||
});
|
||||
await postFrom(popup, '/api/print-status/recovery/' + id, () => popup.locator('#print').click());
|
||||
await dialog
|
||||
.locator('[data-print-kind=recovery][data-print-id="' + id + '"]')
|
||||
.getByText('✓ 已打印')
|
||||
.waitFor();
|
||||
} finally {
|
||||
await popup.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function createCustomerDeposit(ctx, page) {
|
||||
await action(page, 'customer-material-new').click();
|
||||
const f = page.locator('#customer-material-form');
|
||||
return ctx.step('客料登记寄存克重与备忘', async () => {
|
||||
await field(f, 'grams').fill('9.125');
|
||||
await field(f, 'memo').fill('寄存对照袋');
|
||||
await field(f, 'verified').check();
|
||||
const r = await postFrom(page, '/api/customer-materials', () => submit(f).click());
|
||||
await page.locator('#customer-material-list').getByText('寄存对照袋', { exact: true }).waitFor();
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
async function cancelRecord(page, id, reason) {
|
||||
await action(detail(page), 'recovery-edit-cancel').click();
|
||||
const f = page.locator('#recovery-cancel-form');
|
||||
await field(f, 'reason').fill(reason);
|
||||
await field(f, 'verified').check();
|
||||
const legacy = field(f, 'legacyCountVerified');
|
||||
if (await legacy.count()) await legacy.check();
|
||||
return postFrom(page, api + '/' + id + '/cancel', () => submit(f).click());
|
||||
}
|
||||
|
||||
async function review(page, id, decision) {
|
||||
await action(page, 'recovery-changes-open').click();
|
||||
await action(page.locator('#recovery-change-list'), 'recovery-change-open').click();
|
||||
await page.locator('[data-action=recovery-change-decision][data-kind="' + decision + '"]').click();
|
||||
const f = page.locator('#recovery-change-review-form');
|
||||
await field(f, 'note').fill(decision === 'reject' ? '退回重新核对' : '已对照原凭证');
|
||||
if (decision === 'approve') await field(f, 'verified').check();
|
||||
return postFrom(page, '/api/recovery-changes/' + id + '/' + decision, () => submit(f).click());
|
||||
}
|
||||
|
||||
function historicalInput(day) {
|
||||
const product = (oldGrams, quantity, extra) => ({
|
||||
date: day,
|
||||
mode: 'exchange',
|
||||
customer: '历史逐件对照',
|
||||
customer_type: 'new',
|
||||
salesperson: '麦麦',
|
||||
old_lines: [{ name: '旧料', incoming_weight: oldGrams, melted_weight: oldGrams, purity: '100' }],
|
||||
buy_rate: '850',
|
||||
payer: 'owner',
|
||||
payment_account: '麦麦微信',
|
||||
verified: true,
|
||||
exchange: {
|
||||
name: '足金合成新货',
|
||||
quantity,
|
||||
pocket: '现货',
|
||||
gold_price: '1000',
|
||||
labor_rate: '20',
|
||||
labor_mode: 'gram',
|
||||
depreciation_rate: '10',
|
||||
cost_material: { mode: 'gram', rate: '900' },
|
||||
cost_labor: { mode: 'gram', rate: '5' },
|
||||
cost_payer: 'owner',
|
||||
discount: '0',
|
||||
rounding_mode: 'cent',
|
||||
...extra,
|
||||
},
|
||||
});
|
||||
const a = product('10', '15', {}),
|
||||
b = product('20', '12', {
|
||||
pocket: '',
|
||||
gold_price: '1100',
|
||||
labor_rate: '30',
|
||||
depreciation_rate: '5',
|
||||
cost_labor: { mode: 'total', amount: '60' },
|
||||
cost_labor_payer: 'assistant2',
|
||||
});
|
||||
return {
|
||||
...a,
|
||||
member: 'owner',
|
||||
exchange: { items: [a, b], charges: [], fee_items: [], discount: '0', rounding_mode: 'cent' },
|
||||
};
|
||||
}
|
||||
|
||||
export async function recoveryWrites(ctx, owner, staff) {
|
||||
const { step, day, session } = ctx;
|
||||
const yesterday = new Date(Date.parse(day + 'T12:00Z') - 86400000).toISOString().slice(0, 10);
|
||||
await session.post('owner', '/api/stock', {
|
||||
kind: 'increase',
|
||||
date: day,
|
||||
pocket: '现货',
|
||||
grams: '100',
|
||||
note: '置换对照库存',
|
||||
});
|
||||
const historical = await session.post('owner', api, historicalInput(day));
|
||||
const previous = await session.post('assistant', api, {
|
||||
date: yesterday,
|
||||
mode: 'direct',
|
||||
customer: '跨日回收对照',
|
||||
member: 'assistant',
|
||||
salesperson: '娜娜',
|
||||
old_lines: [{ name: '旧料', incoming_weight: '2', melted_weight: '2', purity: '100' }],
|
||||
buy_rate: '850',
|
||||
payer: 'assistant',
|
||||
payment_account: '助理微信',
|
||||
verified: true,
|
||||
});
|
||||
assert.deepEqual(session.problems, []);
|
||||
await section(owner, ctx, 'recoveries');
|
||||
const deposit = await createCustomerDeposit(ctx, owner);
|
||||
await action(owner, 'customer-material-back').click();
|
||||
const f = owner.locator('#recovery-form');
|
||||
const direct = await step('直接回收登记称重纯度与结算', async () => {
|
||||
await field(f, 'customer').fill('直接回收对照');
|
||||
await field(f, 'incoming_weight').fill('3.100');
|
||||
await field(f, 'purity').fill('99');
|
||||
await field(f, 'buy_rate').fill('733.22');
|
||||
await field(f, 'buy_total').fill('2253.44');
|
||||
return quoteAndSave(owner, api);
|
||||
});
|
||||
await step('直接回收单客户打印回写', () => printRecovery(owner, direct.id));
|
||||
await action(detail(owner), 'recovery-edit-open').click();
|
||||
await step('店主修改回收价格及结算', async () => {
|
||||
await field(f, 'change_reason').fill('对照原始价格');
|
||||
await field(f, 'buy_rate').fill('734.22');
|
||||
await action(f, 'recovery-reset-buy').click();
|
||||
await quoteAndSave(owner, api + '/' + direct.id + '/update');
|
||||
});
|
||||
await step('店主取消回收记录并冲回购料', () => cancelRecord(owner, direct.id, '核对后撤回'));
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await owner.locator('[data-action=recovery-mode][data-mode=exchange]').click();
|
||||
const exchange = await step('置换使用部分客料并记录工费收款', async () => {
|
||||
await field(f, 'customer').fill('寄存置换对照');
|
||||
await f.locator('[name=customer_type][value=new]').check();
|
||||
await field(f, 'old_source').selectOption('deposit');
|
||||
await field(f, 'deposit_id').selectOption(deposit.id);
|
||||
await field(f, 'deposit_weight').fill('2');
|
||||
await field(f, 'new_quantity').fill('2');
|
||||
await field(f, 'labor_rate').fill('35');
|
||||
await field(f, 'cost_labor_value').fill('10');
|
||||
return quoteAndSave(owner, api);
|
||||
});
|
||||
const linked = (await session.get('owner', api + '/' + exchange.id + '/edit')).record.order_id;
|
||||
await section(owner, ctx, 'orders');
|
||||
await owner
|
||||
.locator('[data-action=open-order][data-id="' + linked + '"]')
|
||||
.first()
|
||||
.click();
|
||||
await step('置换关联销售单客户打印回写', () =>
|
||||
printRecovery(owner, exchange.id, owner.locator('#order-dialog[open]')),
|
||||
);
|
||||
await openRecord(ctx, owner, exchange.id, day);
|
||||
await step('取消客料置换并恢复寄存余额', () => cancelRecord(owner, exchange.id, '退还原客户寄存'));
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await owner.locator('[data-action=recovery-mode][data-mode=exchange]').click();
|
||||
await step('多件置换共用来料并将余料登记为客料', async () => {
|
||||
await field(f, 'customer').fill('余料寄存对照');
|
||||
await f.locator('[name=customer_type][value=returning]').check();
|
||||
await field(f, 'incoming_weight').fill('5');
|
||||
await field(f, 'new_quantity').fill('2');
|
||||
await field(f, 'labor_rate').fill('20');
|
||||
await field(f, 'cost_labor_value').fill('2');
|
||||
await action(f, 'recovery-add-product').click();
|
||||
await field(f, 'extra_new_quantity').fill('1');
|
||||
await field(f, 'extra_labor_rate').fill('25');
|
||||
await field(f, 'extra_cost_labor_value').fill('3');
|
||||
await field(f, 'surplus_mode').selectOption('deposit');
|
||||
await field(f, 'surplus_memo').fill('新袋余料');
|
||||
await field(f, 'payment_method').selectOption('信用卡');
|
||||
return quoteAndSave(owner, api);
|
||||
});
|
||||
await session.post('owner', '/api/material-purchases', {
|
||||
date: day,
|
||||
grams: '8',
|
||||
total: '6800',
|
||||
payer: 'owner',
|
||||
note: '置换公共料池对照',
|
||||
});
|
||||
assert.deepEqual(session.problems, []);
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await owner.locator('[data-action=recovery-mode][data-mode=exchange]').click();
|
||||
await step('置换补金按所选料池核算并确认收款', async () => {
|
||||
await field(f, 'customer').fill('补金料池对照');
|
||||
await f.locator('[name=customer_type][value=new]').check();
|
||||
await field(f, 'incoming_weight').fill('2');
|
||||
await field(f, 'new_quantity').fill('3');
|
||||
await field(f, 'gold_price').fill('920');
|
||||
await field(f, 'cost_labor_value').fill('15');
|
||||
await field(f, 'labor_rate').fill('20');
|
||||
await field(f, 'material_source').selectOption('pool');
|
||||
await field(f, 'material_pool_id').selectOption(day);
|
||||
return quoteAndSave(owner, api);
|
||||
});
|
||||
await openRecord(ctx, owner, historical.id, day);
|
||||
await action(detail(owner), 'recovery-edit-open').click();
|
||||
await step('历史逐件置换仅修改第二件工费', async () => {
|
||||
await f.locator('[data-recovery-item]').nth(1).waitFor();
|
||||
assert.equal(await f.locator('[data-recovery-item]').count(), 2);
|
||||
await f.locator('[data-recovery-item]').nth(1).locator('[name=extra_labor_rate]').fill('31.5');
|
||||
await field(f, 'change_reason').fill('更正第二件工费');
|
||||
await quoteAndSave(owner, api + '/' + historical.id + '/update');
|
||||
});
|
||||
await openRecord(ctx, staff, previous.id, yesterday);
|
||||
await action(detail(staff), 'recovery-edit-open').click();
|
||||
const sf = staff.locator('#recovery-form');
|
||||
const proposal = await step('店员跨日提交回收更正申请', async () => {
|
||||
// 两个页面都先显示详情模态框,等具备修改理由的编辑表单到位再输入。
|
||||
await field(sf, 'change_reason').fill('请核对历史手续费');
|
||||
await field(sf, 'buy_rate').fill('858');
|
||||
const proposal = await quoteAndSave(staff, api + '/' + previous.id + '/update');
|
||||
assert.equal(proposal.request.after.buy_rate, '858.00');
|
||||
return proposal;
|
||||
});
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await step('店主批准历史回收更正', () => review(owner, proposal.requestId || proposal.request?.id, 'approve'));
|
||||
await openRecord(ctx, staff, previous.id, yesterday);
|
||||
const cancellation = await step('店员跨日提交回收取消申请', () => cancelRecord(staff, previous.id, '核对历史取消'));
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await step('店主驳回历史回收取消申请', () =>
|
||||
review(owner, cancellation.requestId || cancellation.request?.id, 'reject'),
|
||||
);
|
||||
await openRecord(ctx, staff, previous.id, yesterday);
|
||||
const again = await step('店员重新提交已驳回的回收取消申请', () =>
|
||||
cancelRecord(staff, previous.id, '重查后仍需作废'),
|
||||
);
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await step('店主批准回收取消及关联冲回', () => review(owner, again.requestId || again.request?.id, 'approve'));
|
||||
}
|
||||
Reference in new issue
Block a user