# oca/sale-workflow architecture

> Architecture diagram of the GitHub repository oca/sale-workflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oca/sale-workflow
- Repository: https://github.com/oca/sale-workflow

## Overview

##### Project Type and Purpose
- This is not a standalone web‐app but an Odoo “addons” repository (OCA/sale-workflow) containing 70+ individual modules (“addons”) that extend and customize Odoo’s Sales application.
- The README lists each addon, its version and summary: e.g., sale_automatic_workflow, portal_sale_order_search, sale_exception, pricelist_cache, etc.

##### File-Structure Insights
- Top level: configuration files (.pylintrc, pre-commit, github workflows), a `requirements.txt`, and a `setup` metapackage.
- Each addon is a directory (e.g. `sale_automatic_workflow/`, `portal_sale_order_search/`, `pricelist_cache/`, …).
- Common subfolders per addon:
- `__manifest__.py` (Odoo manifest)
- `models/` (Python ORM extensions)
- `views/` (XML form/tree/view definitions)
- `data/` (demo or ir.cron, mail templates, etc.)
- `controllers/` for portal addons
- `static/` (assets/html, js, CSS)
- `i18n/` (translations)
- `security/` (access rules)
- `tests/`

##### Architectural Context from README
- These addons plug into the Odoo server process. Some register cron jobs (e.g. sale_automatic_workflow), some define queue‐job tasks (sale_automatic_workflow_job), others extend views or models, or add portal controllers.
- They rely on Odoo core modules: `sale_management`, `stock`, `crm`, `portal`, `queue_job`.

##### Main Components
A. Odoo Core Platform
- HTTP/Web Client (web.assets, web controllers)
- Odoo Server (Python application, request handlers)
- ORM Layer (models, recordsets)
- Scheduler / Cron subsystem
- Queue Job Worker (for asynchronous tasks)
- PostgreSQL Database
B. Custom Addon Clusters
1. Sale Automation
- sale_automatic_workflow (defines processes, workflows)
- sale_automatic_workflow_job (queue‐job integration)
- sale_automatic_workflow_stock / _periodicity / _stock_job
2. Portal Extensions
- portal_sale_order_search (controllers + views)
- portal_sale_personal_data_only
3. Pricing & Pricelist
- pricelist_cache
4. Sale Exceptions & Blocking
- sale_exception & plugins (sale_exception_product_sale_manufactured_for)
- sale_block_no_stock, sale_stock_cancel_restriction, sale_invoice_blocking, sale_stock_picking_blocking
5. Sale Order Enhancements (each a separate addon):
- sale_cancel_reason, sale_commercial_partner, sale_company_currency, sale_delivery_split_date, sale_delivery_state, sale_discount_display_amount, sale_elaboration, sale_fixed_discount, sale_force_invoiced, sale_invoice_frequency, sale_invoice_policy, sale_manual_delivery, sale_mrp_bom, sale_order_archive, sale_order_carrier_auto_assign, sale_order_general_discount, sale_order_invoicing_finished_task, sale_order_line_date, sale_order_line_delivery_state, sale_order_line_input, sale_order_line_menu, sale_order_line_note, sale_order_line_price_history, sale_order_line_sequence, sale_order_line_stock_move_history, sale_order_line_tag, sale_order_lot_selection, sale_order_note_template, sale_order_price_recalculation, sale_order_product_assortment, sale_order_product_availability_inline, sale_order_product_recommendation, sale_order_report_without_price, sale_order_requested_delivery, sale_order_revision, sale_order_secondary_unit, sale_order_split_strategy, sale_order_tag, sale_order_type, sale_order_warn_message, sale_partner_address_restrict, sale_partner_incoterm, sale_partner_selectable_option, sale_procurement_group_by_line, sale_product_set, sale_product_set_packaging_qty, sale_quotation_number, sale_require_po_doc, sale_shipping_info_helper, sale_sourced_by_line, sale_stock_delivery_state, sale_stock_line_customer_ref, sale_stock_line_sequence, sale_stock_picking_note, sale_stock_return_request, sale_substate, sale_tier_validation, sale_transaction_form_link, sale_wishlist, sales_team_security, sell_only_by_packaging.

##### Relationships & Interactions
- Web Client → Odoo HTTP Controllers → Core + Addon Controllers (portal modules) → ORM → Database.
- User actions on Sale Order forms: addons extend view definitions, add buttons, fields, wizards, and business logic in python models.
- Scheduled Cron (Scheduler) → sale_automatic_workflow → may enqueue Queue Jobs via sale_automatic_workflow_job → Queue Worker → executes business processes updating sale_order/sale_workflow_process records → ORM → Database.
- Modules often inherit Odoo core models (`sale.order`, `sale.order.line`, `stock.move`, `res.partner`, etc.) to add fields or override methods.
- Security rules restrict access to new models/views (security/ir.model.access.csv).

