# Registration to Odoo Field Mapping

## Customer Type Mapping

### Portal Customer Types → Odoo Fields

| Portal Type | Description | Odoo `is_company` | Odoo `company_type` | Use Case |
|------------|-------------|-------------------|---------------------|----------|
| **wholesale** | Partners, ISPs, telecom companies who resell AFINET services | `true` (always) | `company` | Wholesale partners with clients |
| **business** | Companies, organizations, and individuals needing direct services | `true` if company_name provided, `false` otherwise | `company` or `person` | Direct customers (retail) - can be companies OR individuals |

### Business Type Logic

The **business** customer type is flexible and can represent both:

1. **Individual Customers** (is_company: false)
   - Person registering for personal/home internet
   - No company name provided
   - Example: "John Doe" registering for home internet

2. **Company Customers** (is_company: true)
   - Small/medium business registering for office internet
   - Company name provided
   - Example: "Small Business Ltd" registering for office connectivity

**Key Rule:** If a business customer provides a company name during registration, they are marked as `is_company: true` in Odoo. Otherwise, they are marked as `is_company: false`.

## Complete Field Mapping

### Basic Information (All Customers)

| Portal Field | Odoo Field | Required | Notes |
|-------------|-----------|----------|-------|
| `name` | `name` | Yes | Contact person name (overridden by company_name for wholesale) |
| `email` | `email` | Yes | Unique identifier |
| `phone` | `phone` | Yes | Primary phone |
| `mobile` | `mobile` | No | Secondary phone |
| `type` | `is_company` | Yes | wholesale=true, business=false |

### Company Information

| Portal Field | Odoo Field | Required For | Notes |
|-------------|-----------|--------------|-------|
| `company_name` | `name` + `commercial_company_name` | Wholesale (Required), Business (Optional) | Becomes primary name for wholesale |
| `industry` | `comment` | Both (Optional) | Stored as "Industry: {value}" |
| `tin_number` | `ref` | Wholesale (Required), Business (Optional) | TIN/Tax Identification Number |
| `vat_number` | `vat` | Wholesale (Required), Business (Optional) | VAT/Tax number |
| `website` | `website` | Wholesale (Optional) | Company website |
| `job_title` | `function` | Wholesale (Optional) | User's job title |

### Address Information (Optional for All)

| Portal Field | Odoo Field | Notes |
|-------------|-----------|-------|
| `street` | `street` | Street address |
| `street2` | `street2` | Apartment, suite, etc. |
| `city` | `city` | City |
| `zip` | `zip` | ZIP/Postal code |
| `state` | `state_id` | State/Province (set to false for now) |
| `country` | `country_id` | Country (not set to avoid FK issues) |

### System Fields (Auto-generated)

| Portal Field | Odoo Field | Value |
|-------------|-----------|-------|
| N/A | `customer_rank` | `1` (marks as customer) |
| N/A | `state_id` | `false` (will be mapped later) |
| N/A | `country_id` | Not set (to avoid FK constraints) |

## Registration Flow Examples

### Example 1: Wholesale Partner Registration

**User Input:**
```
Category: Wholesale Partner
Name: John Smith
Email: john@ispcompany.com
Phone: +263771234567
Company Name: ISP Company Ltd
Industry: Telecommunications
TIN Number: TIN123456789
VAT Number: VAT987654321
Website: https://ispcompany.com
Job Title: CEO
```

**Sent to Odoo:**
```json
{
  "name": "ISP Company Ltd",
  "email": "john@ispcompany.com",
  "phone": "+263771234567",
  "mobile": null,
  "website": "https://ispcompany.com",
  "function": "CEO",
  "customer_rank": 1,
  "is_company": true,
  "ref": "TIN123456789",
  "vat": "VAT987654321",
  "comment": "Industry: Telecommunications",
  "commercial_company_name": "ISP Company Ltd"
}
```

**Result in Odoo:**
- Partner ID: 3584
- Name: ISP Company Ltd
- Is Company: Yes ✓
- Company Type: company
- TIN (ref): TIN123456789 ✓
- VAT: VAT987654321 ✓
- Industry (comment): Industry: Telecommunications ✓

### Example 2: Business Customer (Individual) Registration

