workOrders Core Collection (Folha de Obra) #34

Closed
opened 2025-10-19 19:03:30 +00:00 by GFMpt13 · 3 comments
GFMpt13 commented 2025-10-19 19:03:30 +00:00 (Migrated from github.com)

This is the core collection for the application, tracking the entire lifecycle of a repair job. It must support multiple functional and business requirements by aggregating data from clients, vehicles, and items.

We will use a single document per work order, embedding line items (parts and labor) for performance and atomicity.

Requirements Covered

  • RF03 (Manage work orders)
  • RF04 (Register diagnostics/quotes)
  • RF05 (Assign mechanics)
  • RF06 (Register parts and labor)
  • RB02 (One active FO per vehicle)
  • RB03 (All materials must have ref, qty, value)
  • RB06 (Client approval)

Tasks

  • Define the top-level schema (e.g., workOrderNumber, status, entryDate, completionDate).
  • Add clientId and vehicleId references to link to the other collections.
  • Design the embedded quote sub-document (for diagnostics, totals, and clientApproved status).
  • Design the items array of embedded documents for parts and labor, ensuring all required fields are present (type: 'Part'|'Labor', description, reference, quantity, unitPriceWithoutIVA, ivaRate, totalWithIVA).
  • Define the status field enum (e.g., AwaitingApproval, InProgress, AwaitingParts, Completed) to manage the workflow and trigger notifications (RB07).
  • Define how to address RB02. (Suggestion: a partial, unique index on vehicleId where status is not 'Completed' or 'Invoiced').
  • Define Timestamps:
  1. Document Management Timestamps

    • createdAt - When the WO was created
    • updatedAt - Updated on EVERY modification
  2. Workflow Timestamps

    • entryDate - Vehicle check-in
    • diagnosisRegisteredAt - Diagnosis registered
    • quoteApprovedAt - Customer approval
    • executionStartedAt - Optional, but good for measuring performance
    • completedAt - Work completed
    • notificationSentAt - Notification sent
    • deliveredAt - Vehicle delivered
  • Add mechanicsIds array to link to the user system (see Issue #37 ).
This is the core collection for the application, tracking the entire lifecycle of a repair job. It must support multiple functional and business requirements by aggregating data from clients, vehicles, and items. We will use a single document per work order, **embedding** line items (parts and labor) for performance and atomicity. ### Requirements Covered * RF03 (Manage work orders) * RF04 (Register diagnostics/quotes) * RF05 (Assign mechanics) * RF06 (Register parts and labor) * RB02 (One active FO per vehicle) * RB03 (All materials must have ref, qty, value) * RB06 (Client approval) ### Tasks - [x] Define the top-level schema (e.g., `workOrderNumber`, `status`, `entryDate`, `completionDate`). - [x] Add `clientId` and `vehicleId` references to link to the other collections. - [x] Design the embedded `quote` sub-document (for diagnostics, totals, and `clientApproved` status). - [x] Design the `items` array of embedded documents for parts and labor, ensuring all required fields are present (`type: 'Part'|'Labor'`, `description`, `reference`, `quantity`, `unitPriceWithoutIVA`, `ivaRate`, `totalWithIVA`). - [x] Define the `status` field enum (e.g., `AwaitingApproval`, `InProgress`, `AwaitingParts`, `Completed`) to manage the workflow and trigger notifications (**RB07**). - [x] Define how to address **RB02**. (Suggestion: a partial, unique index on `vehicleId` where `status` is not 'Completed' or 'Invoiced'). - [x] Define Timestamps: 1. Document Management Timestamps * `createdAt` - When the WO was created * `updatedAt` - Updated on EVERY modification 2. Workflow Timestamps * `entryDate` - Vehicle check-in * `diagnosisRegisteredAt` - Diagnosis registered * `quoteApprovedAt` - Customer approval * `executionStartedAt` - Optional, but good for measuring performance * `completedAt` - Work completed * `notificationSentAt` - Notification sent * `deliveredAt` - Vehicle delivered - [ ] Add `mechanicsIds` array to link to the user system (see Issue #37 ).
GFMpt13 commented 2025-10-23 16:22:27 +00:00 (Migrated from github.com)

The scheme is looking like this for now, we have to Define how to address RB02. And module the items array.
Image

The scheme is looking like this for now, we have to Define how to address RB02. And module the items array. ![Image](https://github.com/user-attachments/assets/58340e02-2f4f-44dd-8db9-9612b55832ec)
GFMpt13 commented 2025-10-25 19:18:36 +00:00 (Migrated from github.com)

Added the items array.
It can be "Part" or "Labor", for example:
"items": [
{
"type": "Part", // 'Part' ou 'Labor'
"description": "Amortecedor Bilstein B4",
"reference": "BLS-22-1111", // (RB03)
"quantity": Decimal128("2.0"), // (RB03)
"unitPriceWithoutIVA": Decimal128("85.00"), // (RB03, RF06)
"ivaRate": Decimal128("0.23"),
"totalPriceWithoutIVA": Decimal128("170.00"),
"totalPriceWithIVA": Decimal128("209.10") // (RF06)
},
{
"type": "Labor",
"description": "Substituição amortecedores",
"reference": "MO-005", // (RB03)
"quantity": Decimal128("1.5"), // (RB03)
"unitPriceWithoutIVA": Decimal128("50.00"), // (RB03, RF06)
"ivaRate": Decimal128("0.23"),
"totalPriceWithoutIVA": Decimal128("75.00"),
"totalPriceWithIVA": Decimal128("92.25") // (RF06)
}
],

Image

Added the items array. It can be "Part" or "Labor", for example: "items": [ { "type": "Part", // 'Part' ou 'Labor' "description": "Amortecedor Bilstein B4", "reference": "BLS-22-1111", // (RB03) "quantity": Decimal128("2.0"), // (RB03) "unitPriceWithoutIVA": Decimal128("85.00"), // (RB03, RF06) "ivaRate": Decimal128("0.23"), "totalPriceWithoutIVA": Decimal128("170.00"), "totalPriceWithIVA": Decimal128("209.10") // (RF06) }, { "type": "Labor", "description": "Substituição amortecedores", "reference": "MO-005", // (RB03) "quantity": Decimal128("1.5"), // (RB03) "unitPriceWithoutIVA": Decimal128("50.00"), // (RB03, RF06) "ivaRate": Decimal128("0.23"), "totalPriceWithoutIVA": Decimal128("75.00"), "totalPriceWithIVA": Decimal128("92.25") // (RF06) } ], ![Image](https://github.com/user-attachments/assets/e4b78bcf-1703-45ad-ae34-dfee14502e52)
GFMpt13 commented 2025-10-25 19:25:17 +00:00 (Migrated from github.com)

To address RB02 it will be necessary to create an index.

// --- Index for RB02 ---
// Ensures that a vehicle can only have ONE active worOrder.
db.workOrders.createIndex(
{ vehicleId: 1 },
{
unique: true,
partialFilterExpression: {
status: { $nin: ["Completed", "Invoiced", "Delivered"] }
}
}
);

To address RB02 it will be necessary to create an index. // --- Index for RB02 --- // Ensures that a vehicle can only have ONE active worOrder. db.workOrders.createIndex( { vehicleId: 1 }, { unique: true, partialFilterExpression: { status: { $nin: ["Completed", "Invoiced", "Delivered"] } } } );
Sign in to join this conversation.
No description provided.