##### Architectural Patterns & Principles
- Plugin architecture: each addon is loosely coupled, Odoo picks them up via addons path.
- Inheritance / Monkey‐patching: use _inherit to extend core models, views.
- Event scheduling: use ir.cron + queue_job for asynchronous, decoupled execution.
- MVC pattern: XML views for UI, Python models for business logic, controllers for HTTP endpoints.
- i18n: translation files support multi‐language.
- Tests: each addon contains unit/integration tests.

##### Elements
- Clear labels on each component (e.g., “sale_automatic_workflow_job addon”, “Scheduler”, “PostgreSQL DB”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Odoo Core
    subgraph "Odoo Core"
        direction TB
        WC["Web Client"]:::core
        HC[/HTTP Controllers/]:::core
        ORM["ORM Layer"]:::core
        SCH["Scheduler (Cron)"]:::core
        QW{{Queue Worker}}:::core
    end
    DB[(PostgreSQL DB)]:::db

    %% Sale Automation Cluster
    subgraph "Sale Automation" 
        direction TB
        SA1(["sale_automatic_workflow addon"]):::saleAuto
        SA2(["sale_automatic_workflow_job addon"]):::saleAuto
        SA3(["sale_automatic_workflow_periodicity addon"]):::saleAuto
        SA4(["sale_automatic_workflow_stock addon"]):::saleAuto
        SA5(["sale_automatic_workflow_stock_job addon"]):::saleAuto
    end

    %% Portal Extensions Cluster
    subgraph "Portal Extensions"
        direction TB
        P1(["portal_sale_order_search addon"]):::portal
        P2(["portal_sale_personal_data_only addon"]):::portal
    end

    %% Pricing Cluster
    subgraph "Pricing & Pricelist"
        direction TB
        PR(["pricelist_cache addon"]):::pricing
    end

    %% Exceptions & Blocking Cluster
    subgraph "Sale Exceptions & Blocking"
        direction TB
        E1(["sale_exception addon"]):::exceptions
        E2(["sale_exception_product_sale_manufactured_for addon"]):::exceptions
        E3(["sale_block_no_stock addon"]):::exceptions
        E4(["sale_stock_cancel_restriction addon"]):::exceptions
        E5(["sale_invoice_blocking addon"]):::exceptions
        E6(["sale_stock_picking_blocking addon"]):::exceptions
    end

    %% Core Flows
    WC -->|"RPC call"| HC
    HC -->|"calls ORM"| ORM
    ORM -->|"SQL read/write"| DB
    SCH -->|"cron trigger"| SA1
    SA1 -->|"model extension"| ORM
    SA2 -->|"enqueue job"| QW
    QW -->|"process job"| ORM

    %% Portal Flow
    WC -->|"HTTP"| HC
    HC -->|"/portal endpoints"| P1
    HC -->|"/portal endpoints"| P2
    P1 -->|"ORM calls"| ORM
    P2 -->|"ORM calls"| ORM

    %% Pricing Flow
    PR -->|"model extension"| ORM

    %% Exceptions Flow
    E1 -->|"model extension"| ORM
    E2 -->|"model extension"| ORM
    E3 -->|"model extension"| ORM
    E4 -->|"model extension"| ORM
    E5 -->|"model extension"| ORM
    E6 -->|"model extension"| ORM

    %% Click Events
    click SA1 "https://github.com/oca/sale-workflow/tree/18.0/sale_automatic_workflow/"
    click SA2 "https://github.com/oca/sale-workflow/tree/18.0/sale_automatic_workflow_job/"
    click SA3 "https://github.com/oca/sale-workflow/tree/18.0/sale_automatic_workflow_periodicity/"
    click SA4 "https://github.com/oca/sale-workflow/tree/18.0/sale_automatic_workflow_stock/"
    click SA5 "https://github.com/oca/sale-workflow/tree/18.0/sale_automatic_workflow_stock_job/"
    click P1 "https://github.com/oca/sale-workflow/tree/18.0/portal_sale_order_search/"
    click P2 "https://github.com/oca/sale-workflow/tree/18.0/portal_sale_personal_data_only/"
    click PR "https://github.com/oca/sale-workflow/tree/18.0/pricelist_cache/"
    click E1 "https://github.com/oca/sale-workflow/tree/18.0/sale_exception/"
    click E2 "https://github.com/oca/sale-workflow/tree/18.0/sale_exception_product_sale_manufactured_for/"
    click E3 "https://github.com/oca/sale-workflow/tree/18.0/sale_block_no_stock/"
    click E4 "https://github.com/oca/sale-workflow/tree/18.0/sale_stock_cancel_restriction/"
    click E5 "https://github.com/oca/sale-workflow/tree/18.0/sale_invoice_blocking/"
    click E6 "https://github.com/oca/sale-workflow/tree/18.0/sale_stock_picking_blocking/"

    %% Styles
    classDef core fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef db fill:#ffffcc,stroke:#333,stroke-width:1px
    classDef saleAuto fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef portal fill:#ffe5cc,stroke:#333,stroke-width:1px
    classDef pricing fill:#e0ccff,stroke:#333,stroke-width:1px
    classDef exceptions fill:#ffcccc,stroke:#333,stroke-width:1px
```
