Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
```
83 changes: 83 additions & 0 deletions src/Apps/W1/Quality Management/app/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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/`
41 changes: 41 additions & 0 deletions src/Apps/W1/Quality Management/app/docs/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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`
124 changes: 124 additions & 0 deletions src/Apps/W1/Quality Management/app/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading