feat: dukung penjualan produk per timbangan
Produk kini punya cara jual `unit` (cacah) atau `weight` (timbangan), mengikuti kontrak backend di docs/integration-weight-based-products.md. - tipe SellBy, domain/infrastructure unit baru, dan endpoint /api/v1/units - dialog input berat saat produk timbangan ditambahkan ke keranjang - tiap penimbangan jadi baris keranjang sendiri; total baris dihitung berat x harga satuan, sedangkan produk cacah tetap digabung - request ke backend mengirim quantity 1 dan membawa berat - migrasi DB v3: kolom sell_by, unit_id, unit_name, unit_abbreviation di tabel products supaya satuan tetap tampil saat offline - tampilan keranjang, struk, split bill, void, dan refund memakai berat - test/weight_based_products_test.dart menutup perilaku di atas (9 test) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ class AddItemOrderRequestDto with _$AddItemOrderRequestDto {
|
||||
@JsonKey(name: 'quantity') int? quantity,
|
||||
@JsonKey(name: 'unit_price') int? unitPrice,
|
||||
@JsonKey(name: 'notes') String? notes,
|
||||
@JsonKey(name: 'weight') double? weight,
|
||||
}) = _AddItemOrderRequestDto;
|
||||
|
||||
factory AddItemOrderRequestDto.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -21,6 +22,7 @@ class AddItemOrderRequestDto with _$AddItemOrderRequestDto {
|
||||
quantity: quantity ?? 0,
|
||||
unitPrice: unitPrice ?? 0,
|
||||
notes: notes ?? '',
|
||||
weight: weight,
|
||||
);
|
||||
|
||||
factory AddItemOrderRequestDto.fromDomain(
|
||||
@@ -31,6 +33,7 @@ class AddItemOrderRequestDto with _$AddItemOrderRequestDto {
|
||||
quantity: addItemOrderRequest.quantity,
|
||||
unitPrice: addItemOrderRequest.unitPrice,
|
||||
notes: addItemOrderRequest.notes,
|
||||
weight: addItemOrderRequest.weight,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toRequest() {
|
||||
@@ -45,6 +48,11 @@ class AddItemOrderRequestDto with _$AddItemOrderRequestDto {
|
||||
data['product_variant_id'] = productvariantId;
|
||||
}
|
||||
|
||||
// Produk satuan ditolak backend bila membawa berat.
|
||||
if (weight != null) {
|
||||
data['weight'] = weight;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,10 @@ class OrderItemDto with _$OrderItemDto {
|
||||
@JsonKey(name: "paid_quantity") int? paidQuantity,
|
||||
@JsonKey(name: "category_id") String? categoryId,
|
||||
@JsonKey(name: "category_name") String? categoryName,
|
||||
@JsonKey(name: "weight") double? weight,
|
||||
@JsonKey(name: "unit_id") String? unitId,
|
||||
@JsonKey(name: "unit_name") String? unitName,
|
||||
@JsonKey(name: "unit_abbreviation") String? unitAbbreviation,
|
||||
}) = _OrderItemDto;
|
||||
|
||||
factory OrderItemDto.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -144,6 +148,10 @@ class OrderItemDto with _$OrderItemDto {
|
||||
paidQuantity: paidQuantity ?? 0,
|
||||
categoryId: categoryId ?? '',
|
||||
categoryName: categoryName ?? '',
|
||||
weight: weight,
|
||||
unitId: unitId ?? '',
|
||||
unitName: unitName ?? '',
|
||||
unitAbbreviation: unitAbbreviation ?? '',
|
||||
);
|
||||
|
||||
factory OrderItemDto.fromDomain(OrderItem orderItem) => OrderItemDto(
|
||||
@@ -166,5 +174,9 @@ class OrderItemDto with _$OrderItemDto {
|
||||
paidQuantity: orderItem.paidQuantity,
|
||||
categoryId: orderItem.categoryId,
|
||||
categoryName: orderItem.categoryName,
|
||||
weight: orderItem.weight,
|
||||
unitId: orderItem.unitId,
|
||||
unitName: orderItem.unitName,
|
||||
unitAbbreviation: orderItem.unitAbbreviation,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ class OrderItemRequestDto with _$OrderItemRequestDto {
|
||||
@JsonKey(name: "quantity") int? quantity,
|
||||
@JsonKey(name: "unit_price") int? unitPrice,
|
||||
@JsonKey(name: "notes") String? notes,
|
||||
@JsonKey(name: "weight") double? weight,
|
||||
}) = _OrderItemRequestDto;
|
||||
|
||||
factory OrderItemRequestDto.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -87,6 +88,7 @@ class OrderItemRequestDto with _$OrderItemRequestDto {
|
||||
quantity: quantity ?? 0,
|
||||
unitPrice: unitPrice ?? 0,
|
||||
notes: notes ?? '',
|
||||
weight: weight,
|
||||
);
|
||||
|
||||
factory OrderItemRequestDto.fromDomain(OrderItemRequest request) =>
|
||||
@@ -96,6 +98,7 @@ class OrderItemRequestDto with _$OrderItemRequestDto {
|
||||
quantity: request.quantity,
|
||||
unitPrice: request.unitPrice,
|
||||
notes: request.notes,
|
||||
weight: request.weight,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toRequest() {
|
||||
@@ -110,6 +113,12 @@ class OrderItemRequestDto with _$OrderItemRequestDto {
|
||||
data["product_variant_id"] = productVariantId;
|
||||
}
|
||||
|
||||
// Produk satuan ditolak backend bila membawa berat, jadi field ini hanya
|
||||
// ikut saat memang ada hasil timbangan.
|
||||
if (weight != null) {
|
||||
data["weight"] = weight;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user