enhance: Enhances picking data and persistence
Fetches detailed move line and move data, including product information, for stock picking records from the API. Centralizes ObjectBox persistence within `toEntity()` methods for product, move line, and move models, ensuring data is saved upon conversion. Correctly associates product entities with move line and move entities in the local database. Refactors API call processing to directly return mapped entities, leveraging the updated `toEntity()` behavior.
This commit is contained in:
parent
9dad7f9d9f
commit
60d959eb79
@ -133,6 +133,28 @@ class ApiCalls {
|
||||
"activity_exception_decoration": {},
|
||||
"activity_exception_icon": {},
|
||||
"json_popover": {},
|
||||
"move_line_ids_without_package": {
|
||||
"fields": {
|
||||
"product_id": {
|
||||
"fields": {"display_name": {}, "barcode": {}},
|
||||
},
|
||||
"quantity": {}, // quantité
|
||||
},
|
||||
},
|
||||
"move_ids_without_package": {
|
||||
"fields": {
|
||||
"product_id": {
|
||||
"fields": {"display_name": {}, "barcode": {}},
|
||||
},
|
||||
"quantity": {}, // quantité
|
||||
"product_uom_qty": {}, //quantité demandé
|
||||
},
|
||||
"context": {
|
||||
"form_view_ref": "stock.view_stock_move_operations",
|
||||
},
|
||||
"limit": 40,
|
||||
"order": "",
|
||||
},
|
||||
},
|
||||
"offset": 0,
|
||||
"order": "",
|
||||
@ -166,10 +188,8 @@ class ApiCalls {
|
||||
final recordsModel =
|
||||
result.result?.records ?? <StockPickingRecordModel>[];
|
||||
// add data to local
|
||||
for (var rec in recordsModel) {
|
||||
rec.toEntity();
|
||||
}
|
||||
return Result.success(stockPickingRecords.getAll());
|
||||
final records = recordsModel.map((e) => e.toEntity()).toList();
|
||||
return Result.success(records);
|
||||
} else {
|
||||
return Result.error(Error(data['error']));
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:e_scan/backend/objectbox/entities/product/product_entity.dart';
|
||||
import 'package:e_scan/backend/objectbox/objectbox_manager.dart';
|
||||
import 'package:e_scan/utils/utils.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
@ -19,6 +20,13 @@ abstract class ProductModel with _$ProductModel {
|
||||
}
|
||||
|
||||
extension ProductModelExt on ProductModel {
|
||||
ProductEntity get toEntity =>
|
||||
ProductEntity(id: id ?? 0, displayName: displayName, barcode: barcode);
|
||||
ProductEntity toEntity() {
|
||||
final entity = ProductEntity(
|
||||
id: id ?? 0,
|
||||
displayName: displayName,
|
||||
barcode: barcode,
|
||||
);
|
||||
objectboxManager.store.box<ProductEntity>().put(entity);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
@ -236,6 +236,7 @@ extension MoveLineWithoutPackageModelToEntity on MoveLineWithoutPackageModel {
|
||||
id: id ?? 0,
|
||||
quantity: quantity,
|
||||
);
|
||||
entity.productId.target = productId?.toEntity();
|
||||
objectboxManager.store.box<MoveLineWithoutPackageEntity>().put(entity);
|
||||
return entity;
|
||||
}
|
||||
@ -248,6 +249,7 @@ extension MoveWithoutPackageModelToEntity on MoveWithoutPackageModel {
|
||||
quantity: quantity,
|
||||
productUomQty: productUomQty,
|
||||
);
|
||||
entity.productId.target = productId?.toEntity();
|
||||
objectboxManager.store.box<MoveWithoutPackageEntity>().put(entity);
|
||||
return entity;
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ class _ScannerPageState extends ConsumerState<ScannerPage>
|
||||
);
|
||||
Box<ProductEntity> productStore = objectboxManager.store
|
||||
.box<ProductEntity>();
|
||||
productStore.put(productStruct.toEntity);
|
||||
productStore.put(productStruct.toEntity());
|
||||
//show dialog
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
@ -185,7 +185,7 @@ class _ScannerPageState extends ConsumerState<ScannerPage>
|
||||
);
|
||||
Box<ProductEntity> productStore = objectboxManager.store
|
||||
.box<ProductEntity>();
|
||||
productStore.put(productStruct.toEntity);
|
||||
productStore.put(productStruct.toEntity());
|
||||
//show dialog
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user