feat: enhance inventory management with category and location filters
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -2,6 +2,8 @@ class InventoryItem {
|
||||
final int id;
|
||||
final int productId;
|
||||
final String productName;
|
||||
final String? productCanonicalName;
|
||||
final String? categoryPath;
|
||||
final double quantity;
|
||||
final String unit;
|
||||
final String? location;
|
||||
@@ -15,6 +17,8 @@ class InventoryItem {
|
||||
required this.id,
|
||||
required this.productId,
|
||||
required this.productName,
|
||||
this.productCanonicalName,
|
||||
this.categoryPath,
|
||||
required this.quantity,
|
||||
required this.unit,
|
||||
this.location,
|
||||
@@ -25,11 +29,27 @@ class InventoryItem {
|
||||
this.comment,
|
||||
});
|
||||
|
||||
String get displayName {
|
||||
if (productCanonicalName != null && productCanonicalName!.trim().isNotEmpty) {
|
||||
return productCanonicalName!;
|
||||
}
|
||||
return productName;
|
||||
}
|
||||
|
||||
String get l1Category {
|
||||
final path = categoryPath?.trim();
|
||||
if (path == null || path.isEmpty) return 'Ovrigt';
|
||||
return path.split('>').first.trim();
|
||||
}
|
||||
|
||||
factory InventoryItem.fromJson(Map<String, dynamic> json) {
|
||||
final product = (json['product'] as Map<String, dynamic>?) ?? const {};
|
||||
return InventoryItem(
|
||||
id: json['id'] as int,
|
||||
productId: json['productId'] as int,
|
||||
productName: (json['product'] as Map<String, dynamic>?)?['name'] as String? ?? '',
|
||||
productName: product['name'] as String? ?? '',
|
||||
productCanonicalName: product['canonicalName'] as String?,
|
||||
categoryPath: _buildCategoryPath(product['categoryRef']),
|
||||
quantity: double.tryParse(json['quantity']?.toString() ?? '0') ?? 0,
|
||||
unit: json['unit'] as String? ?? '',
|
||||
location: json['location'] as String?,
|
||||
@@ -40,4 +60,21 @@ class InventoryItem {
|
||||
comment: json['comment'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
static String? _buildCategoryPath(dynamic rawCategoryRef) {
|
||||
if (rawCategoryRef is! Map<String, dynamic>) return null;
|
||||
|
||||
final names = <String>[];
|
||||
dynamic current = rawCategoryRef;
|
||||
while (current is Map<String, dynamic>) {
|
||||
final name = current['name']?.toString().trim();
|
||||
if (name != null && name.isNotEmpty) {
|
||||
names.insert(0, name);
|
||||
}
|
||||
current = current['parent'];
|
||||
}
|
||||
|
||||
if (names.isEmpty) return null;
|
||||
return names.join(' > ');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user