43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
import { expect, it } from 'vitest';
|
|||
|
|
import { Model } from '../src/shared';
|
||
|
|
import type { LedgerState, ReturnedStockLot } from '../src/shared';
|
||
|
|
import { applyLot, restore } from '../src/pages/CreateOrder/useReturnedLots';
|
||
|
|
|
||
|
|
const state: LedgerState = {
|
||
|
|
today: '2026-11-21',
|
||
|
|
mode: 'trial',
|
||
|
|
user: { id: 'u', name: '店主', member: 'owner', role: 'owner' },
|
||
|
|
pockets: ['现货'],
|
||
|
|
};
|
||
|
|
const context = { st: state, uuid: () => 'example' };
|
||
|
|
const lot: ReturnedStockLot = {
|
||
|
|
id: 'returned-necklace',
|
||
|
|
available: true,
|
||
|
|
remainingMg: 2000,
|
||
|
|
date: state.today,
|
||
|
|
name: '足金项链',
|
||
|
|
pocket: '现货',
|
||
|
|
laborCost: 5000,
|
||
|
|
laborPayer: 'assistant',
|
||
|
|
};
|
||
|
|
|
||
|
|
it('编辑已开再售单时保留已消耗批次,新开单使用该批次须先验证库存', () => {
|
||
|
|
const draft = {
|
||
|
|
customer_type: 'new',
|
||
|
|
lines: [{ name: '足金项链', payer: 'owner', cost: '1250', returnedStockId: lot.id }],
|
||
|
|
};
|
||
|
|
expect(() => Model.validateFormFields(Model.newForm(context, draft), state)).toThrow(/所选售后退回现货/);
|
||
|
|
const edit = Model.newForm({ ...context, editing: true }, { ...draft, id: 'original-resale' });
|
||
|
|
expect(() => Model.validateFormFields(edit, state)).not.toThrow();
|
||
|
|
expect(Model.syncForm(edit, context).draft.lines[0].returnedStockId).toBe(lot.id);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('套用批次继承整批重量、原工费及其付款人,取消时保留新填的售价', () => {
|
||
|
|
const line = Model.newLine({ name: '足金999', quantity: '1.2' }, context);
|
||
|
|
const applied = applyLot(line, lot, state.today);
|
||
|
|
expect(applied.quantity).toBe('2.000');
|
||
|
|
expect(applied.purchase).toMatchObject({ laborMode: 'total', labor: '50.00', laborPayer: 'assistant' });
|
||
|
|
const restored = restore({ ...applied, goldPrice: '800' });
|
||
|
|
expect(restored).toMatchObject({ quantity: '1.2', goldPrice: '800', purchase: line.purchase, pool: line.pool });
|
||
|
|
expect(restored.returnedStockId).toBeUndefined();
|
||
|
|
});
|