added singleUserMode and removed StaffSection from forms
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/features/customers/models/customer_model.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/operations/data/operations_repository.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
@@ -13,22 +14,20 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
final OperationsRepository _repository = GetIt.I<OperationsRepository>();
|
||||
final SessionCubit _sessionCubit = GetIt.I<SessionCubit>();
|
||||
final Uuid _uuid = const Uuid();
|
||||
final String createdById;
|
||||
final String createdByName;
|
||||
|
||||
OperationFormCubit({required this.createdById, required this.createdByName})
|
||||
: super(
|
||||
OperationFormState(
|
||||
// Inizializziamo con un modello vuoto di sicurezza
|
||||
operation: OperationModel(
|
||||
storeId: '',
|
||||
companyId: '',
|
||||
reference: '',
|
||||
status: OperationStatus.draft,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
),
|
||||
);
|
||||
OperationFormCubit({
|
||||
StaffMemberModel? createdBy,
|
||||
OperationModel? existingOperation,
|
||||
}) : super(
|
||||
OperationFormState(
|
||||
operation:
|
||||
existingOperation ??
|
||||
OperationModel.empty().copyWith(
|
||||
staffId: createdBy?.id,
|
||||
staffDisplayName: createdBy?.name,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> initForm({
|
||||
OperationModel? existingOperation,
|
||||
@@ -45,26 +44,37 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
),
|
||||
);
|
||||
} else if (operationId != null) {
|
||||
// Avendo separato i cubit, se ci passano solo l'ID lo scarichiamo dal DB
|
||||
final operation = await _repository.fetchOperationById(operationId);
|
||||
emit(
|
||||
state.copyWith(
|
||||
operation: operation,
|
||||
status: OperationFormStatus.ready,
|
||||
),
|
||||
);
|
||||
emit(state.copyWith(status: OperationFormStatus.loading));
|
||||
try {
|
||||
final operation = await _repository.fetchOperationById(operationId);
|
||||
emit(
|
||||
state.copyWith(
|
||||
operation: operation,
|
||||
status: OperationFormStatus.ready,
|
||||
),
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: OperationFormStatus.failure,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// NUOVA PRATICA: Creiamo un nuovo Batch UUID
|
||||
final currentStore = _sessionCubit.state.currentStore;
|
||||
final companyId = _sessionCubit.state.company?.id ?? '';
|
||||
final newOperation = state.operation.copyWith(
|
||||
companyId: companyId,
|
||||
storeId: currentStore?.id,
|
||||
status: OperationStatus.success,
|
||||
reference: '',
|
||||
batchUuid: _uuid.v4(),
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
operation: OperationModel(
|
||||
storeId: _sessionCubit.state.currentStore?.id ?? '',
|
||||
reference: '',
|
||||
createdAt: DateTime.now(),
|
||||
companyId: _sessionCubit.state.company!.id!,
|
||||
status: OperationStatus.draft,
|
||||
batchUuid: _uuid.v4(),
|
||||
),
|
||||
operation: newOperation,
|
||||
status: OperationFormStatus.ready,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user