diff --git a/src/Apps/W1/Quality Management/app/.github/copilot-instructions.md b/src/Apps/W1/Quality Management/app/.github/copilot-instructions.md new file mode 100644 index 0000000000..a7cd81bc46 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/.github/copilot-instructions.md @@ -0,0 +1,75 @@ +# Quality Management App — Copilot Instructions + +## What this app does + +Microsoft Business Central extension (v29.0.0.0) that integrates quality inspection +routines, test plans, and quality specifications into production, inventory, purchasing, +and warehouse workflows. Object ID range: 20400-20600. No external dependencies. + +## Project structure + +``` +app/ Main extension +test/ Test codeunits +Test Library/ Shared test utilities and data generators +``` + +## Before writing or modifying any code, read + +| What you need | File | +|---|---| +| Architecture overview | `docs/architecture.md` | +| Tables and relationships | `docs/data-model.md` | +| AL naming conventions and code patterns | `docs/conventions.md` | +| Product features and key objects | `docs/features.md` | +| Testing setup and patterns | `docs/testing.md` | + +## Working in a specific area? + +Load the relevant component docs first: + +| Area | File | +|---|---| +| Inspection document (Header/Lines, creation, status) | `src/Document/docs/CLAUDE.md` and `architecture.md` | +| Templates, generation rules, result conditions | `src/Configuration/docs/CLAUDE.md` and `architecture.md` | +| BC module integrations (Purchasing, Manufacturing, Warehouse...) | `src/Integration/docs/CLAUDE.md` | +| Post-inspection disposition actions | `src/Dispositions/docs/CLAUDE.md` | + +## Key entry points + +- **Creating an inspection:** `src/Document/QltyInspectionCreate.Codeunit.al` — `CreateInspectionWithVariant()` +- **Generation rule matching:** `src/Configuration/GenerationRule/QltyInspecGenRuleMgmt.Codeunit.al` +- **App setup/configuration:** `src/Setup/QltyManagementSetup.Table.al` +- **Disposition interface:** `src/Dispositions/QltyDisposition.Interface.al` + +## Context loading — read these before making changes + +When working in a specific area, reference the component docs first: + +| Working in... | Read first | +|---|---| +| `src/Document/` | `#file:src/Document/docs/CLAUDE.md` + `#file:src/Document/docs/architecture.md` | +| `src/Configuration/` | `#file:src/Configuration/docs/CLAUDE.md` + `#file:src/Configuration/docs/architecture.md` | +| `src/Integration/` | `#file:src/Integration/docs/CLAUDE.md` | +| `src/Dispositions/` | `#file:src/Dispositions/docs/CLAUDE.md` | +| Any area | `#file:docs/architecture.md` + `#file:docs/conventions.md` | + +Always reference `#file:docs/data-model.md` when modifying or adding tables. + +## How to reference docs in Copilot Chat + +``` +#file:docs/architecture.md how does inspection creation work? +#file:src/Document/docs/architecture.md explain the re-inspection chain +#file:docs/conventions.md what naming convention should I use for this codeunit? +``` + +## Dev workflow (compile → publish → test) + +Always compile and publish both the app and test app before running tests. +See `Eng/Docs/al-workflow.md` and `Eng/Docs/al-testing.md` at the repo root. + +```powershell +# Run all Quality Management tests +.\Eng\Core\Scripts\RunALTestFromEnlistment.ps1 -ApplicationName "Quality Management Tests" -CountryCode W1 +``` diff --git a/src/Apps/W1/Quality Management/app/CLAUDE.md b/src/Apps/W1/Quality Management/app/CLAUDE.md new file mode 100644 index 0000000000..29210d85c3 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/CLAUDE.md @@ -0,0 +1,83 @@ +# Quality Management App - AI Context + +## Overview + +Microsoft Business Central extension (v29.0.0.0) that integrates quality inspection routines, test plans, and quality specifications into production, inventory, and purchasing workflows. + +- **Publisher:** Microsoft +- **App ID:** bc7b3891-f61b-4883-bbb3-384cdef88bec +- **Object ID Range:** 20400-20600 +- **Namespace root:** `Microsoft.QualityManagement.*` +- **No external dependencies** (platform + application base only) + +## Quick Navigation + +| What you need | Where to look | +|---|---| +| Architecture overview | `docs/architecture.md` | +| Data model (tables) | `docs/data-model.md` | +| AL coding conventions | `docs/conventions.md` | +| Product features | `docs/features.md` | +| Testing strategy | `docs/testing.md` | +| Inspection document logic | `src/Document/docs/` | +| Templates & generation rules | `src/Configuration/docs/` | +| BC module integration | `src/Integration/docs/` | +| Disposition actions | `src/Dispositions/docs/` | + +## Source Structure + +``` +src/ +├── AccessControl/ # Permission management codeunit +├── API/ # REST API pages for inspection creation/query +├── Configuration/ # Templates, generation rules, results, source config +│ ├── GenerationRule/ # When to trigger inspections (rules + scheduling) +│ ├── Result/ # Result conditions and evaluation logic +│ ├── SourceConfiguration/ # Table-to-inspection field mapping +│ └── Template/ # Inspection templates and test definitions +├── Dispositions/ # Post-inspection actions (transfer, put-away, adjust, etc.) +├── Document/ # Core inspection document (header + lines) +├── Installation/ # Install codeunit and upgrade logic +├── Integration/ # Hooks into Assembly, Manufacturing, Purchasing, Transfers, Warehouse +├── Permissions/ # Permission sets +├── Reports/ # Certificate of Analysis, Non-Conformance, General Purpose +├── RoleCenters/ # Quality Manager role center and cues +├── Setup/ # QltyManagementSetup + guided/manual setup pages +├── Utilities/ # Parsing, expressions, notifications, helpers +└── Workflow/ # Approval workflow setup and responses +``` + +## Core Workflow + +``` +Generation Rule (trigger condition) + → matches source record + → QltyInspectionCreate codeunit + → Inspection Header + Lines (from Template) + → Inspector fills in results + → Finish inspection + → Disposition action (optional post-processing) +``` + +## Context Loading Instructions + +When working in a specific area, read the corresponding component docs **before** making changes: + +| Working in... | Read first | +|---|---| +| `src/Document/` | `src/Document/docs/CLAUDE.md` + `src/Document/docs/architecture.md` | +| `src/Configuration/` | `src/Configuration/docs/CLAUDE.md` + `src/Configuration/docs/architecture.md` | +| `src/Integration/` | `src/Integration/docs/CLAUDE.md` | +| `src/Dispositions/` | `src/Dispositions/docs/CLAUDE.md` | +| Any area | `docs/architecture.md` + `docs/conventions.md` | + +Always read `docs/data-model.md` when modifying or adding tables. + +## Development Environment + +- **CountryCode:** W1 (world-wide) +- **Symbol packages:** `Run/W1/AllExtensions/` +- **Build & publish:** See `Eng/Docs/al-workflow.md` +- **Run tests:** `Eng/Core/Scripts/RunALTestFromEnlistment.ps1` +- **Test app:** `src/Apps/W1/Quality Management/test/` +- **Test library:** `src/Apps/W1/Quality Management/Test Library/` diff --git a/src/Apps/W1/Quality Management/app/docs/CLAUDE.md b/src/Apps/W1/Quality Management/app/docs/CLAUDE.md new file mode 100644 index 0000000000..99d4593b5f --- /dev/null +++ b/src/Apps/W1/Quality Management/app/docs/CLAUDE.md @@ -0,0 +1,41 @@ +# Quality Management - Docs Index + +Project-wide documentation for the Quality Management app. + +## Files in This Directory + +| File | Contents | +|---|---| +| `architecture.md` | System architecture, layer breakdown, design patterns, component relationships | +| `data-model.md` | All tables, table extensions, enums, and their relationships | +| `conventions.md` | AL naming conventions, namespace mapping, code patterns to follow | +| `features.md` | Product features overview — what users can do and which objects implement each feature | +| `testing.md` | Testing setup, test project structure, how to run tests, patterns for new tests | + +## Component Documentation + +Each major source module has its own `docs/` folder: + +| Module | Docs location | What it covers | +|---|---|---| +| Inspection Document | `src/Document/docs/` | Header/Line tables, creation codeunit, status lifecycle | +| Configuration | `src/Configuration/docs/` | Templates, generation rules, source config, result conditions | +| Integration | `src/Integration/docs/` | BC module hooks (Purchasing, Manufacturing, Assembly, Warehouse, Transfers) | +| Dispositions | `src/Dispositions/docs/` | Post-inspection inventory actions, interface pattern | + +## Quick Answers + +**Where is the inspection creation entry point?** +`src/Document/QltyInspectionCreate.Codeunit.al` — `CreateInspectionWithVariant()` + +**Where are generation rules evaluated?** +`src/Configuration/GenerationRule/QltyInspecGenRuleMgmt.Codeunit.al` + +**Where is the app setup (number series, defaults)?** +`src/Setup/QltyManagementSetup.Table.al` + `QltyManagementSetup.Page.al` + +**How do I add a new integration trigger?** +See `src/Integration/docs/architecture.md` + +**How do I add a new disposition action?** +See `src/Dispositions/docs/architecture.md` diff --git a/src/Apps/W1/Quality Management/app/docs/architecture.md b/src/Apps/W1/Quality Management/app/docs/architecture.md new file mode 100644 index 0000000000..7166a5d43d --- /dev/null +++ b/src/Apps/W1/Quality Management/app/docs/architecture.md @@ -0,0 +1,124 @@ +# Quality Management - Architecture + +## Architectural Overview + +The Quality Management app follows a **configuration-driven inspection** architecture. Instead of hard-coding when and how inspections occur, all behavior is data-driven through three layers of configuration: + +``` +[Source Configuration] What tables/fields map into inspections + ↓ +[Inspection Template] What questions/tests to ask + ↓ +[Generation Rule] When to trigger inspection creation +``` + +At runtime, `QltyInspectionCreate` (codeunit 20404) ties these together: given a source record, it finds matching generation rules, selects the right template, and creates a structured inspection document. + +## Layer Breakdown + +### 1. Configuration Layer (`src/Configuration/`) + +**Inspection Templates** (`Configuration/Template/`) +- `Qlty. Inspection Template Hdr.` (table) - Template header with code, description, sampling settings +- `Qlty. Inspection Template Line` (table) - Individual test/question lines within a template +- `Qlty. Test` (table) - Reusable test definitions (value type, lookup values, case sensitivity) +- `Qlty. Test Lookup Value` (table) - Allowed values for lookup-type tests + +**Generation Rules** (`Configuration/GenerationRule/`) +- `Qlty. Inspection Gen. Rule` (table 20404) - Defines trigger conditions: source table, filter criteria, template to use, sort order for matching priority +- `Qlty. Inspec. Gen. Rule Mgmt.` (codeunit) - Evaluates rules against source records +- `Qlty. Job Queue Management` (codeunit) - Handles scheduled (non-event-triggered) inspection creation via job queue +- Trigger enums per module: `QltyPurchaseOrderTrigger`, `QltyTransferOrderTrigger`, `QltyAssemblyTrigger`, `QltyProductionOrderTrigger`, `QltyWhseReceiptTrigger`, `QltyWarehouseTrigger` + +**Source Configuration** (`Configuration/SourceConfiguration/`) +- `Qlty. Inspect. Source Config.` (table) - Maps a source table to inspection fields (item no., quantity, lot, location, etc.) +- `Qlty. Inspect. Src. Fld. Conf.` (table) - Per-field mapping configuration +- `Qlty. Traversal` (codeunit) - Navigates complex record relationships to extract source field values + +**Result Configuration** (`Configuration/Result/`) +- `Qlty. Inspection Result` (table) - Defines named result options for template lines +- `Qlty. I. Result Condit. Conf.` (table) - Conditional configuration based on result values (auto-disposition, failure states, item tracking block) +- `Qlty. Result Condition Mgmt.` (codeunit) - Evaluates result conditions +- `Qlty. Result Evaluation` (codeunit) - Determines pass/fail based on line results + +### 2. Document Layer (`src/Document/`) + +**Core tables:** +- `Qlty. Inspection Header` (table 20405) - One per inspection. Tracks: no., template, status, source quantity, item/lot/location, re-inspection chain +- `Qlty. Inspection Line` (table 20406) - One per template line. Tracks: test result, failure state, visibility, finish-allowed flags + +**Status lifecycle:** +``` +Open → (Inspector fills lines) → Finished + ↑ ↓ + └─── Re-open ←──────────────┘ +``` +Re-inspections create new Header records linked via `Re-inspection No.` counter and `Most Recent Re-inspection` flag. + +**Creation:** +- `Qlty. Inspection - Create` (codeunit 20404) - Main entry point. `CreateInspectionWithVariant()` accepts any Record/RecordRef/RecordId. Matches generation rules, resolves template, maps source fields. +- `Qlty. Create Inspection` (report) - Batch creation from source records +- `Qlty. Schedule Inspection` (report) - Job-queue triggered creation + +**Navigation:** +- `Qlty. Document Navigation` (codeunit) - Handles navigation between inspection and source document + +### 3. Integration Layer (`src/Integration/`) + +Each integration sub-module subscribes to events from the corresponding BC module and calls `QltyInspectionCreate` when trigger conditions are met. + +| Sub-module | Integrated BC Areas | +|---|---| +| `Integration/Receiving/` | Purchase Orders, Sales Returns, Warehouse Receipts | +| `Integration/Manufacturing/` | Production Orders (output + routing), Consumption Journal | +| `Integration/Assembly/` | Assembly Orders | +| `Integration/Inventory/` | Item tracking (lot/serial/package), transfers, item availability | +| `Integration/Warehouse/` | Warehouse entries, receipts | +| `Integration/Foundation/` | Attachments (photos), Navigate integration | + +**Pattern:** Each integration codeunit (e.g. `QltyReceivingIntegration`) subscribes to `OnAfterPost` / `OnBeforePost` events in the base app and calls into `QltyInspectionCreate`. Table extensions add inspection-related fields (e.g. `QltyTransferHeader.TableExt.al` adds inspection status to transfer orders). + +### 4. Dispositions Layer (`src/Dispositions/`) + +After finishing an inspection, dispositions define what action to take on the inspected inventory. Each disposition implements the `IQltyDisposition` interface. + +| Disposition | Action | +|---|---| +| `QltyDispTransfer` | Create transfer order to move inventory | +| `QltyDispWarehousePutAway` | Create warehouse put-away | +| `QltyDispInternalPutAway` | Create internal put-away | +| `QltyDispPurchaseReturn` | Create purchase return order | +| `QltyDispNegAdjustInv` | Post negative inventory adjustment | +| `QltyDispChangeTracking` | Change item tracking (lot/serial/package) | +| `QltyDispMoveItemReclass` | Move via item reclassification journal | +| `QltyDispMoveWhseReclass` | Move via warehouse reclassification | +| `QltyDispMoveWorksheet` | Move via movement worksheet | +| `QltyDispInternalMove` | Internal move | + +`QltyDispositionBuffer` (table) holds the working data during disposition processing. + +### 5. Workflow Layer (`src/Workflow/`) + +Optional approval workflow integration using BC's standard workflow engine: +- `QltyWorkflowSetup` - Registers workflow events and responses +- `QltyWorkflowApprovals` - Handles approval request logic +- `QltyWorkflowResponse` - Implements workflow response actions +- `QltyStartWorkflow` - Triggers workflow from inspection actions + +### 6. Setup (`src/Setup/`) + +- `Qlty. Management Setup` (singleton table) - App-wide settings: number series, default behaviors for item tracking, inspection creation options, add-picture handling, update-source behavior +- `QltyManagementSetupGuide` - Assisted setup wizard +- `QltyDemoDataMgmt` - Demo data provisioning + +## Key Design Patterns + +**Interface-based Dispositions:** All disposition actions implement `IQltyDisposition` interface, making it easy to add new disposition types without changing core logic. + +**Variant-based Inspection Creation:** `CreateInspectionWithVariant()` accepts `Variant` (Record/RecordRef/RecordId), decoupling integrations from specific table types. + +**Event-driven Integration:** All BC module integrations use event subscribers rather than direct calls, keeping the base app unmodified. + +**Rule Priority + Sort Order:** Multiple generation rules can match a source record; the one with the lowest Sort Order wins. This enables complex conditional logic without code. + +**Re-inspection Chain:** A re-inspection is a new Header record with the same base `No.` but incremented `Re-inspection No.`. The `Most Recent Re-inspection` flag on the latest record simplifies filtering. diff --git a/src/Apps/W1/Quality Management/app/docs/conventions.md b/src/Apps/W1/Quality Management/app/docs/conventions.md new file mode 100644 index 0000000000..f00e0184ae --- /dev/null +++ b/src/Apps/W1/Quality Management/app/docs/conventions.md @@ -0,0 +1,129 @@ +# Quality Management - Conventions + +## Naming Conventions + +### AL Objects + +| Type | Pattern | Example | +|---|---|---| +| Tables | `Qlty. ` | `Qlty. Inspection Header` | +| Table Extensions | `Qlty` (PascalCase file) | `QltyTransferHeader.TableExt.al` | +| Pages | `Qlty. ` | `Qlty. Inspection List` | +| Page Extensions | File: `Qlty.PageExt.al` | `QltyItemCard.PageExt.al` | +| Codeunits | `Qlty. ` | `Qlty. Inspection - Create` | +| Reports | `Qlty. ` | `Qlty. Create Inspection` | +| Enums | `Qlty. ` | `Qlty. Inspection Status` | +| Enum Extensions | `Qlty.EnumExt.al` | `QltyApprovalDocumentType.EnumExt.al` | +| Interfaces | `IQlty` | `IQltyDisposition` | +| Permission Sets | `QltyMngmnt` | `QltyMngmntEdit` | + +### File Names + +File names use PascalCase without spaces and match the object name: +- `QltyInspectionHeader.Table.al` +- `QltyInspectionCreate.Codeunit.al` +- `QltyInspectionStatus.Enum.al` + +### Namespaces + +Namespace mirrors the folder structure under `src/`: + +``` +Microsoft.QualityManagement.Document +Microsoft.QualityManagement.Configuration.GenerationRule +Microsoft.QualityManagement.Configuration.GenerationRule.JobQueue +Microsoft.QualityManagement.Configuration.Template +Microsoft.QualityManagement.Configuration.Template.Test +Microsoft.QualityManagement.Configuration.SourceConfiguration +Microsoft.QualityManagement.Configuration.Result +Microsoft.QualityManagement.Integration.Assembly +Microsoft.QualityManagement.Integration.Inventory +Microsoft.QualityManagement.Integration.Inventory.Transfer +Microsoft.QualityManagement.Integration.Manufacturing +Microsoft.QualityManagement.Integration.Receiving +Microsoft.QualityManagement.Integration.Warehouse +Microsoft.QualityManagement.Integration.Foundation.Attachment +Microsoft.QualityManagement.Integration.Foundation.Navigate +Microsoft.QualityManagement.Integration.Utilities +Microsoft.QualityManagement.Dispositions (implied) +Microsoft.QualityManagement.Workflow +Microsoft.QualityManagement.Setup +Microsoft.QualityManagement.Utilities +Microsoft.QualityManagement.AccessControl +Microsoft.QualityManagement.Reports +Microsoft.QualityManagement.RoleCenters +Microsoft.QualityManagement.Permissions +Microsoft.QualityManagement.API +``` + +## Object ID Ranges + +All objects use IDs within **20400-20600**. + +Known assignments (from code): +- 20404: `Qlty. Inspection Gen. Rule` (table) + `Qlty. Inspection - Create` (codeunit) +- 20405: `Qlty. Inspection Header` (table) +- 20406: `Qlty. Inspection Line` (table) + +When adding new objects, check existing IDs first using Grep and pick the next available in range. + +## AL Code Patterns + +### `NoImplicitWith` Feature Flag + +The app uses `"NoImplicitWith"` — always qualify record field access explicitly: +```al +// Correct +InspectionHeader."No." := ... +InspectionHeader.Status := InspectionHeader.Status::Finished; + +// Wrong (implicit with) +"No." := ... +``` + +### Access Modifiers + +- Use `internal` for procedures not part of the public API surface +- Use `local` for procedures only used within the codeunit +- Public procedures should have XML doc comments (`/// `) + +### Event Subscribers for Integration + +Integration codeunits use `[EventSubscriber]` to hook into base app events. Do not call integration codeunits directly from document code — always go through events: + +```al +[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purchase Post", 'OnAfterPostPurchaseDoc', '', false, false)] +local procedure OnAfterPostPurchaseDoc(...) +begin + QltyInspectionCreate.CreateInspectionWithVariant(PurchaseHeader, false); +end; +``` + +### Inspection Creation Entry Points + +Always use `QltyInspectionCreate` codeunit. The main entry points are: +- `CreateInspectionWithVariant(Variant, IsManualCreation)` - rule-based template selection +- `CreateInspectionWithVariantAndTemplate(Variant, IsManualCreation, TemplateCode)` - explicit template + +The codeunit has `EventSubscriberInstance = Manual`, so instantiate it when needed. + +### Interface Pattern for Dispositions + +New disposition actions must implement `IQltyDisposition` interface. Register the enum value in `QltyDispositionAction` enum and map it to the interface implementation. + +### Permissions Pattern + +The app uses explicit `Permissions = tabledata ... = RIM` declarations on codeunits that write data, rather than relying on blanket permission sets. Follow this pattern for any new codeunit that modifies data. + +### Translation + +The app uses `"TranslationFile"` feature — all user-facing strings must use `Label` declarations. Do not use string literals for UI text. + +## Testing Conventions + +See `docs/testing.md` for the full testing approach. + +- Test codeunits live in `test/src/` +- Test Library helpers live in `Test Library/src/` +- All tests use the `QltyInspectionUtility` helper from the Test Library +- Unit tests should be tagged with `[Test]` and grouped by codeunit/feature diff --git a/src/Apps/W1/Quality Management/app/docs/data-model.md b/src/Apps/W1/Quality Management/app/docs/data-model.md new file mode 100644 index 0000000000..3f66990d3d --- /dev/null +++ b/src/Apps/W1/Quality Management/app/docs/data-model.md @@ -0,0 +1,140 @@ +# Quality Management - Data Model + +## Core Tables + +### Inspection Document + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Inspection Header` | 20405 | One record per inspection. Tracks source document, item, lot, location, status, re-inspection chain. | +| `Qlty. Inspection Line` | 20406 | One record per template line (test/question). Stores result value, failure state, visibility. | + +**Key relationships:** +``` +Qlty. Inspection Header (No., Re-inspection No.) + └── Qlty. Inspection Line (Inspection No., Re-inspection No., Line No.) + └── Qlty. Inspection Template Line (via Template Code + Template Line No.) + └── Qlty. Test (via Test Code on template line) +``` + +**Re-inspection chain:** +- Same `No.` across re-inspections +- `Re-inspection No.` increments (0 = original, 1 = first re-inspection, ...) +- `Most Recent Re-inspection = true` on the latest record only + +**Status enum (`Qlty. Inspection Status`):** Open, Finished + +### Configuration: Templates + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Inspection Template Hdr.` | ~20407 | Template header: code, description, sample size source, copy behavior | +| `Qlty. Inspection Template Line` | ~20408 | Template lines: test code, result options, visibility rules, finish-allowed rules | +| `Qlty. Test` | ~20409 | Reusable test definition: value type (numeric/text/boolean/lookup), case sensitivity | +| `Qlty. Test Lookup Value` | ~20410 | Valid lookup values for a test | + +**Key relationships:** +``` +Qlty. Inspection Template Hdr. (Code) + └── Qlty. Inspection Template Line (Template Code, Line No.) + └── Qlty. Test (Test Code) + └── Qlty. Test Lookup Value (Test Code, Line No.) +``` + +### Configuration: Generation Rules + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Inspection Gen. Rule` | 20404 | Rule: source table, trigger type, filter expression, template code, sort order, schedule group | + +**Rule matching:** Multiple rules can exist per source table. `Sort Order` determines priority (lower = evaluated first). First matching rule wins. + +**Schedule Group:** Links rules to job queue entries for time-based (non-event) inspection creation. + +### Configuration: Source Configuration + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Inspect. Source Config.` | ~20411 | Maps a source table to which fields to populate on the inspection (item no., quantity, lot, location, etc.) | +| `Qlty. Inspect. Src. Fld. Conf.` | ~20412 | Per-field mapping: source field → inspection header field | + +### Configuration: Results + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Inspection Result` | ~20413 | Named result options (e.g. "Pass", "Fail", "N/A") | +| `Qlty. I. Result Condit. Conf.` | ~20414 | Conditional behavior when a result is selected: auto-disposition, failure state, item tracking block | + +### Setup + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Management Setup` | ~20415 | Singleton. Number series, default behaviors, feature toggles | +| `Qlty. Management Role Center Cue` | ~20416 | Cue counts for role center activities page | + +### Dispositions + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Disposition Buffer` | ~20417 | Temporary working record during disposition processing | +| `Qlty. Related Transfers Buffer` | ~20418 | Temporary buffer for related transfer order lookups | + +### Workflow + +| Table | ID | Purpose | +|---|---|---| +| `Qlty. Workflow Config. Value` | ~20419 | Configuration values for workflow responses | + +## Table Extensions + +These extend existing BC tables with Quality Management fields: + +| Extension | Extended Table | Added Fields | +|---|---|---| +| `QltyApplicationAreaSetup.TableExt` | Application Area Setup | Quality Management application area flag | +| `QltyTransferHeader.TableExt` | Transfer Header | Inspection status, inspection no. | +| `QltyDirectTransHeader.TableExt` | Direct Trans. Header | Posted transfer inspection link | +| `QltyTransferReceiptHeader.TableExt` | Transfer Receipt Header | Inspection link | +| `QltyTransferShipmentHeader.TableExt` | Transfer Shipment Header | Inspection link | +| `QltyLotNoInformation.TableExt` | Lot No. Information | Inspection count/link | +| `QltySerialNoInformation.TableExt` | Serial No. Information | Inspection link | +| `QltyPackageNoInformation.TableExt` | Package No. Information | Inspection link | +| `QltyAvailInfoBuffer.TableExt` | Availability Info. Buffer | Quality hold flag | +| `QltyEntrySummary.TableExt` | Entry Summary | Quality hold quantities | +| `QltyRelatedTransfersBuffer.Table` | (new buffer) | Transfer documents related to an inspection | + +## Key Enums + +### Document +- `Qlty. Inspection Status`: Open, Finished +- `Qlty. Inspection Create Status`: Created, AlreadyExists, NoMatchingRules, Error +- `Qlty. Line Failure State`: (none), Failed, FailedWithComment + +### Configuration +- `Qlty. Gen. Rule Intent`: Manual, Automatic, Scheduled +- `Qlty. Gen. Rule Act. Trigger`: (per-module trigger points) +- `Qlty. Test Value Type`: Numeric, Text, Boolean, Lookup, LargeText +- `Qlty. Result Category`: Pass, Fail, Inconclusive, NotApplicable +- `Qlty. Result Visibility`: Always, OnlyWhenSelected, Never +- `Qlty. Result Finish Allowed`: Always, OnlyWhenSelected, Never +- `Qlty. Insp. Selection Criteria`: Item, ItemVariant, ItemTracking + +### Integration Triggers (one enum per integrated module) +- `Qlty. Purchase Order Trigger`: OnRelease, OnPost, OnReceive, ... +- `Qlty. Transfer Order Trigger`: OnShip, OnReceive, ... +- `Qlty. Assembly Trigger`: OnPost, ... +- `Qlty. Production Order Trigger`: OnOutput, OnConsumption, ... +- `Qlty. Whse. Receipt Trigger`: OnPost, ... +- `Qlty. Warehouse Trigger`: OnPost, ... +- `Qlty. Sales Return Trigger`: OnPost, ... + +### Dispositions +- `Qlty. Disposition Action`: Transfer, WarehousePutAway, InternalPutAway, PurchaseReturn, NegativeAdjustment, ChangeTracking, Move, InternalMove +- `Qlty. Item Adj. Post Behavior`: PostImmediately, CreateDraft +- `Qlty. Quantity Behavior`: FullQuantity, SampleQuantity, UserDefined + +### Setup +- `Qlty. Item Tracking Behavior`: None, BlockOnFail, AlwaysBlock +- `Qlty. Update Source Behavior`: Never, OnFinish, AlwaysPrompt +- `Qlty. Inspect. Creation Option`: Automatic, Manual, Both +- `Qlty. Add Picture Handling`: None, Prompt, Automatic diff --git a/src/Apps/W1/Quality Management/app/docs/features.md b/src/Apps/W1/Quality Management/app/docs/features.md new file mode 100644 index 0000000000..3d3def28c3 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/docs/features.md @@ -0,0 +1,137 @@ +# Quality Management - Product Features + +## Feature Overview + +Quality Management enables systematic quality control by allowing companies to define what to inspect, when to inspect, and what to do with inspected inventory. + +## Feature 1: Inspection Template Management + +**What users do:** Create and maintain reusable inspection templates that define the structure of a quality inspection — what questions to ask, what tests to run, and what results are acceptable. + +**Key objects:** +- Page: `Qlty. Inspection Template List` → `Qlty. Inspection Template Edit` +- Tables: `Qlty. Inspection Template Hdr.`, `Qlty. Inspection Template Line`, `Qlty. Test`, `Qlty. Test Lookup Value` + +**Capabilities:** +- Define named tests with value types (numeric measurement, text, boolean pass/fail, lookup from list) +- Configure result options per template line (Pass/Fail/N/A with conditional behaviors) +- Set visibility and finish-allowed rules per result value +- Copy templates with `Qlty. Inspection - Copy Template` report +- Configure sample size source (fixed count, percentage of source quantity, etc.) + +## Feature 2: Inspection Generation Rules + +**What users do:** Configure when inspections should be automatically or manually triggered for specific source documents/records, and which template to use. + +**Key objects:** +- Page: `Qlty. Inspection Gen. Rules` +- Table: `Qlty. Inspection Gen. Rule` +- Codeunit: `Qlty. Inspec. Gen. Rule Mgmt.` + +**Capabilities:** +- Map source tables (Purchase Order, Transfer Order, Production Output, etc.) to templates +- Set filter criteria (by item, vendor, location, etc.) for rule matching +- Define trigger point (on release, on post, on receive, scheduled) +- Schedule inspections via job queue using `Schedule Group` +- Priority ordering via `Sort Order` +- Guided setup pages per module: `QltyRecGenRuleSGuide`, `QltyProdGenRuleSGuide`, `QltyAsmGenRuleSGuide`, `QltyWhseGenRuleSGuide` + +## Feature 3: Quality Inspection Processing + +**What users do:** Open, fill in, and finish quality inspections. Record measurements and test results against each template line. + +**Key objects:** +- Page: `Qlty. Inspection` (card) + `Qlty. Inspection List` +- Tables: `Qlty. Inspection Header`, `Qlty. Inspection Line` +- Codeunit: `Qlty. Inspection - Create` + +**Capabilities:** +- Create inspections manually or automatically from source documents +- Fill in test results on each inspection line +- Attach photos/documents via attachment integration +- Navigate back to source document +- Finish or re-open inspections +- Re-inspect: create follow-up inspection in a chain (linked by `Re-inspection No.`) +- View inspection status directly on source documents (transfer orders, lot/serial/package info cards) + +## Feature 4: Source Configuration + +**What users do:** Configure which fields from source tables (Purchase Line, Transfer Line, etc.) automatically populate inspection header fields (item no., quantity, location, lot, etc.). + +**Key objects:** +- Page: `Qlty. Inspect. Source Config.`, `Qlty. Ins. Source Config. List` +- Tables: `Qlty. Inspect. Source Config.`, `Qlty. Inspect. Src. Fld. Conf.` +- Codeunit: `Qlty. Traversal` + +**Capabilities:** +- Map any BC table's fields to inspection header fields +- Handle complex document/line relationships via traversal logic +- Auto-configure common source tables with `QltyAutoConfigure` codeunit + +## Feature 5: Disposition Actions + +**What users do:** After finishing an inspection (especially a failed one), take action on the inspected inventory. + +**Key objects:** +- Interface: `IQltyDisposition` +- Pages: Triggered from inspection card +- Reports: `QltyCreateTransferOrder`, `QltyCreatePurchaseReturn`, `QltyCreateNegativeAdjmt`, `QltyMoveInventory`, `QltyCreateInternalPutaway`, `QltyChangeItemTracking` + +**Available dispositions:** +- Transfer inventory to another location/bin +- Create warehouse or internal put-away +- Create purchase return order +- Post negative inventory adjustment +- Change item tracking (lot/serial/package reassignment) +- Move via reclassification journal or movement worksheet + +## Feature 6: Item Tracking Integration + +**What users do:** Inspect inventory tracked by lot, serial, or package numbers. Block or unblock item tracking entries based on inspection results. + +**Key objects:** +- Codeunit: `Qlty. Item Tracking Mgmt.`, `Qlty. Tracking Integration` +- Table extensions: `QltyLotNoInformation`, `QltySerialNoInformation`, `QltyPackageNoInformation` +- Page extensions: Lot/Serial/Package info cards and lists + +**Capabilities:** +- View inspection history from lot/serial/package info pages +- Automatically block item tracking entries when inspection fails (configurable in Setup) +- Unblock on re-inspection pass + +## Feature 7: Workflow Approvals + +**What users do:** Route inspections through an approval process before they can be finished. + +**Key objects:** +- Codeunit: `Qlty. Workflow Setup`, `Qlty. Workflow Approvals`, `Qlty. Workflow Response` +- Page extension: `QltyWorkflowRespOptions` + +**Capabilities:** +- Register quality inspection as a workflow-enabled document +- Set up approval chains using standard BC workflow engine +- Configure approval responses (approve, reject, delegate) + +## Feature 8: Reporting + +**Key reports:** +- `Qlty. Certificate of Analysis` - Formal inspection certificate (2 RDLC layouts: Default, Alternate) +- `Qlty. Non-Conformance` - Non-conformance report for failed inspections (2 RDLC layouts) +- `Qlty. General Purpose Inspection` - General inspection output (2 RDLC layouts) +- `Qlty. Create Inspection` - Batch create inspections from source records +- `Qlty. Schedule Inspection` - Job-queue triggered inspection creation + +## Feature 9: API + +**Key objects:** +- `Qlty. Inspections API` (page) - Query existing inspections +- `Qlty. Create Inspection API` (page) - Create inspections via API + +## Feature 10: Quality Manager Role Center + +**Key objects:** +- Profile: `Qlty. Manager` +- Page: `Qlty. Manager Role Center` + `Qlty. Inspection Activities` (cue group) +- Table: `Qlty. Management Role Center Cue` + +Shows open/overdue/finished inspection counts and quick navigation to key lists. diff --git a/src/Apps/W1/Quality Management/app/docs/testing.md b/src/Apps/W1/Quality Management/app/docs/testing.md new file mode 100644 index 0000000000..7309a8f09d --- /dev/null +++ b/src/Apps/W1/Quality Management/app/docs/testing.md @@ -0,0 +1,99 @@ +# Quality Management - Testing + +## Test Projects + +| Project | Path | Purpose | +|---|---|---| +| Test app | `test/` | Functional and unit tests | +| Test Library | `Test Library/` | Shared test utilities and data generators | + +The Test Library app (`Quality Management Test Library`) is declared in `app.json` under `internalsVisibleTo`, giving it access to internal procedures. + +## Running Tests + +Use `Eng/Core/Scripts/RunALTestFromEnlistment.ps1`: + +```powershell +# All Quality Management tests +.\RunALTestFromEnlistment.ps1 -ApplicationName "Quality Management Tests" -CountryCode W1 + +# Specific test codeunit +.\RunALTestFromEnlistment.ps1 -ApplicationName "Quality Management Tests" -CountryCode W1 -TestCodeunitId + +# Single test method +.\RunALTestFromEnlistment.ps1 -ApplicationName "Quality Management Tests" -CountryCode W1 -TestProcedureRange "" + +# Unit tests only +.\RunALTestFromEnlistment.ps1 -ApplicationName "Quality Management Tests" -CountryCode W1 -TestType UnitTest +``` + +**Always compile and publish both the app and test app before running tests.** See `Eng/Docs/al-workflow.md`. + +## Test Structure + +### Known Test Codeunits (`test/src/`) + +| File | Focus Area | +|---|---| +| `QltyTestsInsepctions.Codeunit.al` | Inspection creation, status transitions, re-inspection | +| `QltyTestsTraversal.Codeunit.al` | Source field traversal and mapping | +| `QltyTestsExpressions.Codeunit.al` | Expression evaluation in generation rules | +| `QltyTestProdOrderRouting.PageExt.al` | Production order routing integration | + +### Test Library (`Test Library/src/`) + +Provides shared generators and utility codeunits: + +| Codeunit | Purpose | +|---|---| +| `QltyProdOrderGenerator` | Creates production orders for test setup | +| `QltyPurOrderGenerator` | Creates purchase orders for test setup | +| `QltyInspectionUtility` (implied) | Common inspection creation/assertion helpers | + +## Testing Patterns + +### Use Test Library Utilities + +All tests should use `QltyInspectionUtility` from the Test Library for creating test inspections, rather than calling `QltyInspectionCreate` directly in every test. This ensures consistent setup and reduces duplication. + +### Test Data Setup + +Follow the standard BC test pattern: +1. Use `LibraryInventory`, `LibraryPurchase`, etc. for base BC test data +2. Use Quality Management Test Library utilities for QM-specific setup +3. Each test should be self-contained (create its own data, don't rely on existing demo data) + +### Test Method Naming + +```al +[Test] +procedure __() +``` + +Example: `CreateInspection_WithMatchingGenerationRule_CreatesInspectionDocument()` + +### Snapshot Tests + +The `.snapshots/` folder at the app root stores UI snapshot test baselines. Update snapshots when intentional UI changes are made. + +## What to Test When Adding Features + +When adding a new **disposition action:** +- Test that the disposition creates the correct BC document/journal +- Test quantity handling (full, sample, user-defined) +- Test failure cases (missing setup, insufficient inventory) + +When adding a new **integration trigger:** +- Test that the correct generation rule is matched +- Test that inspection is created with correct source fields populated +- Test that the trigger does NOT fire when no matching rule exists + +When adding **template/test features:** +- Test result evaluation (pass/fail/inconclusive logic) +- Test conditional configuration (result conditions triggering disposition or item tracking block) +- Test copy template behavior + +When modifying **inspection creation logic:** +- Test `CreateInspectionWithVariant` with Record, RecordRef, and RecordId variants +- Test re-inspection chain creation +- Test all `QltyInspectionCreateStatus` return values diff --git a/src/Apps/W1/Quality Management/app/src/Configuration/docs/CLAUDE.md b/src/Apps/W1/Quality Management/app/src/Configuration/docs/CLAUDE.md new file mode 100644 index 0000000000..916c1a611e --- /dev/null +++ b/src/Apps/W1/Quality Management/app/src/Configuration/docs/CLAUDE.md @@ -0,0 +1,32 @@ +# Configuration Module - AI Context + +The Configuration module defines the **data-driven rules** that control what inspections look like and when they're created. + +## Sub-modules + +``` +Configuration/ +├── GenerationRule/ When to create inspections (trigger conditions, templates, scheduling) +│ └── JobQueue/ Scheduled inspection creation via job queue +├── Template/ What to ask (inspection structure, test definitions) +│ └── Test/ Test definitions and lookup values +├── SourceConfiguration/ How to populate inspection from source record fields +└── Result/ What result options exist and what happens when selected +``` + +## Quick Reference + +| Task | File | +|---|---| +| Add/modify when inspections trigger | `GenerationRule/QltyInspectionGenRule.Table.al` + `QltyInspecGenRuleMgmt.Codeunit.al` | +| Add/modify inspection template structure | `Template/QltyInspectionTemplateHdr.Table.al` + `QltyInspectionTemplateLine.Table.al` | +| Add test definitions | `Template/Test/QltyTest.Table.al` | +| Map source fields to inspection header | `SourceConfiguration/QltyInspectSourceConfig.Table.al` + `QltyTraversal.Codeunit.al` | +| Configure result behaviors | `Result/QltyInspectionResult.Table.al` + `QltyIResultConditConf.Table.al` | +| Schedule inspections | `GenerationRule/JobQueue/QltyJobQueueManagement.Codeunit.al` | +| Auto-configure common sources | `QltyAutoConfigure.Codeunit.al` | + +## Relevant Docs +- `docs/architecture.md` - How configuration layers relate to inspection creation +- `docs/data-model.md` - Full table details for all configuration tables +- `src/Document/docs/` - How inspection creation consumes configuration diff --git a/src/Apps/W1/Quality Management/app/src/Configuration/docs/architecture.md b/src/Apps/W1/Quality Management/app/src/Configuration/docs/architecture.md new file mode 100644 index 0000000000..e9e9cd92f3 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/src/Configuration/docs/architecture.md @@ -0,0 +1,75 @@ +# Configuration Module - Architecture + +## Three Configuration Layers + +### Layer 1: Generation Rules (When) + +`Qlty. Inspection Gen. Rule` defines the "when" condition: + +``` +Entry No. | Sort Order | Intent | Source Table | Table Filter | Template Code | Trigger +1 | 10 | Automatic | Purch. Line | Item = 1000 | VENDOR-QC | OnReceive +2 | 20 | Automatic | Purch. Line | (any) | GENERAL-QC | OnReceive +``` + +**Matching logic (`QltyInspecGenRuleMgmt`):** +1. Filter rules by source table +2. Apply Sort Order (ascending) — evaluate rules in order +3. Check table filter against the source record +4. First match wins → return template code + +**Trigger types:** Each integration module defines its own trigger enum (e.g., `QltyPurchaseOrderTrigger`). The generation rule stores the trigger as an integer, with the enum providing the named values. + +**Scheduling:** If `Schedule Group` is set, `QltyJobQueueManagement` creates a BC Job Queue Entry that periodically calls `QltyScheduleInspection` report to create inspections on schedule. + +### Layer 2: Inspection Templates (What) + +``` +Template Header (Code = "VENDOR-QC") + ├── Template Line 1: Test = "VISUAL-CHECK", Results: Pass/Fail + ├── Template Line 2: Test = "DIMENSION", Value type: Numeric, Min: 9.8, Max: 10.2 + └── Template Line 3: Test = "SURFACE", Results: A/B/C/Reject +``` + +**Template Line details:** +- Linked to a `Qlty. Test` record (test definition with value type) +- Has result visibility and finish-allowed rules per result value +- Can define result conditions (see Layer 3) + +**Test value types (`QltyTestValueType`):** +- `Numeric` - Decimal measurement +- `Text` - Free text +- `Boolean` - Yes/No +- `Lookup` - Selection from `Qlty. Test Lookup Value` list +- `LargeText` - Long text (memo) + +### Layer 3: Result Conditions (What Happens) + +`Qlty. I. Result Condit. Conf.` defines consequences of result selection: + +``` +Template Code | Line No. | Result | Action | Item Tracking Block +VENDOR-QC | 30 | Reject | AutoDisposition=Transfer | Yes +VENDOR-QC | 30 | A/B/C | (none) | No +``` + +**Result conditions can trigger:** +- Auto-disposition action on inspection finish +- Item tracking blocking/unblocking +- Failure state on the line + +## Source Configuration + +`Qlty. Inspect. Source Config.` answers: "Given a record from Table X, how do I find the item no., lot no., quantity, location, etc. to put on the inspection header?" + +**Traversal (`QltyTraversal`):** Handles complex relationships. For example, a Warehouse Receipt Line may need to traverse to its associated Purchase Line to find the vendor or item attributes. The traversal codeunit follows configured field paths across table relationships. + +**Auto-configuration (`QltyAutoConfigure`):** Pre-populates source configuration for standard BC tables (Purchase Line, Transfer Line, Assembly Line, etc.) during installation or when users run the assisted setup. + +## Key Design Decisions + +**Sort Order over code:** Rule priority is a user-editable integer rather than a code-based switch. This lets non-developers adjust prioritization without changing AL code. + +**Filter as string:** Generation rule table filters are stored as filter strings applied dynamically via `SetView()`. This allows arbitrary filter criteria without requiring new fields. + +**Result conditions are copied to inspection:** When an inspection is created, `Qlty. I. Result Condit. Conf.` records are copied to the inspection. This ensures that even if configuration changes after creation, the inspection behaves according to the rules at creation time. diff --git a/src/Apps/W1/Quality Management/app/src/Dispositions/docs/CLAUDE.md b/src/Apps/W1/Quality Management/app/src/Dispositions/docs/CLAUDE.md new file mode 100644 index 0000000000..8d99ebd590 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/src/Dispositions/docs/CLAUDE.md @@ -0,0 +1,45 @@ +# Dispositions Module - AI Context + +The Dispositions module handles **post-inspection inventory actions** — what to do with inspected stock after an inspection is finished (especially after a failure). + +## Files in This Module + +| File | Disposition Type | +|---|---| +| `QltyDisposition.Interface.al` | Interface all dispositions must implement | +| `QltyDispositionBuffer.Table.al` | Temporary working data during disposition | +| `Transfer/QltyDispTransfer.Codeunit.al` | Move inventory via transfer order | +| `Transfer/QltyCreateTransferOrder.Report.al` | Create the transfer order document | +| `PutAway/QltyDispWarehousePutAway.Codeunit.al` | Create warehouse put-away | +| `PutAway/QltyCreateInternalPutaway.Report.al` | Create internal put-away document | +| `PutAway/QltyDispInternalPutAway.Codeunit.al` | Internal put-away handler | +| `Purchase/QltyDispPurchaseReturn.Codeunit.al` | Create purchase return order | +| `Purchase/QltyCreatePurchaseReturn.Report.al` | Purchase return document | +| `InventoryAdjustment/QltyDispNegAdjustInv.Codeunit.al` | Negative inventory adjustment | +| `InventoryAdjustment/QltyCreateNegativeAdjmt.Report.al` | Negative adjustment journal | +| `ItemTracking/QltyDispChangeTracking.Codeunit.al` | Change lot/serial/package tracking | +| `ItemTracking/QltyChangeItemTracking.Report.al` | Item tracking change report | +| `Move/QltyDispInternalMove.Codeunit.al` | Internal inventory move | +| `Move/QltyDispMoveAutoChoose.Codeunit.al` | Auto-choose movement method | +| `Move/QltyDispMoveItemReclass.Codeunit.al` | Item reclassification journal move | +| `Move/QltyDispMoveWhseReclass.Codeunit.al` | Warehouse reclassification move | +| `Move/QltyDispMoveWorksheet.Codeunit.al` | Movement worksheet move | +| `Move/QltyMoveInventory.Report.al` | Move inventory report | + +## How to Add a New Disposition Action + +1. **Add enum value** to `QltyDispositionAction.Enum.al` +2. **Create codeunit** implementing `IQltyDisposition` interface in the appropriate subfolder +3. **Create report** for the actual BC document/journal creation (if needed) +4. **Register the mapping** between enum value and codeunit (follow existing pattern) + +## Key Enums + +- `Qlty. Disposition Action` - All available disposition types +- `Qlty. Item Adj. Post Behavior` - PostImmediately vs CreateDraft +- `Qlty. Quantity Behavior` - FullQuantity, SampleQuantity, UserDefined + +## Relevant Docs +- `docs/architecture.md` - Disposition layer overview and interface pattern +- `src/Document/docs/architecture.md` - When dispositions are triggered (finish inspection) +- `src/Configuration/docs/architecture.md` - Result conditions that auto-trigger dispositions diff --git a/src/Apps/W1/Quality Management/app/src/Document/docs/CLAUDE.md b/src/Apps/W1/Quality Management/app/src/Document/docs/CLAUDE.md new file mode 100644 index 0000000000..30cebc77f6 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/src/Document/docs/CLAUDE.md @@ -0,0 +1,37 @@ +# Document Module - AI Context + +The Document module is the runtime core of Quality Management — it contains the inspection document (header + lines) and all logic for creating, processing, and completing inspections. + +## Files in This Module + +| File | Purpose | +|---|---| +| `QltyInspectionHeader.Table.al` | Core inspection document. Tracks source, item, lot, location, status, re-inspection chain. | +| `QltyInspectionLine.Table.al` | Inspection lines (one per template test). Stores result value, failure state. | +| `QltyInspectionCreate.Codeunit.al` | **Main entry point** for inspection creation. Matches generation rules, resolves templates, maps source fields. | +| `QltyCreateInspection.Report.al` | Batch create inspections from source records. | +| `QltyInspection.Page.al` | Inspection card (single inspection view). | +| `QltyInspectionList.Page.al` | Inspection list page. | +| `QltyInspectionSubform.Page.al` | Lines subform embedded in card. | +| `QltyInspectionLines.Page.al` | Standalone lines page. | +| `QltyMostRecentPicture.Page.al` | Page part showing the most recent attached photo. | +| `QltyDocumentNavigation.Codeunit.al` | Navigate from inspection to source document. | +| `QltyInspectionStatus.Enum.al` | Open, Finished | +| `QltyInspectionCreateStatus.Enum.al` | Created, AlreadyExists, NoMatchingRules, Error | +| `QltyLineFailureState.Enum.al` | None, Failed, FailedWithComment | + +## Key Patterns + +**Creating an inspection:** Always use `QltyInspectionCreate`: +```al +QltyInspectionCreate.CreateInspectionWithVariant(SourceRecord, IsManualCreation); +``` + +**Finishing an inspection:** Set `Status = Finished` on the header. The `OnValidate` trigger calls `ProcessFinishInspection()` which evaluates result conditions. + +**Re-inspection:** Creates a new Header record with same base `No.` but `Re-inspection No. + 1`. Previous record's `Most Recent Re-inspection` is set to false. + +## Relevant Docs +- `docs/architecture.md` - Full system architecture and layer overview +- `docs/data-model.md` - Table field details and relationships +- `src/Configuration/docs/` - Templates and generation rules that drive inspection creation diff --git a/src/Apps/W1/Quality Management/app/src/Document/docs/architecture.md b/src/Apps/W1/Quality Management/app/src/Document/docs/architecture.md new file mode 100644 index 0000000000..0e95811937 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/src/Document/docs/architecture.md @@ -0,0 +1,101 @@ +# Document Module - Architecture + +## Responsibilities + +This module owns: +1. The **data model** for quality inspections (Header + Lines) +2. The **creation logic** that converts generation rule matches into inspection documents +3. The **UI** for inspectors to view and fill in inspections +4. The **status lifecycle** management (Open → Finished, re-open, re-inspect) + +It does NOT own: +- When to trigger creation (→ Generation Rules in Configuration) +- What to ask (→ Templates in Configuration) +- What to do after finishing (→ Dispositions) +- How to integrate with specific BC modules (→ Integration) + +## Data Flow: Inspection Creation + +``` +Caller (Integration event or user action) + │ + ▼ +QltyInspectionCreate.CreateInspectionWithVariant(Variant, IsManual) + │ + ├─ QltyInspecGenRuleMgmt.FindMatchingRule(RecordRef) + │ └─ Evaluates Qlty. Inspection Gen. Rule table + │ Returns template code + │ + ├─ QltyInspectSourceConfig → QltyTraversal + │ └─ Maps source record fields → Inspection Header fields + │ + ├─ Creates Qlty. Inspection Header + │ + └─ Creates Qlty. Inspection Lines from Template Lines + └─ Copies Qlty. Inspection Result Condition Config +``` + +## Status Lifecycle + +``` + CreateInspectionWithVariant() + │ + ▼ + ┌─────────────────┐ + │ Open │◄──── Re-open + └────────┬────────┘ + │ Set Status = Finished + ▼ + ┌─────────────────┐ + │ Finished │ + └────────┬────────┘ + │ Re-inspect action + ▼ + ┌─────────────────┐ + │ New Header │ (Re-inspection No. + 1) + │ Open │ + └─────────────────┘ +``` + +When an inspection is **Finished**: +- `ProcessFinishInspection()` runs in `OnValidate` of Status field +- Result conditions are evaluated (`QltyResultConditionMgmt`) +- Item tracking may be blocked if configured +- Workflow may be triggered if configured +- Source document may be updated if `UpdateSourceBehavior` is configured + +## Re-inspection Chain + +All re-inspections share the same base `No.` (from number series). The chain is: + +| No. | Re-inspection No. | Most Recent Re-inspection | +|---|---|---| +| QI-001 | 0 | false | +| QI-001 | 1 | false | +| QI-001 | 2 | true | + +To get the current inspection for a given `No.`: filter on `Most Recent Re-inspection = true`. + +## Inspection Creation - Error Handling + +`CreateInspectionWithVariant` returns `Boolean` (true = success). Detailed status available via `GetLastCreateStatus()` returning `Qlty. Inspection Create Status` enum: + +- `Created` - New inspection was created +- `AlreadyExists` - An open inspection already exists for this source record +- `NoMatchingRules` - No generation rule matched the source record +- `Error` - Creation failed (check error message) + +The codeunit has `AvoidThrowingErrorWhenPossible` flag for silent failure in batch scenarios. + +## Page Architecture + +``` +QltyInspectionList (list) + └─ drill-down → QltyInspection (card) + ├─ QltyInspectionSubform (lines subform) + └─ QltyMostRecentPicture (picture part) + +QltyInspectionLines (standalone lines, used in subforms from other pages) +``` + +The inspection card is the main UI. Inspectors fill in result values on each line in the subform. diff --git a/src/Apps/W1/Quality Management/app/src/Integration/docs/CLAUDE.md b/src/Apps/W1/Quality Management/app/src/Integration/docs/CLAUDE.md new file mode 100644 index 0000000000..ef190337c1 --- /dev/null +++ b/src/Apps/W1/Quality Management/app/src/Integration/docs/CLAUDE.md @@ -0,0 +1,72 @@ +# Integration Module - AI Context + +The Integration module connects Quality Management to standard BC modules using **event subscribers**. It never modifies base app code — it only hooks into published events. + +## Sub-modules + +``` +Integration/ +├── Assembly/ Assembly order triggers +├── Foundation/ +│ ├── Attachment/ Photo/document attachment integration +│ └── Navigate/ Navigate page integration +├── Inventory/ Item tracking, transfers, item availability, item journal +│ ├── Availability/ Item availability info +│ ├── Item/ Item card/list extensions +│ ├── Tracking/ Lot/Serial/Package info extensions + tracking integration +│ └── Transfer/ Transfer order document and history extensions +├── Manufacturing/ Production order output + routing + journals +│ ├── Document/ Prod. Order Routing page extension +│ ├── Journal/ Output/Consumption journal extensions +│ └── Routing/ Routing line lookup +├── Purchases/ Purchase order line extensions +│ └── Document/ PO and purchase return order subform extensions +├── Receiving/ Purchase receiving, transfer receiving, warehouse receipt, sales returns +├── Sales/ Sales order line extensions +│ └── Document/ Sales order and sales return order subform extensions +├── Utilities/ Integration with BC utilities (misc BC interactions) +└── Warehouse/ Warehouse entries and warehouse receipt integration + └── Ledger/ Warehouse entry extensions +``` + +## How to Add a New Integration Trigger + +1. **Create trigger enum** (if needed for a new module): Add `QltyTrigger.Enum.al` in the appropriate sub-folder. Follow the pattern of existing trigger enums. + +2. **Add event subscriber** in the relevant integration codeunit (e.g., `QltyReceivingIntegration`): +```al +[EventSubscriber(ObjectType::Codeunit, Codeunit::"", '', '', false, false)] +local procedure OnAfterSomeEvent(var Rec: Record "") +var + QltyInspectionCreate: Codeunit "Qlty. Inspection - Create"; +begin + QltyInspectionCreate.CreateInspectionWithVariant(Rec, false); +end; +``` + +3. **Add generation rule support**: Ensure the source table is covered by a Source Configuration entry (see `QltyAutoConfigure` for how standard tables are registered). + +4. **Add guided setup page** (optional): For new modules, add a `QltyGenRuleSGuide.Page.al` following the pattern of `QltyRecGenRuleSGuide.Page.al`. + +## Integration Codeunits + +| Codeunit | Module | What it hooks into | +|---|---|---| +| `QltyReceivingIntegration` | Receiving | Purchase order receipt, warehouse receipt, sales return, transfer receipt | +| `QltyManufacturIntegration` | Manufacturing | Production output journal, consumption journal | +| `QltyAssemblyIntegration` | Assembly | Assembly order posting | +| `QltyTransferIntegration` | Inventory/Transfer | Transfer order shipment/receipt | +| `QltyTrackingIntegration` | Inventory/Tracking | Item tracking line changes, lot/serial/package creation | +| `QltyWarehouseIntegration` | Warehouse | Warehouse receipt posting | +| `QltyInventoryAvailability` | Inventory | Item availability calculations (quality holds) | +| `QltyItemJournalManagement` | Inventory | Item journal posting | +| `QltyItemTracking` | Inventory | Item tracking assignment | +| `QltyItemTrackingMgmt` | Inventory | Item tracking management | +| `QltyAttachmentIntegration` | Foundation | Document attachment events | +| `QltyNavigateIntegration` | Foundation | Navigate page "Find" integration | +| `QltyUtilitiesIntegration` | Utilities | Miscellaneous BC utility hooks | + +## Relevant Docs +- `docs/architecture.md` - Full integration layer description +- `src/Document/docs/architecture.md` - Inspection creation entry point +- `src/Configuration/docs/architecture.md` - Generation rules and source configuration