# Product Lifecycle

## Overview

Products are the central entity in the Product Management module. A product represents a commercial product — identified by a unique code, along with its name, description, and attribute assignments. Products serve as the parent entity from which variants are generated. Each product has a lifecycle state machine (DRAFT → ACTIVE ↔ ARCHIVED) that controls when variant generation and downstream operations are permitted.

## Business Purpose

Products provide the commercial/marketing view of a product, separate from the operational SKU-level Item in item-management. This separation enables:

- Marketing and product teams to define product structure and descriptions before SKUs exist
- Attribute assignment and configuration before generating actual Items
- Archival of discontinued product lines while preserving generated Items for historical transactions
  The lifecycle ensures:

- Products are reviewed before variant generation is allowed (DRAFT → ACTIVE)
- Archived products stop generating new variants but existing Items remain unaffected
- Only DRAFT products can be permanently deleted; ACTIVE/ARCHIVED products are preserved

## Process Flow

```mermaid
stateDiagram-v2
    [*] --> Draft: createProduct
    Draft --> Active: activateProduct
    Active --> Archived: deactivateProduct
    Archived --> Active: reactivateProduct
    Draft --> [*]: deleteProduct
```

The product creation and setup flow follows this pattern:

```mermaid
flowchart TD
    A[Create Product] --> B[Assign Attributes]
    B --> C{Ready for variants?}
    C -->|Yes| D[Activate Product]
    C -->|No| E[Continue editing]
    E --> B
    D --> F[Generate Variants]
```

## Scenario Patterns

- **New Product Setup**: A product is created in DRAFT, attributes are assigned (Color, Size), then the product is activated
- **Product Line Archival**: An entire product line is archived. The product moves to ARCHIVED status, preventing new variant generation, but all existing Items remain ACTIVE in item-management
- **Product Relaunch**: A previously archived product is reactivated for a new season, allowing new variant generation with updated attribute values
- **Draft Cleanup**: Unfinished products in DRAFT are deleted before activation
- **Product Update**: An ACTIVE product's name and description can be updated. New attribute values can be added to existing attributes (to support incremental variant generation), but existing values cannot be modified or removed to preserve variant consistency

## Test Cases

- Product lifecycle follows DRAFT → ACTIVE ↔ ARCHIVED state machine
- Products can only be created in DRAFT status
- Only DRAFT products can be deleted; ACTIVE and ARCHIVED products cannot
- Product code is required, unique, and immutable after creation
- Product name is required and must be non-empty
- On ACTIVE products, new attribute values can be added but existing values cannot be modified or removed
- On DRAFT products, all attribute operations (add, modify, remove) are allowed
- Archiving a product does not affect existing Items generated from its variants
- Reactivating an ARCHIVED product returns it to ACTIVE status

## Reference Links

- [Odoo Product Variants](https://www.odoo.com/documentation/19.0/applications/sales/sales/products_prices/products/variants.html)
- [Akeneo Product Model](https://help.akeneo.com/pim/serenity/articles/what-about-products-variants.html)
