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>
62 lines
1.6 KiB
Dart
62 lines
1.6 KiB
Dart
part of '../order.dart';
|
|
|
|
@freezed
|
|
class OrderRequest with _$OrderRequest {
|
|
const factory OrderRequest({
|
|
required String outletId,
|
|
required String customerId,
|
|
required String tableNumber,
|
|
required String tableId,
|
|
required String orderType,
|
|
required String notes,
|
|
required List<OrderItemRequest> orderItems,
|
|
required String customerName,
|
|
}) = _OrderRequest;
|
|
|
|
factory OrderRequest.empty() => const OrderRequest(
|
|
outletId: '',
|
|
customerId: '',
|
|
tableNumber: '',
|
|
tableId: '',
|
|
orderType: '',
|
|
notes: '',
|
|
orderItems: [],
|
|
customerName: '',
|
|
);
|
|
}
|
|
|
|
@freezed
|
|
class OrderItemRequest with _$OrderItemRequest {
|
|
const factory OrderItemRequest({
|
|
required String productId,
|
|
required String productVariantId,
|
|
required int quantity,
|
|
required int unitPrice,
|
|
required String notes,
|
|
|
|
/// Hanya diisi untuk produk `sell_by: "weight"`; produk cacah tidak boleh
|
|
/// mengirim berat sama sekali.
|
|
double? weight,
|
|
}) = _OrderItemRequest;
|
|
|
|
factory OrderItemRequest.empty() => const OrderItemRequest(
|
|
productId: '',
|
|
productVariantId: '',
|
|
quantity: 0,
|
|
unitPrice: 0,
|
|
notes: '',
|
|
);
|
|
|
|
/// Bentuk baris dari isi keranjang: produk timbangan selalu `quantity: 1`
|
|
/// ditambah `weight`, produk cacah tetap seperti sebelumnya.
|
|
factory OrderItemRequest.fromProductQuantity(ProductQuantity item) =>
|
|
OrderItemRequest(
|
|
productId: item.product.id,
|
|
productVariantId: item.variant?.id ?? '',
|
|
quantity: item.isWeighted ? 1 : item.quantity,
|
|
unitPrice: item.product.price.toInt(),
|
|
notes: item.notes,
|
|
weight: item.weight,
|
|
);
|
|
}
|