Commit Graph

48 Commits

Author SHA1 Message Date
Claude
232ef80a6e fix: Correct production batch date filtering to check start date only
The previous logic required batches to both START and END within the date range,
which excluded batches that start today but end later. Now correctly filters
batches based on their planned_start_time only, so today's batches include all
batches scheduled to start today regardless of their end time.

Fixes bug where PENDING batches with today's start date were not appearing
in the dashboard production timeline.
2025-11-08 07:37:12 +00:00
Claude
ed7db4d4f2 feat: Complete backend i18n implementation with error codes and demo data
Demo Seed Scripts:
- Updated seed_demo_purchase_orders.py to use structured reasoning_data
  * Imports create_po_reasoning_low_stock and create_po_reasoning_supplier_contract
  * Generates reasoning_data with product names, stock levels, and consequences
  * Removed deprecated reasoning/consequence TEXT fields
- Updated seed_demo_batches.py to use structured reasoning_data
  * Imports create_batch_reasoning_forecast_demand and create_batch_reasoning_regular_schedule
  * Generates intelligent reasoning based on batch priority and AI assistance
  * Adds reasoning_data to all production batches

Backend Services - Error Code Implementation:
- Updated safety_stock_calculator.py with error codes
  * Replaced "Lead time or demand std dev is zero or negative" with ERROR:LEAD_TIME_INVALID
  * Replaced "Insufficient historical demand data" with ERROR:INSUFFICIENT_DATA
- Updated replenishment_planning_service.py with error codes
  * Replaced "Insufficient data for safety stock calculation" with ERROR:INSUFFICIENT_DATA
  * Frontend can now translate error codes using i18n

Demo data will now display with translatable reasoning in EN/ES/EU languages.
Backend services return error codes that frontend translates for user's language.
2025-11-07 18:40:44 +00:00
Claude
f74b8d5402 refactor: Remove TEXT fields and use only reasoning_data for i18n
Completed the migration to structured reasoning_data for multilingual
dashboard support. Removed hardcoded TEXT fields (reasoning, consequence)
and updated all related code to use JSONB reasoning_data.

Changes:

1. Models Updated (removed TEXT fields):
   - PurchaseOrder: Removed reasoning, consequence TEXT columns
   - ProductionBatch: Removed reasoning TEXT column
   - Both now use only reasoning_data (JSONB/JSON)

2. Dashboard Service Updated:
   - Changed to return reasoning_data instead of TEXT fields
   - Creates default reasoning_data if missing
   - PO actions: reasoning_data with type and parameters
   - Production timeline: reasoning_data for each batch

3. Unified Schemas Updated (no separate migration):
   - services/procurement/migrations/001_unified_initial_schema.py
   - services/production/migrations/001_unified_initial_schema.py
   - Removed reasoning/consequence columns from table definitions
   - Updated comments to reflect i18n approach

Database Schema:
- purchase_orders: Only reasoning_data (JSONB)
- production_batches: Only reasoning_data (JSON)

Backend now generates:
{
  "type": "low_stock_detection",
  "parameters": {
    "supplier_name": "Harinas del Norte",
    "days_until_stockout": 3,
    ...
  },
  "consequence": {
    "type": "stockout_risk",
    "severity": "high"
  }
}

Next Steps:
- Frontend: Create i18n translation keys
- Frontend: Update components to translate reasoning_data
- Test multilingual support (ES, EN, CA)
2025-11-07 18:20:05 +00:00
Claude
ddc4928d78 feat: Implement structured reasoning_data generation for i18n support
Implemented proper reasoning data generation for purchase orders and
production batches to enable multilingual dashboard support.

Backend Strategy:
- Generate structured JSON with type codes and parameters
- Store only reasoning_data (JSONB), not hardcoded text
- Frontend will translate using i18n libraries

Changes:
1. Created shared/schemas/reasoning_types.py
   - Defined reasoning types for POs and batches
   - Created helper functions for common reasoning patterns
   - Supports multiple reasoning types (low_stock, forecast_demand, etc.)

