fix product

This commit is contained in:
Phuoc Nguyen
2025-11-17 15:07:53 +07:00
parent 0828ff1355
commit ff3629d6d1
14 changed files with 1087 additions and 110 deletions

View File

@@ -24,6 +24,7 @@ class Product {
this.brand,
this.unit,
this.conversionOfSm,
this.introAttributes,
required this.isActive,
required this.isFeatured,
this.erpnextItemCode,
@@ -70,6 +71,11 @@ class Product {
/// Used to calculate: Số viên = Số lượng × conversionOfSm
final double? conversionOfSm;
/// Intro attributes (quick reference)
/// List of maps with 'code' and 'value' keys
/// Example: [{"code": "Size", "value": "120x120"}, {"code": "UOM", "value": "2 viên/hộp"}]
final List<Map<String, String>>? introAttributes;
/// Product is active
final bool isActive;
@@ -116,15 +122,25 @@ class Product {
/// TODO: Implement stock tracking when backend supports it
bool get isLowStock => false;
/// Check if product is in stock
/// Currently using isActive as proxy
bool get inStock => isActive;
/// Get specification value by key
String? getSpecification(String key) {
return specifications[key]?.toString();
}
/// Get intro attribute value by code
String? getIntroAttribute(String code) {
if (introAttributes == null) return null;
try {
final attr = introAttributes!.firstWhere(
(attr) => attr['code']?.toLowerCase() == code.toLowerCase(),
);
return attr['value'];
} catch (e) {
return null;
}
}
/// Copy with method for creating modified copies
Product copyWith({
String? productId,
@@ -140,6 +156,7 @@ class Product {
String? brand,
String? unit,
double? conversionOfSm,
List<Map<String, String>>? introAttributes,
bool? isActive,
bool? isFeatured,
String? erpnextItemCode,
@@ -160,6 +177,7 @@ class Product {
brand: brand ?? this.brand,
unit: unit ?? this.unit,
conversionOfSm: conversionOfSm ?? this.conversionOfSm,
introAttributes: introAttributes ?? this.introAttributes,
isActive: isActive ?? this.isActive,
isFeatured: isFeatured ?? this.isFeatured,
erpnextItemCode: erpnextItemCode ?? this.erpnextItemCode,