补齐固定旧版的浏览器逐笔写入对照并记录账务差异
This commit is contained in:
1 parent
e77588b337
commit
7d2007955f
39 files changed
+3653
-41
No files matched your search
@@ -0,0 +1,128 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createRequire } from 'node:module';
|
||||
import path from 'node:path';
|
||||
import { ui } from './funds-ui.mjs';
|
||||
|
||||
function seedLegacyPurchases(appPath, dbPath, dates) {
|
||||
// 使用与旧购料账本测试相同的双人 Ledger 入口,真实生成结算、耗料和分摊记录。
|
||||
const { Ledger } = createRequire(import.meta.url)(path.join(appPath, 'core/ledger.js'));
|
||||
const ledger = new Ledger(dbPath);
|
||||
const actor = { id: 'legacy-assistant-funds', role: 'assistant', name: '库存交接员' };
|
||||
try {
|
||||
for (const [index, date] of dates.entries()) {
|
||||
const run = (kind, input, save) => ledger.transact('funds-legacy-' + date + '-' + kind, actor, input, save);
|
||||
const buy = { date, grams: '10', total: '9000', payer: 'assistant', note: '双人旧账采购凭据' };
|
||||
run('buy', buy, () => ledger.createMaterialPurchase(buy, actor));
|
||||
if (index === 0) continue;
|
||||
const pay = {
|
||||
date,
|
||||
amount: '9000',
|
||||
direction: 'toAssistant',
|
||||
verified: true,
|
||||
note: '双人账先结清整批',
|
||||
revision: ledger.materialPoolDetail(date).revision,
|
||||
};
|
||||
run('settle', pay, () => ledger.settleMaterialPool(date, pay, actor));
|
||||
const sale = {
|
||||
date,
|
||||
customer: '双人旧账后续耗料',
|
||||
internal_note: '原单凭据',
|
||||
salesperson: '库存交接员',
|
||||
discount: '0',
|
||||
payment_account: '助理微信',
|
||||
fee_items: [],
|
||||
lines: [
|
||||
{
|
||||
name: '足金999',
|
||||
unit: 'g',
|
||||
quantity: '3',
|
||||
pocket: '',
|
||||
payer: 'owner',
|
||||
pricingMode: 'manual',
|
||||
sale: '3000',
|
||||
costParts: { material: '0', labor: '0', accessories: '0', other: '0' },
|
||||
costMaterial: { mode: 'pool', poolId: date },
|
||||
},
|
||||
],
|
||||
};
|
||||
run('sale', sale, () => ledger.issueOrder(sale, actor));
|
||||
}
|
||||
} finally {
|
||||
ledger.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url) && process.argv[2] === '--seed-legacy-pools') {
|
||||
seedLegacyPurchases(process.argv[3], process.argv[4], process.argv.slice(5));
|
||||
}
|
||||
|
||||
export default async function legacyPools(context) {
|
||||
const { session, day, dbPath, appPath } = context;
|
||||
const dates = [4, 3].map(offset =>
|
||||
new Date(Date.parse(day + 'T02:00:00Z') - offset * 86400000).toISOString().slice(0, 10),
|
||||
);
|
||||
assert.ok(dbPath, '需要当前对照组的临时 SQLite 路径以准备双人时代的购料记录');
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[
|
||||
'--disable-warning=ExperimentalWarning',
|
||||
'--require',
|
||||
path.join(appPath, 'e2e/fake-clock.cjs'),
|
||||
fileURLToPath(import.meta.url),
|
||||
'--seed-legacy-pools',
|
||||
appPath,
|
||||
dbPath,
|
||||
...dates,
|
||||
],
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
TZ: 'Asia/Shanghai',
|
||||
FAKE_CLOCK_START: day + 'T02:00:00Z',
|
||||
FAKE_RANDOM_SEED: 'old-two-person-pool-fixture',
|
||||
FAKE_CLOCK_TICK_MS: '0',
|
||||
},
|
||||
},
|
||||
);
|
||||
const owner = await context.pageFor('owner');
|
||||
const { navigate, write } = ui(context);
|
||||
const user = (await session.get('owner', '/api/state')).user.id;
|
||||
for (const [index, date] of dates.entries()) {
|
||||
const url = '/api/material-pools/' + date;
|
||||
const detail = await session.get('owner', url);
|
||||
const due = index === 0 ? -900000 : 270000;
|
||||
assert.equal(detail.settlement.settlementDue, due);
|
||||
const direction = due < 0 ? 'toAssistant' : 'toOwner';
|
||||
const job = {
|
||||
url: url + '/settlement',
|
||||
userId: user,
|
||||
key: 'funds-legacy-pool-settle-' + date,
|
||||
data: {
|
||||
date: day,
|
||||
amount: (Math.abs(due) / 100).toFixed(2),
|
||||
direction,
|
||||
note: '旧批次结算原操作',
|
||||
verified: true,
|
||||
revision: detail.revision,
|
||||
},
|
||||
};
|
||||
await owner.evaluate(job => localStorage.setItem('mm-pending-' + job.userId, JSON.stringify(job)), job);
|
||||
await owner.reload();
|
||||
await navigate(owner, 'material-pools');
|
||||
const response = await write(
|
||||
'恢复双人旧购料' + (index === 0 ? '返还店员垫付款' : '耗料后向店主交款'),
|
||||
owner,
|
||||
job.url,
|
||||
() => owner.getByRole('button', { name: '恢复原操作', exact: true }).click(),
|
||||
);
|
||||
assert.equal(response.request().headers()['idempotency-key'], job.key);
|
||||
assert.deepEqual(response.request().postDataJSON(), job.data);
|
||||
const after = await session.get('owner', url);
|
||||
assert.equal(after.settlement.settlementDue, 0);
|
||||
assert.equal(after.settlements.length, detail.settlements.length + 1);
|
||||
assert.equal(after.settlements.at(-1).amount, due);
|
||||
assert.equal(await owner.evaluate(key => localStorage.getItem(key), 'mm-pending-' + user), null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user