2. Production Service (services/production/app/services/production_service.py)
   - Generate reasoning_data when creating batches from forecast
   - Include parameters: product_name, predicted_demand, current_stock, etc.
   - Structure supports frontend i18n interpolation

3. Procurement Service (services/procurement/app/services/procurement_service.py)
   - Implemented actual PO creation (was placeholder before!)
   - Groups requirements by supplier
   - Generates reasoning_data based on context (low_stock vs forecast)
   - Creates PO items automatically

Example reasoning_data:
{
  "type": "low_stock_detection",
  "parameters": {
    "supplier_name": "Harinas del Norte",
    "product_names": ["Flour Type 55", "Flour Type 45"],
    "days_until_stockout": 3,
    "current_stock": 45.5,
    "required_stock": 200
  },
  "consequence": {
    "type": "stockout_risk",
    "severity": "high",
    "impact_days": 3
  }
}

Frontend will translate:
- EN: "Low stock detected for Harinas del Norte. Stock runs out in 3 days."
- ES: "Stock bajo detectado para Harinas del Norte. Se agota en 3 días."
- CA: "Estoc baix detectat per Harinas del Norte. S'esgota en 3 dies."

Next steps:
- Remove TEXT fields (reasoning, consequence) from models
- Update dashboard service to use reasoning_data
- Create frontend i18n translation keys
- Update dashboard components to translate dynamically
2025-11-07 18:16:44 +00:00
Claude
392bfb186f refactor: Unify database migrations into single initial schemas
Consolidated incremental migrations into single unified initial schema files for both procurement and production services. This simplifies database setup and eliminates migration chain complexity.

Changes:
- Procurement: Merged 3 migrations into 001_unified_initial_schema.py
  - Initial schema (20251015_1229)
  - Add supplier_price_list_id (20251030_0737)
  - Add JTBD reasoning fields (20251107)

- Production: Merged 3 migrations into 001_unified_initial_schema.py
  - Initial schema (20251015_1231)
  - Add waste tracking fields (20251023_0900)
  - Add JTBD reasoning fields (20251107)

All new fields (reasoning, consequence, reasoning_data, waste_defect_type, is_ai_assisted, supplier_price_list_id) are now included in the initial schemas from the start.

Updated model files to use deferred() for reasoning fields to prevent breaking queries when running against existing databases.
2025-11-07 17:35:38 +00:00
Claude
436622dc9a fix: Resolve build errors and add database migrations
- Fix frontend import: Change from useAppContext to useTenant store
- Fix backend imports: Use app.core.database instead of shared.database
- Remove auth dependencies from dashboard endpoints
- Add database migrations for reasoning fields in procurement and production

Migrations:
- procurement: Add reasoning, consequence, reasoning_data to purchase_orders
- production: Add reasoning, reasoning_data to production_batches
2025-11-07 17:19:46 +00:00
Claude
2ced1ec670 feat: Complete JTBD-aligned bakery dashboard redesign
Implements comprehensive dashboard redesign based on Jobs To Be Done methodology
focused on answering: "What requires my attention right now?"

## Backend Implementation

### Dashboard Service (NEW)
- Health status calculation (green/yellow/red traffic light)
- Action queue prioritization (critical/important/normal)
- Orchestration summary with narrative format
- Production timeline transformation
- Insights calculation and consequence prediction

### API Endpoints (NEW)
- GET /dashboard/health-status - Overall bakery health indicator
- GET /dashboard/orchestration-summary - What system did automatically
- GET /dashboard/action-queue - Prioritized tasks requiring attention
- GET /dashboard/production-timeline - Today's production schedule
- GET /dashboard/insights - Key metrics (savings, inventory, waste, deliveries)

### Enhanced Models
- PurchaseOrder: Added reasoning, consequence, reasoning_data fields
- ProductionBatch: Added reasoning, reasoning_data fields
- Enables transparency into automation decisions

