This commit is contained in:
2026-05-27 16:00:50 +02:00
parent f6ecb33729
commit b6e5f9acbe
8 changed files with 232 additions and 134 deletions

View File

@@ -1,4 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:flux/core/enums_and_consts/consts.dart';
import 'package:flux/core/utils/extensions.dart';
import 'package:flux/features/attachments/models/attachment_model.dart';
import 'package:flux/features/customers/models/customer_model.dart';
@@ -184,10 +185,11 @@ class OperationModel extends Equatable {
// I campi relazionali nullabili restano rigorosamente null!
providerId: map['provider_id'] as String?,
// MAGIA ANTI-CRASH: Usiamo ?['chiave'] per non far esplodere i join vuoti
providerDisplayName: (map['provider']?['name'] as String?)?.myFormat(),
providerDisplayName: (map[Tables.providers]?['name'] as String?)
?.myFormat(),
modelId: map['model_id'] as String?,
modelDisplayName: (map['model']?['name_with_brand'] as String?)
modelDisplayName: (map[Tables.models]?['name_with_brand'] as String?)
?.myFormat(),
description: map['description'] as String?,
@@ -202,25 +204,26 @@ class OperationModel extends Equatable {
storeId:
map['store_id'] as String? ??
'', // Questo è non-nullable nella tua classe
storeDisplayName: (map['store']?['name'] as String?)?.myFormat(),
storeDisplayName: (map[Tables.stores]?['name'] as String?)?.myFormat(),
quantity: map['quantity'] is int
? map['quantity']
: int.tryParse(map['quantity']?.toString() ?? '1') ?? 1,
staffId: map['staff_id'] as String?,
staffDisplayName: (map['staff_member']?['name'] as String?)?.myFormat(),
staffDisplayName: (map[Tables.staffMembers]?['name'] as String?)
?.myFormat(),
lastCampaignId: map['last_campaign_id'] as String?,
status: OperationStatus.fromString(map['status'] ?? 'draft'),
customerId: map['customer_id'] as String?,
customer: map['customer'] != null
? CustomerModel.fromMap(map['customer'] as Map<String, dynamic>)
customer: map[Tables.customers] != null
? CustomerModel.fromMap(map[Tables.customers] as Map<String, dynamic>)
: null,
attachments:
(map['attachment'] as List?)
(map[Tables.attachments] as List?)
?.map((x) => AttachmentModel.fromMap(x))
.toList() ??
const [],