Enhance sales document flow with new service and related functionalities

- Introduced `SalesDocumentFlowService` to manage the lifecycle of sales documents, including packing slips and invoices.
- Implemented methods for processing orders, generating invoices, and handling packing slips based on order status.
- Updated `SalesOrdersService`, `PackingSlipsService`, and `SalesInvoicesService` to integrate with the new document flow service.
- Added new methods for marking drafts processed and checking if invoices are on sales plans.
- Enhanced existing services and repositories to support new functionalities, including status transitions and related document management.
- Updated DTOs to include new fields for packing slip and invoice IDs in sales order responses.
- Added unit tests for the new service and updated existing tests to cover new functionalities.
This commit is contained in:
shancheas
2026-08-31 09:35:18 +07:00
parent 627aeac4a0
commit afed5ff0f5
24 changed files with 950 additions and 53 deletions
@@ -1,7 +1,13 @@
import {
isAllowedStatusTransition,
isValidDocumentCode,
isValidImageUrl,
isValidLatitude,
PACKING_SLIP_USER_TRANSITIONS,
SALES_INVOICE_USER_TRANSITIONS,
SALES_ORDER_SYSTEM_TRANSITIONS,
SALES_ORDER_USER_TRANSITIONS,
SALES_PAYMENT_USER_TRANSITIONS,
} from './sales-fields';
describe('sales fields', () => {
@@ -22,4 +28,93 @@ describe('sales fields', () => {
expect(isValidLatitude(-6.2)).toBe(true);
expect(isValidLatitude(100)).toBe(false);
});
it('allows sales-order user transitions draft to processed or cancelled', () => {
expect(
isAllowedStatusTransition(
'draft',
'processed',
SALES_ORDER_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'draft',
'cancelled',
SALES_ORDER_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'processed',
'completed',
SALES_ORDER_USER_TRANSITIONS,
),
).toBe(false);
expect(
isAllowedStatusTransition(
'processed',
'completed',
SALES_ORDER_SYSTEM_TRANSITIONS,
),
).toBe(true);
});
it('allows packing processed to completed or cancelled', () => {
expect(
isAllowedStatusTransition(
'processed',
'completed',
PACKING_SLIP_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'draft',
'completed',
PACKING_SLIP_USER_TRANSITIONS,
),
).toBe(false);
});
it('limits invoice user transitions to cancelled', () => {
expect(
isAllowedStatusTransition(
'draft',
'processed',
SALES_INVOICE_USER_TRANSITIONS,
),
).toBe(false);
expect(
isAllowedStatusTransition(
'draft',
'cancelled',
SALES_INVOICE_USER_TRANSITIONS,
),
).toBe(true);
});
it('allows payment pending to approved, rejected, or draft', () => {
expect(
isAllowedStatusTransition(
'draft',
'pending',
SALES_PAYMENT_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'pending',
'approved',
SALES_PAYMENT_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'draft',
'approved',
SALES_PAYMENT_USER_TRANSITIONS,
),
).toBe(false);
});
});