fix product
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user