docs: FASES_IMPLEMENTADAS + MULTI_BRANCH + GLOBAL_INVOICE
- Actualiza FASES_IMPLEMENTADAS.md con Fase 7 (precios proveedor, multi-sucursal, factura global) - Agrega docs/MULTI_BRANCH.md con arquitectura y endpoints - Agrega docs/GLOBAL_INVOICE.md con requerimiento SAT y flujo de uso
This commit is contained in:
52
docs/MULTI_BRANCH.md
Normal file
52
docs/MULTI_BRANCH.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Multi-sucursal — Documentación Técnica
|
||||
|
||||
**Versión DB:** v4.0
|
||||
**Commit:** `2b73c2c`
|
||||
|
||||
---
|
||||
|
||||
## Arquitectura
|
||||
|
||||
### Catálogo compartido
|
||||
- `inventory.branch_id` es siempre `NULL` (catálogo compartido a nivel tenant).
|
||||
- `part_number` tiene unique index `idx_inventory_part_unique`.
|
||||
- Productos duplicados por `part_number` en múltiples sucursales fueron consolidados en la migración v4.0.
|
||||
|
||||
### Stock por sucursal
|
||||
- Tabla `inventory_stock (inventory_id, branch_id, stock, location)`.
|
||||
- Trigger `trg_update_inventory_stock` en `inventory_operations` mantiene `inventory_stock` sincronizado automáticamente.
|
||||
- `inventory_stock_summary` sigue existiendo como stock total agregado (sin `branch_id`).
|
||||
|
||||
### Datos fiscales por sucursal
|
||||
- Tabla `branches` incluye: `rfc`, `razon_social`, `regimen_fiscal`, `codigo_postal`, `serie_cfdi`, `folio_inicial`, `licencia_fiscal`, `certificado_pem`, `llave_pem`, `is_main`.
|
||||
- Solo una sucursal puede ser `is_main = true`.
|
||||
- Al facturar, `_get_issuer_config(cur, branch_id)` usa datos de la sucursal de la venta; fallback a config global del tenant.
|
||||
|
||||
---
|
||||
|
||||
## Endpoints
|
||||
|
||||
### Config
|
||||
- `GET /pos/api/config/branches` — lista sucursales (sin PEM)
|
||||
- `GET /pos/api/config/branches/<id>` — detalle completo (con PEM)
|
||||
- `POST /pos/api/config/branches` — crear
|
||||
- `PUT /pos/api/config/branches/<id>` — editar
|
||||
|
||||
### Inventario
|
||||
- `GET /pos/api/inventory/items` — acepta `?branch_id=` para mostrar stock por sucursal
|
||||
- Stock se lee de `inventory_stock` cuando se filtra por sucursal
|
||||
|
||||
### POS
|
||||
- Ventas verifican stock vía `get_stock(conn, inventory_id, branch_id)`
|
||||
- `inventory_operations` registra `branch_id` de la venta
|
||||
|
||||
---
|
||||
|
||||
## Migración
|
||||
|
||||
```bash
|
||||
cd /home/Autopartes/pos
|
||||
python3 migrations/runner.py
|
||||
```
|
||||
|
||||
Archivo: `pos/migrations/v4.0_multi_branch.sql`
|
||||
Reference in New Issue
Block a user