# Invoice Creation Guide for Customer Portal

## Current Situation

❌ **Cannot create invoices via API** - The Odoo API user lacks the required permissions.

### Error Details
```
AccessError: You are not allowed to create 'Journal Entry' (account.move) records.

This operation is allowed for the following groups:
- Accounting/Billing
- Purchase/User
```

## What This Means

The customer portal integration can:
- ✅ Read invoices from Odoo
- ✅ Display invoices to customers
- ✅ Show billing information
- ❌ Create invoices via API (requires admin permissions)

## Solutions

### Option 1: Create Invoices Manually in Odoo (RECOMMENDED)

This is the standard workflow for most businesses:

1. **Log into Odoo** as an administrator or accounting user
2. **Navigate to:** Accounting → Customers → Invoices
3. **Click:** Create (New button)
4. **Fill in the invoice:**
   - Customer: Select "Tawona Rwatida" (Partner ID: 3581)
   - Invoice Date: Today's date
   - Due Date: 30 days from now (or your payment terms)
   - Invoice Lines: Add products/services
     - Product: Select from your product catalog
     - Quantity: 1 (or as needed)
     - Unit Price: Set the price
5. **Click:** Confirm/Post to make it official
6. **Result:** Invoice immediately appears in customer portal

### Option 2: Grant API User Invoice Creation Permissions

If you need automated invoice creation:

1. **Log into Odoo** as administrator
2. **Navigate to:** Settings → Users & Companies → Users
3. **Find the API user** (the one used for portal integration)
4. **Edit the user** and add to these groups:
   - ✅ Accounting/Billing
   - ✅ Sales/User (if not already added)
5. **Save** the changes
6. **Re-run:** `php create-test-invoice.php`

⚠️ **Security Note:** Granting invoice creation permissions to an API user should be done carefully as it allows programmatic creation of financial documents.

### Option 3: Create Invoice from Sales Order

If you have sales orders in Odoo:

1. **Navigate to:** Sales → Orders → Orders
2. **Find an order** for Tawona Rwatida
3. **Click:** Create Invoice button
4. **Confirm** the invoice
5. **Result:** Invoice linked to the order and visible in portal

## Test Invoice Details

For testing purposes, create an invoice with these details:

**Customer Information:**
- Name: Tawona Rwatida
- Email: tawona@quatrohaus.com
- Odoo Partner ID: 3581

**Invoice Details:**
- Invoice Date: Today
- Due Date: 30 days from today
- Product: Any product from your catalog (e.g., Internet Service)
- Quantity: 1
- Unit Price: $50.00 (or any amount)
- Total: $50.00

**After Creation:**
- State: Posted (confirmed)
- Payment State: Not Paid

## Verifying Invoice in Portal

After creating the invoice in Odoo:

1. **Log into customer portal:** http://localhost:3000/login
2. **Email:** tawona@quatrohaus.com
3. **Navigate to:** Dashboard or Invoices page
4. **You should see:**
   - Invoice number
   - Amount due
   - Due date
   - Payment status
   - Option to download/view invoice

## Portal Invoice Features

Once invoices exist in Odoo, customers can:
- ✅ View all their invoices
- ✅ See invoice details (amount, due date, status)
- ✅ Check payment status
- ✅ View arrears/overdue amounts
- ✅ Make payments (if payment gateway configured)
- ✅ Upload proof of payment
- ✅ Download invoice PDFs (if configured in Odoo)

## Current Status

- ✅ Customer exists in Odoo (Partner ID: 3581)
- ✅ Portal integration working
- ✅ Invoice reading functionality working
- ❌ No invoices currently in Odoo
- ❌ API user cannot create invoices (permission issue)

## Next Steps

1. **Create at least one test invoice** in Odoo manually (Option 1)
2. **Test the portal** to verify invoice display
3. **Decide** if you need API invoice creation (Option 2)
4. **Configure** payment gateways if needed

## Technical Notes

### Odoo Invoice Model (account.move)
Required fields for customer invoices:
- `partner_id`: Customer ID (3581 for Tawona)
- `move_type`: 'out_invoice' (customer invoice)
- `invoice_date`: Date of invoice
- `invoice_date_due`: Payment due date
- `invoice_line_ids`: Array of invoice lines with:
  - `product_id`: Product/service ID
  - `name`: Description
  - `quantity`: Quantity
  - `price_unit`: Unit price

### Portal Integration
The portal fetches invoices using:
```php
$odooService->getCustomerInvoices($partnerId)
```

This queries:
```
Model: account.move
Domain: [['partner_id', '=', $partnerId], ['move_type', '=', 'out_invoice']]
Fields: id, name, invoice_date, invoice_date_due, amount_total, amount_residual, state, payment_state
```

## Support

If you need help:
1. Check Odoo user permissions
2. Verify customer exists in Odoo
3. Ensure invoices are in "Posted" state (not draft)
4. Check Odoo logs for any errors
