New enterprise feature

This commit is contained in:
Urtzi Alfaro
2025-11-30 09:12:40 +01:00
parent f9d0eec6ec
commit 972db02f6d
176 changed files with 19741 additions and 1361 deletions

View File

@@ -29,6 +29,16 @@ The **Inventory Service** is the operational backbone of Bakery-IA, managing ing
- **Zero Manual Entry** - Eliminates manual stock entry after deliveries
- **Real-Time Synchronization** - Stock levels update immediately when deliveries are recorded
### 🆕 Enterprise Tier: Internal Transfer Processing (NEW)
- **Automatic Ownership Transfer** - When shipments are delivered, inventory ownership automatically transfers from parent to child
- **Stock Deduction at Parent** - Parent's inventory is reduced when shipment departs
- **Stock Addition at Child** - Child's inventory increases when shipment is delivered
- **Transfer Event Processing** - Consumes `shipment.delivered` events from Distribution Service
- **Dual-Sided Recording** - Creates stock movement records for both source (parent) and destination (child)
- **Transfer Movement Type** - Special stock movement type `transfer_out` (parent) and `transfer_in` (child)
- **Audit Trail** - Complete visibility into inter-location transfers
- **Subscription Validation** - Enterprise transfer processing requires Enterprise tier
### Food Safety Compliance (HACCP)
- **Temperature Monitoring** - Critical control point temperature logs
- **Food Safety Alerts** - Automated safety notifications
@@ -178,16 +188,21 @@ CREATE TABLE stock_movements (
tenant_id UUID NOT NULL,
stock_id UUID REFERENCES stock(id),
ingredient_id UUID REFERENCES ingredients(id),
movement_type VARCHAR(50) NOT NULL, -- in, out, adjustment, waste, production
movement_type VARCHAR(50) NOT NULL, -- in, out, adjustment, waste, production, 🆕 transfer_in, transfer_out (NEW)
quantity DECIMAL(10, 2) NOT NULL,
unit VARCHAR(50) NOT NULL,
reference_id UUID, -- production_batch_id, order_id, etc.
reference_type VARCHAR(50), -- production, sale, adjustment, waste
reference_id UUID, -- production_batch_id, order_id, shipment_id, etc.
reference_type VARCHAR(50), -- production, sale, adjustment, waste, 🆕 internal_transfer (NEW)
reason TEXT,
performed_by UUID,
-- 🆕 Enterprise internal transfer fields (NEW)
source_tenant_id UUID, -- For transfer_out: parent tenant
destination_tenant_id UUID, -- For transfer_in: child tenant
created_at TIMESTAMP DEFAULT NOW(),
INDEX idx_tenant_date (tenant_id, created_at),
INDEX idx_ingredient (ingredient_id)
INDEX idx_ingredient (ingredient_id),
-- 🆕 NEW index for internal transfers
INDEX idx_transfer_tenants (source_tenant_id, destination_tenant_id) WHERE reference_type = 'internal_transfer'
);
```
@@ -351,6 +366,14 @@ CREATE TABLE food_safety_alerts (
- Handles accepted quantities from delivery receipts
- Links stock movements to delivery reference IDs for full traceability
**🆕 From Distribution Service (NEW)**
- **Shipment Delivered** (`shipment.delivered`) - Automatically processes internal transfers when shipments are delivered
- Decreases stock at parent tenant (creates `transfer_out` stock movement)
- Increases stock at child tenant (creates `transfer_in` stock movement)
- Records source_tenant_id and destination_tenant_id for full transfer traceability
- Links both movements to shipment_id for audit trail
- Enterprise tier validation required
**From Other Services**
- **From Production**: Ingredient consumption in production
- **From Sales**: Finished product sales (for inventory valuation)
@@ -486,6 +509,8 @@ pytest --cov=app tests/ --cov-report=html
- **Production Service** - Consume ingredients in production
- **Forecasting Service** - Provide consumption data for forecasts
- **Suppliers Service** - Supplier information for stock items
- **🆕 Distribution Service** (NEW) - Process internal transfers via shipment.delivered events
- **🆕 Tenant Service** (NEW) - Validate tenant hierarchy for internal transfers
- **PostgreSQL** - Inventory data storage
- **Redis** - Dashboard KPI cache
- **RabbitMQ** - Alert publishing and delivery event consumption (🆕)
@@ -496,6 +521,7 @@ pytest --cov=app tests/ --cov-report=html
- **AI Insights Service** - Analyze inventory patterns
- **Frontend Dashboard** - Display inventory status
- **Notification Service** - Send inventory alerts
- **🆕 Distribution Service** (NEW) - Verify inventory availability before creating shipments
## Delivery Event Processing (🆕)