**User Input:**
```
Category: Business Customer
Name: Jane Doe
Email: jane@example.com
Phone: +263779876543
Company Name: (left empty - individual customer)
Industry: Retail
```

**Sent to Odoo:**
```json
{
  "name": "Jane Doe",
  "email": "jane@example.com",
  "phone": "+263779876543",
  "mobile": null,
  "customer_rank": 1,
  "is_company": false,
  "ref": null,
  "comment": "Industry: Retail"
}
```

**Result in Odoo:**
- Partner ID: 3585
- Name: Jane Doe
- Is Company: No ✓ (individual customer)
- Company Type: person
- TIN (ref): (empty) ✓
- Industry (comment): Industry: Retail ✓

### Example 3: Business Customer (Company) Registration

**User Input:**
```
Category: Business Customer
Name: Mike Johnson
Email: mike@smallbiz.com
Phone: +263771111111
Company Name: Small Business Ltd (provided - company customer)
Industry: Consulting
```

**Sent to Odoo:**
```json
{
  "name": "Small Business Ltd",
  "email": "mike@smallbiz.com",
  "phone": "+263771111111",
  "customer_rank": 1,
  "is_company": true,
  "comment": "Industry: Consulting",
  "commercial_company_name": "Small Business Ltd"
}
```

**Result in Odoo:**
- Partner ID: 3586
- Name: Small Business Ltd
- Is Company: Yes ✓ (company customer, not wholesale partner)
- Company Type: company
- Industry (comment): Industry: Consulting ✓

**Note:** This is different from wholesale - it's a company that needs internet services directly from AFINET, not a partner who resells services.

## Comparison with Existing Odoo Customers

### What We Found in Odoo (345 customers analyzed):

| Field | Usage in Existing Customers | Our Implementation |
|-------|---------------------------|-------------------|
| `is_company` | ✓ Used (242 companies, 103 individuals) | ✓ Matches perfectly |
| `company_type` | ✓ Used (company/person) | ✓ Auto-set by Odoo based on is_company |
| `ref` (TIN) | Rarely used (12 customers) | ✓ Now required for wholesale |
| `vat` | Well used (98 customers) | ✓ Required for wholesale |
| `comment` (Industry) | Rarely used (8 customers) | ✓ Now captured for all |
| `function` (Job Title) | Sometimes used | ✓ Captured for wholesale |
| `website` | Sometimes used | ✓ Captured for wholesale |

## Key Differences from Existing Customers

### What's New:
1. **TIN Number (ref)** - Now systematically captured for wholesale partners
2. **Industry (comment)** - Now captured for all customers
3. **Structured Customer Types** - Clear distinction between wholesale and business
4. **Required Fields** - Wholesale partners must provide company info, TIN, VAT

### What Stays the Same:
1. **is_company flag** - Still used to distinguish companies from individuals
2. **VAT field** - Still used for tax numbers
3. **All standard contact fields** - Phone, email, address, etc.

## Validation Rules

### Wholesale Partner (type: wholesale)
- ✓ Company name: Required
- ✓ TIN number: Required
- ✓ VAT number: Required
- ✓ Industry: Optional but recommended
- ✓ Website: Optional
- ✓ Job title: Optional

### Business Customer (type: business)
- ✓ Name: Required
- ✓ Company name: Optional
- ✓ Industry: Optional
- ✓ TIN number: Not required
- ✓ VAT number: Not required

## Summary

✅ **Perfect Fit!** Our customer types and registration fields align perfectly with Odoo's data model:

1. **Customer Type Distinction**: 
   - **Wholesale** → Always `is_company: true` (partners/ISPs)
   - **Business** → Dynamic `is_company` based on whether company_name is provided
     - With company name → `is_company: true` (company customer)
     - Without company name → `is_company: false` (individual customer)

2. **Field Coverage**: All important Odoo fields are captured during registration

3. **Data Quality**: We're now capturing TIN and Industry systematically, improving data quality

4. **Backward Compatible**: Works with existing Odoo customers without conflicts

5. **Flexible Business Type**: Business customers can be either individuals OR companies, matching real-world scenarios

6. **Future Proof**: Can easily add more fields as needed

The registration flow is production-ready and fully integrated with Odoo! 🎉
