历史置换手续费预览采用原单费率,移除两处固定费率兜底
This commit is contained in:
1 parent
d2bc0bb85f
commit
ca19987108
6 files changed
+176
-69
No files matched your search
@@ -9,7 +9,6 @@ export default async function historicalCardFee(ctx) {
|
||||
const { revision } = await session.get('owner', '/api/shop-settings');
|
||||
await session.post('owner', '/api/shop-settings', { revision, creditCardRatePermille: rate });
|
||||
}
|
||||
await setRate(4);
|
||||
await session.post('owner', '/api/stock', {
|
||||
kind: 'increase',
|
||||
date: day,
|
||||
@@ -17,39 +16,44 @@ export default async function historicalCardFee(ctx) {
|
||||
grams: '20',
|
||||
note: '费率对照',
|
||||
});
|
||||
const historical = await session.post('owner', '/api/recoveries', {
|
||||
date: day,
|
||||
mode: 'exchange',
|
||||
customer: '历史卡费对照',
|
||||
customer_type: 'new',
|
||||
salesperson: '麦麦',
|
||||
member: 'owner',
|
||||
payer: 'owner',
|
||||
payment_account: '麦麦信用卡',
|
||||
verified: true,
|
||||
buy_rate: '0',
|
||||
old_lines: [{ name: '旧料', incoming_weight: '1', melted_weight: '1', purity: '100' }],
|
||||
exchange: {
|
||||
name: '足金999',
|
||||
quantity: '1',
|
||||
pocket: '现货',
|
||||
gold_price: '0',
|
||||
labor_rate: '200',
|
||||
labor_mode: 'total',
|
||||
depreciation_rate: '0',
|
||||
cost_labor: { mode: 'total', amount: '15' },
|
||||
cost_payer: 'owner',
|
||||
discount: '0',
|
||||
rounding_mode: 'cent',
|
||||
},
|
||||
});
|
||||
async function seedHistorical(rate, customer) {
|
||||
await setRate(rate);
|
||||
return session.post('owner', '/api/recoveries', {
|
||||
date: day,
|
||||
mode: 'exchange',
|
||||
customer,
|
||||
customer_type: 'new',
|
||||
salesperson: '麦麦',
|
||||
member: 'owner',
|
||||
payer: 'owner',
|
||||
payment_account: '麦麦信用卡',
|
||||
verified: true,
|
||||
buy_rate: '0',
|
||||
old_lines: [{ name: '旧料', incoming_weight: '1', melted_weight: '1', purity: '100' }],
|
||||
exchange: {
|
||||
name: '足金999',
|
||||
quantity: '1',
|
||||
pocket: '现货',
|
||||
gold_price: '0',
|
||||
labor_rate: '200',
|
||||
labor_mode: 'total',
|
||||
depreciation_rate: '0',
|
||||
cost_labor: { mode: 'total', amount: '15' },
|
||||
cost_payer: 'owner',
|
||||
discount: '0',
|
||||
rounding_mode: 'cent',
|
||||
},
|
||||
});
|
||||
}
|
||||
const historical = await seedHistorical(4, '历史卡费对照');
|
||||
const noFee = await seedHistorical(0, '历史免手续费对照');
|
||||
await setRate(9);
|
||||
assert.deepEqual(session.problems, []);
|
||||
const owner = await ctx.pageFor('owner');
|
||||
const form = owner.locator('#recovery-form');
|
||||
const field = name => form.locator('[name="' + name + '"]');
|
||||
|
||||
async function capture(existingId, expectedRate, expectedCents) {
|
||||
async function capture(existingId, expectedRate, expectedReceived, expectedCents) {
|
||||
await field('verified').check();
|
||||
await owner
|
||||
.locator('#recovery-quote-status')
|
||||
@@ -75,14 +79,18 @@ export default async function historicalCardFee(ctx) {
|
||||
);
|
||||
assert.equal(data.credit_card_rate_permille, expectedRate);
|
||||
assert.equal(data.cardFee, expectedCents);
|
||||
if (!existingId || version === 'old') {
|
||||
const received = (data.netSettlement / 100).toFixed(2);
|
||||
const fee = (expectedCents / 100).toFixed(2);
|
||||
assert.equal(
|
||||
preview,
|
||||
`内部信用卡手续费:¥${received} × ${expectedRate}‰ = ¥${fee},由麦麦承担。客户结算金额不变。`,
|
||||
);
|
||||
}
|
||||
assert.equal(data.netSettlement, expectedReceived);
|
||||
const receipts = db
|
||||
.prepare(
|
||||
"SELECT SUM(amount) AS total FROM payments WHERE order_id=? AND kind='receipt' AND account='麦麦信用卡'",
|
||||
)
|
||||
.get(record.order_id);
|
||||
assert.equal(receipts.total, expectedReceived);
|
||||
const expenses = db
|
||||
.prepare('SELECT COUNT(*) AS count, COALESCE(SUM(amount), 0) AS total FROM expenses WHERE order_id=?')
|
||||
.get(record.order_id);
|
||||
assert.equal(expenses.total, expectedCents);
|
||||
if (expectedRate === 0) assert.equal(expenses.count, 0, '历史 0‰ 单应保留费率快照且不产生费用流水');
|
||||
assert.deepEqual(
|
||||
fees.map(row => [row.rate_permille, row.amount]),
|
||||
[[expectedRate, expectedCents]],
|
||||
@@ -109,18 +117,33 @@ export default async function historicalCardFee(ctx) {
|
||||
await field('labor_rate').fill('250');
|
||||
await field('cost_labor_value').fill('15');
|
||||
await field('payment_method').selectOption('信用卡');
|
||||
return capture(null, 9, 234);
|
||||
return capture(null, 9, 26000, 234);
|
||||
});
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await owner
|
||||
.locator('[data-action=recovery-open][data-id="' + historical.id + '"]')
|
||||
.first()
|
||||
.click();
|
||||
await action(owner.locator('#recovery-dialog[open]'), 'recovery-edit-open').click();
|
||||
const edit = await step('修改旧费率信用卡置换并核对预览和入账费用', async () => {
|
||||
await field('change_reason').fill('更正旧单工费');
|
||||
await field('labor_rate').fill('250');
|
||||
return capture(historical.id, 4, 100);
|
||||
});
|
||||
return { create, edit };
|
||||
async function editHistorical(id, rate, cents, label) {
|
||||
await section(owner, ctx, 'recoveries');
|
||||
await owner
|
||||
.locator('[data-action=recovery-open][data-id="' + id + '"]')
|
||||
.first()
|
||||
.click();
|
||||
await action(owner.locator('#recovery-dialog[open]'), 'recovery-edit-open').click();
|
||||
return step(label, async () => {
|
||||
await field('change_reason').fill('更正旧单工费');
|
||||
await field('labor_rate').fill('250');
|
||||
return capture(id, rate, 25000, cents);
|
||||
});
|
||||
}
|
||||
const edit = await editHistorical(historical.id, 4, 100, '修改旧费率信用卡置换并核对预览和入账费用');
|
||||
const editZero = await editHistorical(noFee.id, 0, 0, '修改零费率信用卡置换并核对免手续费及净收款');
|
||||
// 三笔先各自入账,再一起验证三张表单的预览,使 4‰ 和 0‰ 回归能在一次运行中分别复现。
|
||||
const records = { create, edit, editZero };
|
||||
const rows = Object.values(records);
|
||||
assert.deepEqual(
|
||||
rows.map(record => record.preview),
|
||||
rows.map(
|
||||
({ rate, received, fee }) =>
|
||||
`内部信用卡手续费:¥${(received / 100).toFixed(2)} × ${rate}‰ = ¥${(fee / 100).toFixed(2)},由麦麦承担。客户结算金额不变。`,
|
||||
),
|
||||
'每笔浏览器预览必须与已核实的实收、费率快照及关联手续费相符',
|
||||
);
|
||||
return records;
|
||||
}
|
||||
Reference in new issue
Block a user