## Frontend Implementation

### API Hooks (NEW)
- useBakeryHealthStatus() - Real-time health monitoring
- useOrchestrationSummary() - System transparency
- useActionQueue() - Prioritized action management
- useProductionTimeline() - Production tracking
- useInsights() - Glanceable metrics

### Dashboard Components (NEW)
- HealthStatusCard: Traffic light indicator with checklist
- ActionQueueCard: Prioritized actions with reasoning/consequences
- OrchestrationSummaryCard: Narrative of what system did
- ProductionTimelineCard: Chronological production view
- InsightsGrid: 2x2 grid of key metrics

### Main Dashboard Page (REPLACED)
- Complete rewrite with mobile-first design
- All sections integrated with error handling
- Real-time refresh and quick action links
- Old dashboard backed up as DashboardPage.legacy.tsx

## Key Features

### Automation-First
- Shows what orchestrator did overnight
- Builds trust through transparency
- Explains reasoning for all automated decisions

### Action-Oriented
- Prioritizes tasks over information display
- Clear consequences for each action
- Large touch-friendly buttons

### Progressive Disclosure
- Shows 20% of info that matters 80% of time
- Expandable details when needed
- No overwhelming metrics

### Mobile-First
- One-handed operation
- Large touch targets (min 44px)
- Responsive grid layouts

### Trust-Building
- Narrative format ("I planned your day")
- Reasoning inputs transparency
- Clear status indicators

## User Segments Supported

1. Solo Bakery Owner (Primary)
   - Simple health indicator
   - Action checklist (max 3-5 items)
   - Mobile-optimized

2. Multi-Location Owner
   - Multi-tenant support (existing)
   - Comparison capabilities
   - Delegation ready

3. Enterprise/Central Bakery (Future)
   - Network topology support
   - Advanced analytics ready

## JTBD Analysis Delivered

Main Job: "Help me quickly understand bakery status and know what needs my intervention"

Emotional Jobs Addressed:
- Feel in control despite automation
- Reduce daily anxiety
- Feel competent with technology
- Trust system as safety net

Social Jobs Addressed:
- Demonstrate professional management
- Avoid being bottleneck
- Show sustainability

## Technical Stack

Backend: Python, FastAPI, SQLAlchemy, PostgreSQL
Frontend: React, TypeScript, TanStack Query, Tailwind CSS
Architecture: Microservices with circuit breakers

## Breaking Changes

- Complete dashboard page rewrite (old version backed up)
- New API endpoints require orchestrator service deployment
- Database migrations needed for reasoning fields

## Migration Required

Run migrations to add new model fields:
- purchase_orders: reasoning, consequence, reasoning_data
- production_batches: reasoning, reasoning_data

## Documentation

See DASHBOARD_REDESIGN_SUMMARY.md for complete implementation details,
JTBD analysis, success metrics, and deployment guide.

