# Pricing Flow Diagrams

## Simulation Mode vs Reality Mode

```
┌─────────────────────────────────────────────────────────────────┐
│                    SIMULATE_PACKAGE_PRICING                     │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  TRUE (Simulation)              FALSE (Reality) ← CURRENT      │
│  ├─ Demo/Testing                ├─ Production                  │
│  ├─ Mock Pricing                ├─ Real Pricing                │
│  ├─ Fast Flow                   ├─ Odoo Required               │
│  └─ No Odoo Needed              └─ Full Business Process       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘
```

## Custom Pricing Flow (Reality Mode - Current)

```
┌──────────────┐
│   CUSTOMER   │
└──────┬───────┘
       │ 1. Request Quotation
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Creates Quotation (Status: pending_review)                   │
│  • Pricing: $0 (placeholder)                                     │
│  • Sends to Odoo                                                 │
└──────┬───────────────────────────────────────────────────────────┘
       │ 2. Create Draft Sale Order
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                          ODOO                                    │
├──────────────────────────────────────────────────────────────────┤
│  • Receives draft quotation (no order lines)                    │
│  • Sales team reviews requirements                              │
│  • Adds products/services                                        │
│  • Sets pricing                                                  │
│  • Sends quotation (state: 'sent')                              │
└──────┬───────────────────────────────────────────────────────────┘
       │ 3. Webhook: quotation.updated
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Syncs quotation pricing from Odoo                            │
│  • Updates: total_amount, monthly_price, fees                   │
│  • Status: sent                                                  │
│  • Sends email notification to customer                         │
└──────┬───────────────────────────────────────────────────────────┘
       │ 4. Email: "Your quotation is ready"
       ↓
┌──────────────┐
│   CUSTOMER   │
├──────────────┤
│  • Views quotation with REAL PRICING ✓                          │
│  • Reviews pricing breakdown                                     │
│  • Accepts quotation                                             │
└──────┬───────┘
       │ 5. Accept Quotation
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Sends acceptance to Odoo                                      │
└──────┬───────────────────────────────────────────────────────────┘
       │ 6. Confirm Quotation
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                          ODOO                                    │
├──────────────────────────────────────────────────────────────────┤
│  • Confirms quotation                                            │
│  • Converts to Sales Order (state: 'sale')                      │
└──────┬───────────────────────────────────────────────────────────┘
       │ 7. Webhook: sale.order.confirmed
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Creates Sales Order with Odoo pricing                        │
│  • Updates Quotation:                                            │
│    - Status: accepted                                            │
│    - Pricing: Updated from sales order (if changed)             │
│  • Links: Quotation ↔ Sales Order                               │
└──────┬───────────────────────────────────────────────────────────┘
       │ 8. Generate Invoice
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                          ODOO                                    │
├──────────────────────────────────────────────────────────────────┤
│  • Generates invoice from sales order                           │
│  • Invoice pricing = Sales order pricing                        │
└──────┬───────────────────────────────────────────────────────────┘
       │ 9. Webhook: invoice.created
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Creates Invoice with Odoo pricing                            │
│  • Links: Invoice ↔ Sales Order ↔ Quotation                    │
│  • Customer can now pay                                          │
└──────┬───────────────────────────────────────────────────────────┘
       │ 10. View Invoice & Pay
       ↓
┌──────────────┐
│   CUSTOMER   │
├──────────────┤
│  • Views invoice (same price as quotation) ✓                    │
│  • Makes payment                                                 │
└──────┬───────┘
       │ 11. Payment
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                    PAYMENT GATEWAY                               │
├──────────────────────────────────────────────────────────────────┤
│  • Processes payment (Pesepay/Bank Transfer)                    │
│  • Returns confirmation                                          │
└──────┬───────────────────────────────────────────────────────────┘
       │ 12. Payment Confirmation
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Records payment                                               │
│  • Sends payment to Odoo                                         │
└──────┬───────────────────────────────────────────────────────────┘
       │ 13. Record Payment
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                          ODOO                                    │
├──────────────────────────────────────────────────────────────────┤
│  • Records payment on invoice                                    │
│  • Marks invoice as paid                                         │
└──────┬───────────────────────────────────────────────────────────┘
       │ 14. Webhook: invoice.paid
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Updates invoice status: paid                                  │
│  • Updates customer balance                                      │
│  • Sends receipt to customer                                     │
└──────────────────────────────────────────────────────────────────┘

COMPLETE ✓
```

## Fixed Pricing Flow (Reality Mode)

```
┌──────────────┐
│   CUSTOMER   │
└──────┬───────┘
       │ 1. Request Quotation
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                         PORTAL                                   │
├──────────────────────────────────────────────────────────────────┤
│  • Calculates pricing (fixed/distance/bandwidth)                │
│  • Creates Quotation with REAL PRICING ✓                        │
│  • Status: pending                                               │
│  • Sends to Odoo                                                 │
└──────┬───────────────────────────────────────────────────────────┘
       │ 2. Create Draft Sale Order (with pricing)
       ↓
┌──────────────────────────────────────────────────────────────────┐
│                          ODOO                                    │
├──────────────────────────────────────────────────────────────────┤
│  • Receives quotation with pricing                              │
│  • No manual pricing needed                                      │
└──────────────────────────────────────────────────────────────────┘
       │
       ↓
┌──────────────┐
│   CUSTOMER   │
├──────────────┤
│  • Views quotation with pricing immediately ✓                   │
│  • Accepts quotation                                             │
└──────┬───────┘
       │ 3. Accept → Confirm → Invoice → Pay
       ↓
    (Same as steps 5-14 above)
```

