2026-10-21 01:32:49 +08:00
|
|
|
'use strict';
|
|
|
|
|
const { test } = require('node:test'),
|
|
|
|
|
assert = require('node:assert/strict'),
|
|
|
|
|
{ randomUUID } = require('node:crypto');
|
|
|
|
|
const { Ledger } = require('../ledger');
|
|
|
|
|
const actor = { id: 'lock-report-owner', name: '测试麦麦', role: 'owner' };
|
|
|
|
|
const D = '2026-09-30',
|
|
|
|
|
D2 = '2026-10-01',
|
|
|
|
|
D3 = '2026-10-02',
|
|
|
|
|
D4 = '2026-10-03';
|
|
|
|
|
function fixture(t) {
|
|
|
|
|
const ledger = new Ledger(':memory:');
|
|
|
|
|
t.after(() => ledger.close());
|
|
|
|
|
const run = (input, fn) => ledger.transact(randomUUID(), actor, input, fn);
|
|
|
|
|
const create = (extra = {}) => {
|
2026-10-23 09:49:36 +08:00
|
|
|
const input = {
|
|
|
|
|
date: D,
|
|
|
|
|
customer: '合成锁价客户',
|
|
|
|
|
salesperson: '合成开单人',
|
|
|
|
|
line: {
|
|
|
|
|
name: '足金锁价挂件',
|
|
|
|
|
unit: 'g',
|
|
|
|
|
quantity: '2.000',
|
|
|
|
|
goldPrice: '1000',
|
|
|
|
|
laborRate: '20',
|
|
|
|
|
laborMode: 'gram',
|
|
|
|
|
},
|
2026-10-21 01:32:49 +08:00
|
|
|
material: { rate: '900', payer: 'owner', verified: true },
|
|
|
|
|
payment: { amount: '1000', account: '助理微信', verified: true },
|
|
|
|
|
...extra,
|
|
|
|
|
};
|
|
|
|
|
return run(input, () => ledger.createPriceLock(input, actor)).id;
|
|
|
|
|
};
|
|
|
|
|
const deliver = (id, extra = {}) => {
|
|
|
|
|
const input = {
|
|
|
|
|
date: D2,
|
|
|
|
|
revision: ledger.priceLockDetail(id).revision,
|
|
|
|
|
verified: true,
|
|
|
|
|
line: {
|
|
|
|
|
quantity: '2.200',
|
|
|
|
|
laborRate: '20',
|
|
|
|
|
laborMode: 'gram',
|
|
|
|
|
payer: 'assistant',
|
|
|
|
|
costPayers: { material: 'owner', labor: 'assistant' },
|
|
|
|
|
costParts: { labor: '0', accessories: '5', other: '1' },
|
|
|
|
|
costLabor: { mode: 'gram', rate: '20' },
|
|
|
|
|
},
|
|
|
|
|
inventory: { pocket: '现货', original: 'receive', extra: 'receive' },
|
|
|
|
|
extraMaterial: { rate: '950', payer: 'assistant', verified: true },
|
|
|
|
|
fee_items: [
|
|
|
|
|
{ key: 'shipping', note: '快递费', amount: '6', payer: 'assistant' },
|
|
|
|
|
{ key: 'box', note: '包装', amount: '3', payer: 'owner' },
|
|
|
|
|
],
|
|
|
|
|
settlement: { amount: '1244', account: '麦麦支付宝', verified: true },
|
|
|
|
|
...extra,
|
|
|
|
|
};
|
|
|
|
|
return run({ id, input }, () => ledger.deliverPriceLock(id, input, actor)).order_id;
|
|
|
|
|
};
|
|
|
|
|
const action = (id, kind, input) => run({ id, kind, input }, () => ledger.action(id, kind, input, actor));
|
|
|
|
|
const report = (date = D, from = date) => ledger.reportByOrderDate(date, from);
|
|
|
|
|
const close = (date = D) => run({ date, basis: 'orderDate' }, () => ledger.closeDay(date, actor, 'orderDate'));
|
|
|
|
|
return { ledger, run, create, deliver, action, report, close };
|
|
|
|
|
}
|
|
|
|
|
const channel = (report, key) => report.receiptsByOrderDate.channels.find(row => row.channel === key);
|
|
|
|
|
const contents = ledger =>
|
|
|
|
|
JSON.stringify(
|
|
|
|
|
ledger
|
|
|
|
|
.rows("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")
|
|
|
|
|
.map(({ name }) => [name, ledger.rows('SELECT * FROM "' + name + '"')]),
|
|
|
|
|
);
|
|
|
|
|
function totalsAdd(daily, combined) {
|
|
|
|
|
for (const key of ['sales', 'goods', 'expense', 'totalCost', 'profit', 'outlayGoods', 'outlayExpense', 'outlayTotal'])
|
|
|
|
|
assert.equal(
|
|
|
|
|
combined[key],
|
|
|
|
|
daily.reduce((sum, report) => sum + report[key], 0),
|
|
|
|
|
key,
|
|
|
|
|
);
|
|
|
|
|
for (const key of ['receipt', 'refund', 'net'])
|
|
|
|
|
assert.equal(
|
|
|
|
|
combined.receiptsByOrderDate[key],
|
|
|
|
|
daily.reduce((sum, report) => sum + report.receiptsByOrderDate[key], 0),
|
|
|
|
|
key,
|
|
|
|
|
);
|
|
|
|
|
for (const payer of ['owner', 'assistant'])
|
|
|
|
|
assert.equal(
|
|
|
|
|
combined.payerCosts[payer].total,
|
|
|
|
|
daily.reduce((sum, report) => sum + report.payerCosts[payer].total, 0),
|
|
|
|
|
payer,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('锁价当日只核对客户实收及双方实付料费,不生成销售、利润或扣库存', t => {
|
|
|
|
|
const f = fixture(t),
|
|
|
|
|
lock = f.create(),
|
|
|
|
|
r = f.report(),
|
|
|
|
|
b = f.ledger.orderBook({ date: D });
|
|
|
|
|
assert.equal(r.summary.orderCount, 0);
|
|
|
|
|
assert.deepEqual(r.orderRows, []);
|
|
|
|
|
assert.equal(r.sales, 0);
|
|
|
|
|
assert.equal(r.totalCost, 0);
|
|
|
|
|
assert.equal(r.profit, 0);
|
|
|
|
|
assert.equal(r.goods, 0);
|
|
|
|
|
assert.equal(r.expense, 0);
|
|
|
|
|
assert.equal(r.outlayGoods, 180000);
|
|
|
|
|
assert.equal(r.outlayTotal, 180000);
|
|
|
|
|
assert.equal(r.payerCosts.owner.goods, 180000);
|
|
|
|
|
assert.equal(r.payerCosts.owner.total, 180000);
|
|
|
|
|
assert.equal(r.payerCosts.assistant.total, 0);
|
|
|
|
|
assert.equal(r.orderPayerCosts.owner.total, 0);
|
|
|
|
|
assert.equal(channel(r, 'wechat').receipt, 100000);
|
|
|
|
|
assert.equal(r.receiptsByOrderDate.net, 100000);
|
|
|
|
|
assert.equal(b.receiptsWithoutCancelled.net, 100000);
|
|
|
|
|
assert.equal(b.receiptsByPaymentDate.net, 100000);
|
|
|
|
|
assert.equal(r.priceLockActivity.summary.lockCount, 1);
|
|
|
|
|
assert.equal(r.priceLockActivity.summary.materialOutlay, 180000);
|
|
|
|
|
const material = r.payerCosts.owner.items[0];
|
|
|
|
|
assert.equal(material.price_lock_id, lock);
|
|
|
|
|
assert.equal(material.component, 'material');
|
|
|
|
|
assert.equal(material.name, '锁价料费');
|
|
|
|
|
assert.equal(material.date, D);
|
|
|
|
|
assert.deepEqual(material.calculation, { rate: 90000, quantity: 2000 });
|
|
|
|
|
assert.equal(r.priceLockActivity.customerCash[0].customer, '合成锁价客户');
|
|
|
|
|
assert.equal(r.priceLockActivity.materialOutlays[0].product, '足金锁价挂件');
|
|
|
|
|
assert.equal(f.ledger.rows('SELECT * FROM orders').length, 0);
|
|
|
|
|
assert.equal(f.ledger.rows('SELECT * FROM journal').length, 0);
|
|
|
|
|
assert.equal(f.ledger.rows('SELECT * FROM movements').length, 0);
|
|
|
|
|
assert.equal(f.ledger.report(D).accounts.find(row => row.account === '助理微信').receipt, 100000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('跨月交付按原销售金价和实际分段料费算完整利润,原日收付及快照保持不变', t => {
|
|
|
|
|
const f = fixture(t),
|
|
|
|
|
lock = f.create(),
|
|
|
|
|
first = f.report();
|
|
|
|
|
f.close();
|
|
|
|
|
const id = f.deliver(lock),
|
|
|
|
|
original = f.report(),
|
|
|
|
|
delivery = f.report(D2),
|
|
|
|
|
order = f.ledger.detail(id);
|
|
|
|
|
assert.equal(original.reportRevision, first.reportRevision);
|
|
|
|
|
assert.equal(original.close.stale, false);
|
|
|
|
|
assert.equal(original.receiptsByOrderDate.receipt, 100000);
|
|
|
|
|
assert.equal(original.outlayTotal, 180000);
|
|
|
|
|
assert.equal(original.summary.orderCount, 0);
|
|
|
|
|
assert.equal(order.date, D2);
|
|
|
|
|
assert.equal(order.lines[0].goldPrice, 100000);
|
|
|
|
|
assert.equal(order.total, 224400);
|
|
|
|
|
assert.equal(delivery.sales, 224400);
|
|
|
|
|
assert.equal(delivery.goods, 204000);
|
|
|
|
|
assert.equal(delivery.expense, 900);
|
|
|
|
|
assert.equal(delivery.totalCost, 204900);
|
|
|
|
|
assert.equal(delivery.profit, 19500);
|
|
|
|
|
assert.equal(delivery.profit, order.profit);
|
|
|
|
|
assert.equal(delivery.receiptsByOrderDate.receipt, 124400);
|
|
|
|
|
assert.equal(channel(delivery, 'alipay').receipt, 124400);
|
|
|
|
|
assert.equal(channel(delivery, 'wechat').receipt, 0);
|
|
|
|
|
assert.equal(delivery.outlayGoods, 24000);
|
|
|
|
|
assert.equal(delivery.outlayExpense, 900);
|
|
|
|
|
assert.equal(delivery.outlayTotal, 24900);
|
|
|
|
|
assert.equal(delivery.payerCosts.owner.total, 300);
|
|
|
|
|
assert.equal(delivery.payerCosts.assistant.total, 24600);
|
|
|
|
|
assert.equal(delivery.orderPayerCosts.owner.total, 180300);
|
|
|
|
|
assert.equal(delivery.orderPayerCosts.assistant.total, 24600);
|
|
|
|
|
assert.equal(delivery.summary.ownerCost, 180300);
|
|
|
|
|
assert.equal(delivery.summary.assistantCost, 24600);
|
|
|
|
|
const costs = delivery.orderRows[0].costItems.filter(item => item.component === 'material');
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
costs.map(item => [item.amount, item.payer, item.calculation]),
|
2026-12-04 08:58:53 -08:00
|
|
|
[
|
2026-10-21 01:32:49 +08:00
|
|
|
[180000, 'owner', { rate: 90000, quantity: 2000 }],
|
|
|
|
|
[19000, 'assistant', { rate: 95000, quantity: 200 }],
|
2026-12-04 08:58:53 -08:00
|
|
|
],
|
2026-10-21 01:32:49 +08:00
|
|
|
);
|
|
|
|
|
assert.equal(delivery.priceLockActivity.summary.materialOutlay, 19000);
|
|
|
|
|
assert.equal(delivery.payments.length, 1);
|
|
|
|
|
const september = f.report(D, '2026-09-01'),
|
|
|
|
|
october = f.report(D3, D2),
|
|
|
|
|
week = f.report('2026-10-04', '2026-09-28'),
|
|
|
|
|
combined = f.report(D3, D);
|
|
|
|
|
assert.equal(september.receiptsByOrderDate.receipt, 100000);
|
|
|
|
|
assert.equal(september.outlayTotal, 180000);
|
|
|
|
|
assert.equal(october.receiptsByOrderDate.receipt, 124400);
|
|
|
|
|
assert.equal(october.outlayTotal, 24900);
|
|
|
|
|
assert.equal(october.sales, 224400);
|
|
|
|
|
totalsAdd([original, delivery, f.report(D3)], combined);
|
|
|
|
|
totalsAdd([september, october], combined);
|
|
|
|
|
totalsAdd([combined], week);
|
|
|
|
|
assert.equal(combined.receiptsByOrderDate.receipt, order.total);
|
|
|
|
|
assert.equal(combined.outlayTotal, order.goodsCost + order.directCost);
|
|
|
|
|
assert.equal(combined.receiptsByOrderDate.orderCount, 1);
|
|
|
|
|
assert.equal(combined.priceLockActivity.summary.lockCount, 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('同日锁价及交付不重复计算原料和定金,双方付款归属与完整订单一致', t => {
|
|
|
|
|
const f = fixture(t),
|
|
|
|
|
lock = f.create(),
|
|
|
|
|
id = f.deliver(lock, { date: D }),
|
|
|
|
|
r = f.report(),
|
|
|
|
|
order = f.ledger.detail(id);
|
|
|
|
|
assert.equal(r.summary.completedCount, 1);
|
|
|
|
|
assert.equal(r.sales, 224400);
|
|
|
|
|
assert.equal(r.receiptsByOrderDate.receipt, 224400);
|
|
|
|
|
assert.equal(channel(r, 'wechat').receipt, 100000);
|
|
|
|
|
assert.equal(channel(r, 'alipay').receipt, 124400);
|
|
|
|
|
assert.equal(r.outlayGoods, r.goods);
|
|
|
|
|
assert.equal(r.outlayExpense, r.expense);
|
|
|
|
|
assert.equal(r.outlayTotal, r.totalCost);
|
|
|
|
|
assert.equal(r.payerCosts.owner.total, 180300);
|
|
|
|
|
assert.equal(r.payerCosts.assistant.total, 24600);
|
|
|
|
|
assert.equal(r.profit, r.sales - r.totalCost);
|
|
|
|
|
assert.equal(r.profit, order.profit);
|
|
|
|
|
assert.equal(
|
|
|
|
|
f.ledger.rows('SELECT * FROM payments WHERE order_id=?', id).length,
|
|
|
|
|
0,
|
|
|
|
|
'锁价实际收款不复制进普通收款表',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('原料由助理支付、补重及工费由麦麦支付时分别进入实际付款日', t => {
|
|
|
|
|
const f = fixture(t),
|
|
|
|
|
lock = f.create({ material: { rate: '900', payer: 'assistant', verified: true } });
|
|
|
|
|
f.deliver(lock, {
|
|
|
|
|
line: {
|
|
|
|
|
quantity: '2.200',
|
|
|
|
|
laborRate: '20',
|
|
|
|
|
laborMode: 'gram',
|
|
|
|
|
payer: 'owner',
|
|
|
|
|
costPayers: { material: 'assistant', labor: 'owner' },
|
|
|
|
|
costParts: { labor: '0', accessories: '5', other: '1' },
|
|
|
|
|
costLabor: { mode: 'gram', rate: '20' },
|
2026-12-04 08:58:53 -08:00
|
|
|
},
|
2026-10-21 01:32:49 +08:00
|
|
|
extraMaterial: { rate: '950', payer: 'owner', verified: true },
|
|
|
|
|
fee_items: [
|
|
|
|
|
{ key: 'shipping', note: '快递费', amount: '6', payer: 'owner' },
|
|
|
|
|
{ key: 'box', note: '包装', amount: '3', payer: 'owner' },
|
2026-12-04 08:58:53 -08:00
|
|
|
],
|
2026-10-21 01:32:49 +08:00
|
|
|
});
|
|
|
|
|
const first = f.report(),
|
|
|
|
|
delivery = f.report(D2),
|
|
|
|
|
combined = f.report(D2, D);
|
|
|
|
|
assert.equal(first.payerCosts.owner.total, 0);
|
|
|
|
|
assert.equal(first.payerCosts.assistant.total, 180000);
|
|
|
|
|
assert.equal(delivery.payerCosts.owner.total, 24900);
|
|
|
|
|
assert.equal(delivery.payerCosts.assistant.total, 0);
|
|
|
|
|
assert.equal(delivery.orderPayerCosts.owner.total, 24900);
|
|
|
|
|
assert.equal(delivery.orderPayerCosts.assistant.total, 180000);
|
|
|
|
|
assert.equal(delivery.profit, 19500);
|
|
|
|
|
totalsAdd([first, delivery], combined);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('不足锁重的未消耗原料留作资产,交付日只出现客户实退和新增工费费用', t => {
|
|
|
|
|
const f = fixture(t),
|
|
|
|
|
lock = f.create({ payment: { amount: '2200', account: '助理微信', verified: true } });
|
|
|
|
|
const id = f.deliver(lock, {
|
|
|
|
|
line: {
|
|
|
|
|
quantity: '1.800',
|
|
|
|
|
laborRate: '20',
|
|
|
|
|
laborMode: 'gram',
|
|
|
|
|
payer: 'assistant',
|
|
|
|
|
costPayers: { material: 'owner', labor: 'assistant' },
|
|
|
|
|
costParts: { labor: '0', accessories: '5', other: '1' },
|
|
|
|
|
costLabor: { mode: 'gram', rate: '20' },
|
2026-12-04 08:58:53 -08:00
|
|
|
},
|
2026-10-21 01:32:49 +08:00
|
|
|
inventory: { pocket: '现货', original: 'receive' },
|
|
|
|
|
settlement: { amount: '364', account: '助理微信', verified: true },
|
|
|
|
|
});
|
|
|
|
|
const first = f.report(),
|
|
|
|
|
r = f.report(D2),
|
|
|
|
|
combined = f.report(D2, D),
|
|
|
|
|
lockDetail = f.ledger.priceLockDetail(lock);
|
|
|
|
|
assert.equal(first.receiptsByOrderDate.receipt, 220000);
|
|
|
|
|
assert.equal(first.payerCosts.owner.total, 180000);
|
|
|
|
|
assert.equal(r.sales, 183600);
|
|
|
|
|
assert.equal(r.totalCost, 167100);
|
|
|
|
|
assert.equal(r.profit, 16500);
|
|
|
|
|
assert.equal(r.receiptsByOrderDate.receipt, 0);
|
|
|
|
|
assert.equal(r.receiptsByOrderDate.refund, 36400);
|
|
|
|
|
assert.equal(r.receiptsByOrderDate.net, -36400);
|
|
|
|
|
assert.equal(r.priceLockActivity.materialOutlays.length, 0);
|
|
|
|
|
assert.equal(r.outlayTotal, 5100);
|
|
|
|
|
assert.equal(r.payerCosts.owner.total, 300);
|
|
|
|
|
assert.equal(r.payerCosts.assistant.total, 4800);
|
|
|
|
|
assert.equal(lockDetail.delivery.leftover_mg, 200);
|
|
|
|
|
assert.equal(lockDetail.delivery.leftover_cost, 18000);
|
|
|
|
|
assert.equal(f.ledger.inventory().find(row => row.pocket === '现货').mg, 200);
|
|
|
|
|
assert.equal(combined.outlayTotal - combined.totalCost, 18000);
|
|
|
|
|
assert.equal(combined.receiptsByOrderDate.net, f.ledger.detail(id).total);
|
|
|
|
|
totalsAdd([first, r], combined);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('交付后新增费用和费用付款人更正按实际日期核对,完整订单成本仍只计最新有效费用', t => {
|
|
|
|
|
const f = fixture(t),
|
|
|
|
|
lock = f.create();
|
|
|
|
|
f.close();
|
|
|
|
|
const originalRevision = f.report().reportRevision,
|
|
|
|
|
id = f.deliver(lock);
|
|
|
|
|
f.action(id, 'expense', { date: D3, amount: '10', payer: 'owner', note: '追加实际证书费' });
|
|
|
|
|
const target = f.ledger.detail(id).expenses.find(item => item.note === '追加实际证书费').id;
|
|
|
|
|
f.action(id, 'correct', {
|
|
|
|
|
date: D4,
|
|
|
|
|
type: 'expense',
|
|
|
|
|
target,
|
|
|
|
|
amount: '7',
|
|
|
|
|
payer: 'assistant',
|
|
|
|
|
reason: '核对实际付款人及金额',
|
|
|
|
|
verified: true,
|
|
|
|
|
});
|
|
|
|
|
const delivery = f.report(D2),
|
|
|
|
|
paid = f.report(D3),
|
|
|
|
|
corrected = f.report(D4),
|
|
|
|
|
month = f.report(D4, D2);
|
|
|
|
|
assert.equal(delivery.totalCost, 205600);
|
|
|
|
|
assert.equal(delivery.profit, 18800);
|
|
|
|
|
assert.equal(delivery.outlayExpense, 900);
|
|
|
|
|
assert.equal(paid.totalCost, 0);
|
|
|
|
|
assert.equal(paid.outlayExpense, 1000);
|
|
|
|
|
assert.equal(paid.payerCosts.owner.total, 1000);
|
|
|
|
|
assert.equal(corrected.totalCost, 0);
|
|
|
|
|
assert.equal(corrected.outlayExpense, -300);
|
|
|
|
|
assert.equal(corrected.payerCosts.owner.total, -1000);
|
|
|
|
|
assert.equal(corrected.payerCosts.assistant.total, 700);
|
|
|
|
|
assert.equal(corrected.priceLockActivity.directOutlays.length, 2);
|
|
|
|
|
assert.equal(month.outlayExpense, 1600);
|
|
|
|
|
assert.equal(delivery.orderPayerCosts.owner.paidFees, 300);
|
|
|
|
|
assert.equal(delivery.orderPayerCosts.assistant.paidFees, 1300);
|
|
|
|
|
totalsAdd([delivery, paid, corrected], month);
|
|
|
|
|
assert.equal(f.report().reportRevision, originalRevision);
|
|
|
|
|
assert.equal(f.report().close.stale, false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('交付后的普通退款与退款更正归实际日期,不能被整单付款历史再次带回交付日', t => {
|
|
|
|
|
const f = fixture(t),
|
|
|
|
|
lock = f.create(),
|
|
|
|
|
id = f.deliver(lock);
|
|
|
|
|
f.action(id, 'return', { date: D3, reason: '合成退货', verified: true });
|
|
|
|
|
f.action(id, 'refund', { date: D3, amount: '400', account: '助理微信', verified: true });
|
|
|
|
|
const target = f.ledger.detail(id).payments.find(item => item.kind === 'refund' && !item.price_lock_event_id).id;
|
|
|
|
|
f.action(id, 'correct', {
|
|
|
|
|
date: D4,
|
|
|
|
|
type: 'payment',
|
|
|
|
|
target,
|
|
|
|
|
amount: '500',
|
|
|
|
|
account: '助理微信',
|
|
|
|
|
reason: '退款金额核实',
|
|
|
|
|
verified: true,
|
|
|
|
|
});
|
|
|
|
|
const delivery = f.report(D2),
|
|
|
|
|
refund = f.report(D3),
|
|
|
|
|
correction = f.report(D4),
|
|
|
|
|
month = f.report(D4, D2);
|
|
|
|
|
assert.equal(delivery.receiptsByOrderDate.receipt, 124400);
|
|
|
|
|
assert.equal(delivery.receiptsByOrderDate.refund, 0);
|
|
|
|
|
assert.equal(refund.receiptsByOrderDate.refund, 40000);
|
|
|
|
|
assert.equal(correction.receiptsByOrderDate.refund, 10000);
|
|
|
|
|
assert.equal(channel(correction, 'wechat').net, -10000);
|
|
|
|
|
assert.equal(month.receiptsByOrderDate.refund, 50000);
|
|
|
|
|
assert.equal(delivery.goods, 0);
|
|
|
|
|
assert.equal(delivery.totalCost, 900);
|
|
|
|
|
assert.equal(delivery.profit, -900);
|
|
|
|
|
assert.equal(delivery.outlayGoods, 24000, '退货冲回消耗成本,不改写当时已实际支付的工费及补重料费');
|
|
|
|
|
totalsAdd([delivery, refund, correction], month);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('锁价日报与订单簿反复读取无写入,其他日期新增锁价不会让原普通订单快照过期', t => {
|
2026-10-23 09:49:36 +08:00
|
|
|
const f = fixture(t),
|
|
|
|
|
input = {
|
|
|
|
|
date: D,
|
|
|
|
|
customer: '普通客户',
|
|
|
|
|
salesperson: '合成开单人',
|
|
|
|
|
payment_account: '助理现金',
|
|
|
|
|
fee_items: [],
|
2026-10-21 01:32:49 +08:00
|
|
|
lines: [
|
2026-12-04 08:58:53 -08:00
|
|
|
{
|
2026-10-21 01:32:49 +08:00
|
|
|
name: '合成普通单',
|
|
|
|
|
unit: '件',
|
|
|
|
|
quantity: '1',
|
|
|
|
|
pocket: '',
|
|
|
|
|
payer: 'owner',
|
|
|
|
|
sale: '100',
|
|
|
|
|
costParts: { material: '50', labor: '0', accessories: '0', other: '0' },
|
2026-12-04 08:58:53 -08:00
|
|
|
},
|
|
|
|
|
],
|
2026-10-21 01:32:49 +08:00
|
|
|
};
|
|
|
|
|
f.run(input, () => f.ledger.issueOrder(input, actor));
|
|
|
|
|
f.close();
|
|
|
|
|
const revision = f.report().reportRevision;
|
|
|
|
|
f.create({ date: D2 });
|
|
|
|
|
assert.equal(f.report().reportRevision, revision);
|
|
|
|
|
assert.equal(f.report().close.stale, false);
|
|
|
|
|
const before = contents(f.ledger),
|
|
|
|
|
changes = f.ledger.one('SELECT total_changes() AS count').count;
|
|
|
|
|
const first = f.report(D2);
|
|
|
|
|
assert.deepEqual(f.report(D2), first);
|
|
|
|
|
f.ledger.orderBook({ date: D2 });
|
|
|
|
|
f.report(D2, D);
|
|
|
|
|
f.report(D3);
|
|
|
|
|
assert.equal(f.ledger.one('SELECT total_changes() AS count').count, changes);
|
|
|
|
|
assert.equal(contents(f.ledger), before);
|
|
|
|
|
});
|