
Moves product lookup from external API calls to a local ObjectBox database. This improves performance and enables offline product identification during scanning. Removes the standalone scanner page, consolidating barcode scanning functionality directly into the reception flow for a more streamlined user experience. Updates ObjectBox entity fields by removing `final` modifiers, allowing the database to manage and update persisted data effectively. Introduces new methods in the reception scan model to support local product checks, retrieval, and quantity increment for scanned items.
88 lines
2.9 KiB
Dart
88 lines
2.9 KiB
Dart
import 'package:e_scan/backend/objectbox/entities/product/product_entity.dart';
|
|
import 'package:e_scan/backend/objectbox/entities/stock_picking/stock_picking_record_entity.dart';
|
|
import 'package:e_scan/backend/objectbox/objectbox_manager.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
|
|
part 'reception_scan_page_model.freezed.dart';
|
|
|
|
final receptionScanPageModelProvider =
|
|
StateNotifierProvider.autoDispose<
|
|
ReceptionScanPageModel,
|
|
ReceptionScanPageModelState
|
|
>((ref) {
|
|
return ReceptionScanPageModel();
|
|
});
|
|
|
|
class ReceptionScanPageModel
|
|
extends StateNotifier<ReceptionScanPageModelState> {
|
|
ReceptionScanPageModel() : super(const ReceptionScanPageModelState());
|
|
|
|
Future getReceptionById({required int id}) async {
|
|
try {
|
|
final stockPickingRecords = objectboxManager.store
|
|
.box<StockPickingRecordEntity>();
|
|
state = state.copyWith(loading: true);
|
|
final entity = stockPickingRecords.get(id);
|
|
state = state.copyWith(loading: false, reception: entity);
|
|
} catch (e) {
|
|
state = state.copyWith(loading: false);
|
|
}
|
|
}
|
|
|
|
bool isProductExist({required String barcode}) {
|
|
final productBox = objectboxManager.store.box<ProductEntity>();
|
|
return productBox
|
|
.query(ProductEntity_.barcode.equals(barcode))
|
|
.build()
|
|
.findFirst() !=
|
|
null;
|
|
}
|
|
|
|
ProductEntity? getProduct({required String barcode}) {
|
|
final productBox = objectboxManager.store.box<ProductEntity>();
|
|
return productBox
|
|
.query(ProductEntity_.barcode.equals(barcode))
|
|
.build()
|
|
.findFirst();
|
|
}
|
|
|
|
void incrementMoveLineQuantity({required String barcode}) {
|
|
final moveLineBox = objectboxManager.store
|
|
.box<MoveLineWithoutPackageEntity>();
|
|
final productBox = objectboxManager.store.box<ProductEntity>();
|
|
final productEntity = productBox
|
|
.query(ProductEntity_.barcode.equals(barcode))
|
|
.build()
|
|
.findFirst();
|
|
final productId = productEntity?.id;
|
|
if (productId != null) {
|
|
final moveLineEntity = moveLineBox
|
|
.query(MoveLineWithoutPackageEntity_.productId.equals(productId))
|
|
.build()
|
|
.findFirst();
|
|
if (moveLineEntity != null) {
|
|
moveLineEntity.quantity = (moveLineEntity.quantity ?? 0) + 1;
|
|
moveLineBox.put(moveLineEntity);
|
|
}
|
|
}
|
|
}
|
|
|
|
Future handleBarcode({required BarcodeCapture barcodeCapture}) async {
|
|
try {
|
|
final stockPickingRecords = objectboxManager.store
|
|
.box<StockPickingRecordEntity>();
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
|
|
@freezed
|
|
abstract class ReceptionScanPageModelState with _$ReceptionScanPageModelState {
|
|
const factory ReceptionScanPageModelState({
|
|
StockPickingRecordEntity? reception,
|
|
@Default(false) bool loading,
|
|
}) = _ReceptionScanPageModelState;
|
|
}
|