@@ -169,35 +169,49 @@ class OperationModel extends Equatable {
|
||||
|
||||
factory OperationModel.fromMap(Map<String, dynamic> map) {
|
||||
return OperationModel(
|
||||
id: map['id'],
|
||||
id: map['id'] as String?,
|
||||
createdAt: map['created_at'] != null
|
||||
? DateTime.parse(map['created_at'])
|
||||
: null,
|
||||
type: map['type'] as String? ?? '',
|
||||
subtype: map['sub_type'] as String?,
|
||||
providerId: map['provider_id'] as String? ?? '',
|
||||
providerDisplayName: "${map['provider']['name']}".myFormat(),
|
||||
modelId: map['model_id'] as String? ?? '',
|
||||
modelDisplayName: "${map['model']['name_with_brand'] ?? ''}".myFormat(),
|
||||
description: map['description'] as String? ?? '',
|
||||
|
||||
// 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(),
|
||||
|
||||
modelId: map['model_id'] as String?,
|
||||
modelDisplayName: (map['model']?['name_with_brand'] as String?)
|
||||
?.myFormat(),
|
||||
|
||||
description: map['description'] as String?,
|
||||
expirationDate: map['expiration_date'] != null
|
||||
? DateTime.parse(map['expiration_date'])
|
||||
: null,
|
||||
note: map['note'] as String? ?? '',
|
||||
showInDashboard: map['show_in_dashboard'] as bool,
|
||||
batchUuid: map['batch_uuid'] as String,
|
||||
showInDashboard: map['show_in_dashboard'] as bool? ?? true,
|
||||
batchUuid: map['batch_uuid'] as String? ?? '',
|
||||
companyId: map['company_id'] as String,
|
||||
storeId: map['store_id'] as String? ?? '',
|
||||
storeDisplayName: "${map['store']['name']}".myFormat(),
|
||||
|
||||
storeId:
|
||||
map['store_id'] as String? ??
|
||||
'', // Questo è non-nullable nella tua classe
|
||||
storeDisplayName: (map['store']?['name'] as String?)?.myFormat(),
|
||||
|
||||
quantity: map['quantity'] is int
|
||||
? map['quantity']
|
||||
: int.tryParse(map['quantity']?.toString() ?? '0') ?? 0,
|
||||
staffId: map['staff_id'] as String? ?? '',
|
||||
staffDisplayName: "${map['staff_member']['name'] ?? ''}".myFormat(),
|
||||
lastCampaignId: map['last_campaign_id'] as String? ?? '',
|
||||
status: OperationStatus.fromString(map['status']),
|
||||
customerId: map['customer_id'] as String? ?? '',
|
||||
customerDisplayName: "${map['customer']['name'] ?? ''}".myFormat(),
|
||||
: int.tryParse(map['quantity']?.toString() ?? '1') ?? 1,
|
||||
|
||||
staffId: map['staff_id'] as String?,
|
||||
staffDisplayName: (map['staff_member']?['name'] as String?)?.myFormat(),
|
||||
|
||||
lastCampaignId: map['last_campaign_id'] as String?,
|
||||
status: OperationStatus.fromString(map['status'] ?? 'draft'),
|
||||
|
||||
customerId: map['customer_id'] as String?,
|
||||
customerDisplayName: (map['customer']?['name'] as String?)?.myFormat(),
|
||||
|
||||
attachments:
|
||||
(map['attachment'] as List?)
|
||||
?.map((x) => AttachmentModel.fromMap(x))
|
||||
|
||||
Reference in New Issue
Block a user