Fix new services implementation 3

This commit is contained in:
Urtzi Alfaro
2025-08-14 16:47:34 +02:00
parent 0951547e92
commit 03737430ee
51 changed files with 657 additions and 982 deletions

View File

@@ -163,7 +163,8 @@ export const useForecast = () => {
tenantId: string,
format: 'csv' | 'excel' | 'json',
params?: {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility
start_date?: string;
end_date?: string;
}

View File

@@ -91,7 +91,8 @@ export class ForecastingService {
async getForecasts(
tenantId: string,
params?: BaseQueryParams & {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility - will need inventory service lookup
start_date?: string;
end_date?: string;
model_id?: string;
@@ -158,7 +159,8 @@ export class ForecastingService {
}
return forecastsArray.map((forecast: any) => ({
product_name: forecast.product_name,
inventory_product_id: forecast.inventory_product_id,
product_name: forecast.product_name, // Optional - for display
next_day_prediction: forecast.predicted_demand || 0,
next_week_avg: forecast.predicted_demand || 0,
trend_direction: 'stable' as const,
@@ -168,9 +170,10 @@ export class ForecastingService {
} catch (error) {
console.error('QuickForecasts API call failed, using fallback data:', error);
// Return mock data for common bakery products
// Return mock data for common bakery products (using mock inventory_product_ids)
return [
{
inventory_product_id: 'mock-pan-de-molde-001',
product_name: 'Pan de Molde',
next_day_prediction: 25,
next_week_avg: 175,
@@ -179,6 +182,7 @@ export class ForecastingService {
last_updated: new Date().toISOString()
},
{
inventory_product_id: 'mock-baguettes-002',
product_name: 'Baguettes',
next_day_prediction: 20,
next_week_avg: 140,
@@ -187,6 +191,7 @@ export class ForecastingService {
last_updated: new Date().toISOString()
},
{
inventory_product_id: 'mock-croissants-003',
product_name: 'Croissants',
next_day_prediction: 15,
next_week_avg: 105,
@@ -195,6 +200,7 @@ export class ForecastingService {
last_updated: new Date().toISOString()
},
{
inventory_product_id: 'mock-magdalenas-004',
product_name: 'Magdalenas',
next_day_prediction: 12,
next_week_avg: 84,
@@ -244,7 +250,8 @@ export class ForecastingService {
tenantId: string,
format: 'csv' | 'excel' | 'json',
params?: {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility
start_date?: string;
end_date?: string;
}
@@ -272,7 +279,8 @@ export class ForecastingService {
async getForecastAccuracy(
tenantId: string,
params?: {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility
model_id?: string;
start_date?: string;
end_date?: string;
@@ -280,7 +288,8 @@ export class ForecastingService {
): Promise<{
overall_accuracy: number;
product_accuracy: Array<{
product_name: string;
inventory_product_id: string;
product_name?: string; // Optional - for display
accuracy: number;
sample_size: number;
}>;

View File

@@ -139,7 +139,8 @@ export class SalesService {
params?: {
start_date?: string;
end_date?: string;
product_names?: string[];
inventory_product_ids?: string[]; // Primary way to filter by products
product_names?: string[]; // For backward compatibility - will need inventory service lookup
metrics?: string[];
}
): Promise<any> {

View File

@@ -176,7 +176,8 @@ export interface PurchaseOrderItem {
price_list_item_id?: string;
ingredient_id: string;
product_code?: string;
product_name: string;
inventory_product_id: string; // Reference to inventory service product
product_name?: string; // Optional - for display, populated by frontend from inventory service
ordered_quantity: number;
unit_of_measure: string;
unit_price: number;
@@ -207,7 +208,8 @@ export interface CreatePurchaseOrderRequest {
items: {
ingredient_id: string;
product_code?: string;
product_name: string;
inventory_product_id: string; // Reference to inventory service product
product_name?: string; // Optional - for backward compatibility
ordered_quantity: number;
unit_of_measure: string;
unit_price: number;
@@ -268,7 +270,8 @@ export interface DeliveryItem {
delivery_id: string;
purchase_order_item_id: string;
ingredient_id: string;
product_name: string;
inventory_product_id: string; // Reference to inventory service product
product_name?: string; // Optional - for display, populated by frontend from inventory service
ordered_quantity: number;
delivered_quantity: number;
accepted_quantity: number;

View File

@@ -101,7 +101,8 @@ export class TrainingService {
async getModels(
tenantId: string,
params?: BaseQueryParams & {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility - will need inventory service lookup
is_active?: boolean;
}
): Promise<PaginatedResponse<ModelInfo>> {

View File

@@ -9,8 +9,10 @@ export interface SalesData {
id: string;
tenant_id: string;
date: string;
product_name: string;
category?: string;
inventory_product_id: string; // Reference to inventory service product
// Note: product_name now needs to be fetched from inventory service using inventory_product_id
product_name?: string; // Optional - for backward compatibility, populated by frontend logic
category?: string; // Optional - fetched from inventory service
quantity: number;
unit_price: number;
total_revenue: number;
@@ -55,7 +57,9 @@ export interface SalesDataQuery extends BaseQueryParams {
tenant_id: string;
start_date?: string;
end_date?: string;
product_names?: string[];
// Note: product_names filtering now requires inventory service integration or use inventory_product_ids
product_names?: string[]; // For backward compatibility - will need inventory service lookup
inventory_product_ids?: string[]; // Primary way to filter by products
location_ids?: string[];
sources?: string[];
min_quantity?: number;
@@ -64,7 +68,7 @@ export interface SalesDataQuery extends BaseQueryParams {
max_revenue?: number;
search_term?: string;
sales_channel?: string;
inventory_product_id?: string;
inventory_product_id?: string; // Single product filter
is_validated?: boolean;
}
@@ -115,7 +119,8 @@ export interface DashboardStats {
}
export interface ProductStats {
product_name: string;
inventory_product_id: string; // Reference to inventory service product
product_name?: string; // Optional - for display, populated by frontend from inventory service
total_quantity: number;
total_revenue: number;
avg_price: number;

View File

@@ -6,7 +6,7 @@
import { ExternalFactors } from './data';
export interface SingleForecastRequest {
product_name: string;
inventory_product_id: string;
forecast_date: string;
forecast_days: number;
location: string;
@@ -16,7 +16,8 @@ export interface SingleForecastRequest {
}
export interface BatchForecastRequest {
product_names?: string[];
inventory_product_ids?: string[]; // Primary way to specify products
product_names?: string[]; // For backward compatibility - will need inventory service lookup
forecast_date: string;
forecast_days: number;
location: string;
@@ -28,7 +29,8 @@ export interface BatchForecastRequest {
export interface ForecastResponse {
id: string;
tenant_id: string;
product_name: string;
inventory_product_id: string;
product_name?: string; // Optional - for display, populated by frontend from inventory service
forecast_date: string;
predicted_demand: number;
confidence_lower?: number;
@@ -77,7 +79,8 @@ export interface ForecastAlert {
}
export interface QuickForecast {
product_name: string;
inventory_product_id: string;
product_name?: string; // Optional - for display, populated by frontend from inventory service
next_day_prediction: number;
next_week_avg: number;
trend_direction: 'up' | 'down' | 'stable';

View File

@@ -14,7 +14,7 @@ export interface TrainingJobRequest {
}
export interface SingleProductTrainingRequest {
product_name: string;
inventory_product_id: string;
config?: TrainingJobConfig;
priority?: number;
}
@@ -81,11 +81,12 @@ export interface TrainingJobResults {
total_training_time_seconds: number;
average_model_accuracy?: number;
trained_models: TrainedModelInfo[];
failed_products?: string[];
failed_products?: string[]; // inventory_product_ids of failed products
}
export interface TrainedModelInfo {
product_name: string;
inventory_product_id: string;
product_name?: string; // Optional - for display, populated by frontend from inventory service
model_id: string;
model_type: string;
accuracy_metrics: TrainingMetrics;
@@ -107,7 +108,8 @@ export interface TrainingMetrics {
export interface ModelInfo {
model_id: string;
tenant_id: string;
product_name: string;
inventory_product_id: string;
product_name?: string; // Optional - for display, populated by frontend from inventory service
model_type: string;
model_path: string;
version: number;