> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laportenard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Backend development

> Working with the Odoo 12 backend modules and API.

## Module structure

The backend is a single consolidated Odoo 12 addon:

| Module              | Depends on                                                 | Purpose                                                                                        |
| ------------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `nu_restaurant_pos` | `point_of_sale`, `pos_restaurant`, `dgii_pos`, `dgii_encf` | Core POS API, models, voids, side dishes, discounts, printing, presentations, special requests |

## API gateway

All endpoints live under `/pos-api/v1/*` in `controllers/api_v1.py`. The gateway handles:

* JWT Bearer token validation
* CORS headers
* Request routing to legacy controller methods

<Note>
  The legacy controller methods in `api.py`, `api_orders.py`, etc. have no routes of their own — they are called by `api_v1.py`.
</Note>

## Extending bootstrap data

To add data to the bootstrap payload, extend the `pos.config` model:

```python theme={null}
class PosConfig(models.Model):
    _inherit = 'pos.config'

    def _get_bootstrap_extra(self, user):
        result = super()._get_bootstrap_extra(user)
        result['my_new_data'] = self._get_my_data()
        return result
```

<Warning>
  Do not try to use controller inheritance — it does not work reliably in Odoo 12 for internal methods. Use model inheritance (`_inherit`) instead.
</Warning>

## Upgrading modules

```bash theme={null}
./odoo-bin -d <db> -u nu_restaurant_pos \
  --addons-path=addons,extra_addons --stop-after-init
```

## Migrations

Version-specific migration scripts go in `migrations/<version>/pre-migrate.py` or `post-migrate.py`. The `<version>` must match the new version in `__manifest__.py`.

## Declarative configuration

Backend POS configuration (printers, print routes, discount presets, void reasons, special-request tags, side-dish groups, picking-sale reasons, shared configs, and per-terminal `nu_*` fields) is managed declaratively via the [JSON config sync](./json-config-sync) loader. The most recently applied document is replayed automatically on module install and upgrade.

## Permissions

The permission system has three layers resolved in order:

1. **Factory defaults** — `permission_registry.py` `PERMISSION_DEFAULTS`
2. **Per-config role overrides** — `nu.pos.permission.config` model
3. **Per-user grant/deny** — `nu.pos.permission.user.override` model

<Warning>
  Permission models should be writable only by `base.group_system` (admin). Managers should not be able to self-grant privileges.
</Warning>

### Adding a new permission

1. Add the key and default to `PERMISSION_DEFAULTS` in `permission_registry.py`
2. Mirror the same key and default in `permissions.ts` on the frontend
3. Both files must stay in sync
