2026-10-14 11:59:07 -05:00
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
|
import { COPY_FLOWS, OBJECT_TYPES, copyFromDocument, copySources, copyTargets } from './document-copy';
|
|
|
|
|
import { DOCUMENT_SCREENS } from './document-screens';
|
|
|
|
|
|
|
|
|
|
describe('flujos de copiado', () => {
|
|
|
|
|
it('cada documento del flujo existe como pantalla y tiene tipo de objeto', () => {
|
|
|
|
|
const paths = new Set(DOCUMENT_SCREENS.map((s) => s.path));
|
|
|
|
|
for (const [from, to] of Object.entries(COPY_FLOWS)) {
|
|
|
|
|
for (const p of [from, ...to]) {
|
|
|
|
|
expect(paths.has(p), p).toBe(true);
|
|
|
|
|
expect(OBJECT_TYPES[p], p).toBeGreaterThan(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('solo ventas con ventas y compras con compras', () => {
|
|
|
|
|
for (const [from, to] of Object.entries(COPY_FLOWS)) {
|
|
|
|
|
for (const p of to) expect(p.split('/')[1], `${from} → ${p}`).toBe(from.split('/')[1]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('copiar a / copiar de son los dos lados del mismo flujo', () => {
|
2026-10-15 17:32:32 -05:00
|
|
|
expect(copyTargets('/ventas/ordenes')).toEqual([
|
|
|
|
|
'/ventas/entrega', '/ventas/facturas', '/ventas/boletas', '/ventas/facturas-reserva', '/ventas/boletas-reserva',
|
|
|
|
|
]);
|
2026-10-14 11:59:07 -05:00
|
|
|
expect(copySources('/ventas/facturas')).toEqual(['/ventas/ofertas', '/ventas/ordenes', '/ventas/entrega']);
|
2026-10-15 17:13:33 -05:00
|
|
|
expect(copySources('/ventas/boletas')).toEqual(['/ventas/ofertas', '/ventas/ordenes', '/ventas/entrega']);
|
2026-10-15 17:32:32 -05:00
|
|
|
expect(copySources('/ventas/facturas-reserva')).toEqual(['/ventas/ofertas', '/ventas/ordenes']);
|
|
|
|
|
expect(copySources('/ventas/boletas-reserva')).toEqual(['/ventas/ofertas', '/ventas/ordenes']);
|
2026-10-15 17:13:33 -05:00
|
|
|
expect(copyTargets('/ventas/boletas')).toEqual(['/ventas/notas-credito']);
|
2026-10-14 11:59:07 -05:00
|
|
|
expect(copyTargets('/ventas/notas-credito')).toEqual([]);
|
|
|
|
|
expect(copySources('/ventas/ofertas')).toEqual([]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('copyFromDocument', () => {
|
|
|
|
|
const source = {
|
|
|
|
|
DocEntry: 315,
|
|
|
|
|
DocNum: 1315,
|
|
|
|
|
CardCode: 'C1',
|
|
|
|
|
NumAtCard: 'REF',
|
|
|
|
|
DiscountPercent: 5,
|
|
|
|
|
DocumentLines: [
|
|
|
|
|
{ LineNum: 0, ItemCode: 'A1', ItemDescription: 'Pieza', Quantity: 5, RemainingOpenQuantity: 3, WarehouseCode: '01', Price: 100, DiscountPercent: 0, TaxCode: 'IVA', LineStatus: 'bost_Open' },
|
|
|
|
|
{ LineNum: 1, ItemCode: 'B2', Quantity: 2, RemainingOpenQuantity: 0, LineStatus: 'bost_Close' },
|
|
|
|
|
{ LineNum: 2, ItemCode: 'C3', ItemDescription: 'Otra', Quantity: 1, Price: 10, LineStatus: 'bost_Open' },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it('copia las líneas abiertas con la cantidad pendiente y la referencia al origen', () => {
|
|
|
|
|
const c = copyFromDocument(source, '/ventas/ordenes', 'Órdenes de venta');
|
|
|
|
|
expect(c.skipped).toBe(1);
|
|
|
|
|
expect(c.lines).toHaveLength(2);
|
|
|
|
|
expect(c.lines[0]).toMatchObject({
|
|
|
|
|
ItemCode: 'A1', Quantity: 3, Price: 100, LineTotal: 300, BaseType: 17, BaseEntry: 315, BaseLine: 0,
|
|
|
|
|
});
|
|
|
|
|
expect(c.lines[1]).toMatchObject({ ItemCode: 'C3', Quantity: 1, BaseLine: 2 });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('copia socio, referencia y descuento, y deja el origen en el comentario', () => {
|
|
|
|
|
expect(copyFromDocument(source, '/ventas/ordenes', 'Órdenes de venta').header).toEqual({
|
|
|
|
|
CardCode: 'C1',
|
|
|
|
|
NumAtCard: 'REF',
|
|
|
|
|
DiscountPercent: 5,
|
2026-10-16 11:07:38 -05:00
|
|
|
Project: '',
|
|
|
|
|
Indicator: '',
|
2026-10-14 11:59:07 -05:00
|
|
|
Comments: 'Basado en órdenes de venta 1315.',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|