## Pricing Sync Points

```
┌─────────────────────────────────────────────────────────────────┐
│                    PRICING SYNC POINTS                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Point 1: Quotation Created                                     │
│  ┌──────────┐                    ┌──────────┐                  │
│  │  PORTAL  │ ─── Pricing ────→  │   ODOO   │                  │
│  └──────────┘                    └──────────┘                  │
│  • Fixed/Calculated: Real pricing sent                         │
│  • Custom: $0 sent, requirements in notes                      │
│                                                                 │
│  Point 2: Quotation Priced (Custom Only)                       │
│  ┌──────────┐                    ┌──────────┐                  │
│  │  PORTAL  │ ←── Pricing ────   │   ODOO   │                  │
│  └──────────┘                    └──────────┘                  │
│  • Webhook: quotation.updated                                  │
│  • Portal syncs real pricing                                   │
│  • Customer notified                                            │
│                                                                 │
│  Point 3: Sales Order Confirmed                                │
│  ┌──────────┐                    ┌──────────┐                  │
│  │  PORTAL  │ ←── Pricing ────   │   ODOO   │                  │
│  └──────────┘                    └──────────┘                  │
│  • Webhook: sale.order.confirmed                               │
│  • Portal creates sales order                                  │
│  • Portal updates quotation pricing (if changed) ← NEW FIX     │
│                                                                 │
│  Point 4: Invoice Generated                                    │
│  ┌──────────┐                    ┌──────────┐                  │
│  │  PORTAL  │ ←── Pricing ────   │   ODOO   │                  │
│  └──────────┘                    └──────────┘                  │
│  • Webhook: invoice.created                                    │
│  • Portal creates invoice                                      │
│  • Invoice pricing = Sales order pricing                       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘
```

## Data Relationships

```
┌─────────────────────────────────────────────────────────────────┐
│                    DATA RELATIONSHIPS                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Customer                                                       │
│     │                                                           │
│     ├─── Quotation (portal_id ↔ odoo_quotation_id)            │
│     │       │                                                   │
│     │       ├─── total_amount (synced from Odoo) ✓            │
│     │       ├─── monthly_price (synced from Odoo) ✓           │
│     │       ├─── status (synced from Odoo) ✓                  │
│     │       │                                                   │
│     │       └─── Sales Order (portal_id ↔ odoo_order_id)      │
│     │               │                                           │
│     │               ├─── total_amount (from Odoo) ✓           │
│     │               ├─── quotation_id (links back) ✓          │
│     │               │                                           │
│     │               └─── Invoice (portal_id ↔ odoo_invoice_id)│
│     │                       │                                   │
│     │                       ├─── total_amount (from Odoo) ✓   │
│     │                       ├─── sales_order_id (links back) ✓│
│     │                       │                                   │
│     │                       └─── Payment                       │
│     │                               │                           │
│     │                               ├─── amount ✓             │
│     │                               ├─── invoice_id ✓         │
│     │                               └─── synced to Odoo ✓     │
│     │                                                           │
│     └─── Direct relationships maintained                       │
│                                                                 │
│  All pricing consistent across chain ✓                         │
│  All records linked bidirectionally ✓                          │
│  All changes synced via webhooks ✓                             │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘
```

## Timeline Comparison

```
┌─────────────────────────────────────────────────────────────────┐
│                    TIMELINE COMPARISON                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Fixed/Calculated Pricing:                                      │
│  ────────────────────────────────────────────────────────────  │
│  Request → Quote (instant) → Accept → Order → Invoice → Pay    │
│  └─────────────── Same Day ──────────────────────────────────┘ │
│                                                                 │
│  Custom Pricing (Before Fix):                                   │
│  ────────────────────────────────────────────────────────────  │
│  Request → Quote ($0) → Odoo Pricing → ??? → Invoice → Pay     │
│  └─ Customer never sees approved price until invoice ✗         │
│                                                                 │
│  Custom Pricing (After Fix):                                    │
│  ────────────────────────────────────────────────────────────  │
│  Request → Quote ($0) → Odoo Pricing → Quote Updated →         │
│  Customer Notified → Review → Accept → Order → Invoice → Pay   │
│  └─ Customer sees and approves price before invoice ✓          │
│  └─────────── 1-2 Days (depends on sales team) ──────────────┘ │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘
```

## Key Improvements Visualized

```
BEFORE FIX:
┌──────────┐     ┌──────────┐     ┌──────────┐     ┌──────────┐
│Quotation │     │  Sales   │     │ Invoice  │     │ Payment  │
│   $0     │ ──→ │  Order   │ ──→ │  $500    │ ──→ │  $500    │
│          │     │  $500    │     │          │     │          │
└──────────┘     └──────────┘     └──────────┘     └──────────┘
     ✗                ✓                 ✓                ✓
  (Never              (Has              (Has             (Has
  updated)            price)            price)           price)

Customer only sees price at invoice stage!


AFTER FIX:
┌──────────┐     ┌──────────┐     ┌──────────┐     ┌──────────┐
│Quotation │     │  Sales   │     │ Invoice  │     │ Payment  │
│   $0     │ ──→ │  Order   │ ──→ │  $500    │ ──→ │  $500    │
│   ↓      │     │  $500    │     │          │     │          │
│  $500 ✓  │     │          │     │          │     │          │
└──────────┘     └──────────┘     └──────────┘     └──────────┘
     ✓                ✓                 ✓                ✓
  (Updated         (Has              (Has             (Has
  from Odoo)       price)            price)           price)

Customer sees approved price before accepting!
```