BREAKING CHANGE: Dashboard page completely redesigned with new data structures
2025-11-07 17:10:17 +00:00
Urtzi Alfaro
813e8866ef Add readme files 2025-11-06 14:10:04 +01:00
Urtzi Alfaro
394ad3aea4 Improve AI logic 2025-11-05 13:34:56 +01:00
Urtzi Alfaro
5adb0e39c0 Improve the frontend 5 2025-11-02 20:24:44 +01:00
Urtzi Alfaro
f44d235c6d Add user delete process 2 2025-10-31 18:57:58 +01:00
Urtzi Alfaro
269d3b5032 Add user delete process 2025-10-31 11:54:19 +01:00
Urtzi Alfaro
63f5c6d512 Improve the frontend 3 2025-10-30 21:08:07 +01:00
Urtzi Alfaro
36217a2729 Improve the frontend 2 2025-10-29 06:58:05 +01:00
Urtzi Alfaro
61376b7a9f Improve the frontend and fix TODOs 2025-10-24 13:05:04 +02:00
Urtzi Alfaro
07c33fa578 Improve the frontend and repository layer 2025-10-23 07:44:54 +02:00
Urtzi Alfaro
05da20357d Improve teh securty of teh DB 2025-10-19 19:22:37 +02:00
Urtzi Alfaro
312e36c893 Update requirements and insfra versions 2025-10-17 23:09:40 +02:00
Urtzi Alfaro
d4060962e4 Improve demo seed 2025-10-17 07:31:14 +02:00
Urtzi Alfaro
8f9e9a7edc Add role-based filtering and imporve code 2025-10-15 16:12:49 +02:00
Urtzi Alfaro
7556a00db7 Improve the demo feature of the project 2025-10-12 18:47:33 +02:00
Urtzi Alfaro
dbc7f2fa0d Re-create migrations init tables 2025-10-09 20:47:31 +02:00
Urtzi Alfaro
b420af32c5 REFACTOR production scheduler 2025-10-09 18:01:24 +02:00
Urtzi Alfaro
38fb98bc27 REFACTOR ALL APIs 2025-10-06 15:27:01 +02:00
Urtzi Alfaro
0fdc3b0211 Fix issues 2025-10-01 16:25:53 +02:00
Urtzi Alfaro
2eeebfc1e0 Fix Alembic issue 2025-10-01 11:24:06 +02:00
Urtzi Alfaro
7cc4b957a5 Fix DB issue 2s 2025-09-30 21:58:10 +02:00
Urtzi Alfaro
147893015e Fix DB issues 2025-09-30 13:32:51 +02:00
Urtzi Alfaro
ec6bcb4c7d Add migration services 2025-09-30 08:12:45 +02:00
Urtzi Alfaro
2712a60a2a Refactor services alembic 2025-09-29 19:16:34 +02:00
Urtzi Alfaro
befcc126b0 Refactor all main.py 2025-09-29 13:13:12 +02:00
Urtzi Alfaro
3816383760 Add base kubernetes support final 2025-09-28 13:54:28 +02:00
Urtzi Alfaro
63a3f9c77a Add base kubernetes support 2025-09-27 11:18:13 +02:00
Urtzi Alfaro
a27f159e24 Fix few issues 2025-09-26 12:12:17 +02:00
Urtzi Alfaro
cf4405b771 Fix production deadlock 2025-09-25 21:00:40 +02:00
Urtzi Alfaro
c75aed9dfe Fix schedulers of teh production service 2025-09-25 14:49:42 +02:00
Urtzi Alfaro
89b75bd7af Support subcription payments 2025-09-25 14:30:47 +02:00
Urtzi Alfaro
dc6c6f213f Fix some UI issues 2 2025-09-24 21:54:49 +02:00
Urtzi Alfaro
2de1e6ce40 Add quality template logic 2025-09-24 16:42:23 +02:00
Urtzi Alfaro
7892c5a739 Add improved production UI 3 2025-09-23 19:24:22 +02:00
Urtzi Alfaro
4ae8e14e55 Add improved production UI 2025-09-23 12:49:35 +02:00
Urtzi Alfaro
13ca3e90b4 Improve the production frontend 2025-09-21 07:45:19 +02:00
Urtzi Alfaro
ae77a0e1c5 Improve the inventory page 3 2025-09-18 08:06:32 +02:00
Urtzi Alfaro
0faaa25e58 Start integrating the onboarding flow with backend 3 2025-09-04 23:19:53 +02:00
Urtzi Alfaro
b7eb4888a6 Update frontend 2025-08-23 16:30:45 +02:00
Urtzi Alfaro
4b4268d640 Add new alert architecture 2025-08-23 10:19:58 +02:00
Urtzi Alfaro
90100a66c6 Delete legacy alerts 2025-08-22 15:31:52 +02:00
Urtzi Alfaro
c6dd6fd1de Add more services 2025-08-21 20:28:14 +02:00