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>
60 lines
1.6 KiB
Dart
60 lines
1.6 KiB
Dart
part of '../unit_dtos.dart';
|
|
|
|
@freezed
|
|
class UnitDto with _$UnitDto {
|
|
const UnitDto._();
|
|
|
|
const factory UnitDto({
|
|
@JsonKey(name: "id") String? id,
|
|
@JsonKey(name: "organization_id") String? organizationId,
|
|
@JsonKey(name: "name") String? name,
|
|
@JsonKey(name: "abbreviation") String? abbreviation,
|
|
@JsonKey(name: "is_active") bool? isActive,
|
|
}) = _UnitDto;
|
|
|
|
factory UnitDto.fromJson(Map<String, dynamic> json) =>
|
|
_$UnitDtoFromJson(json);
|
|
|
|
ProductUnit toDomain() => ProductUnit(
|
|
id: id ?? '',
|
|
organizationId: organizationId ?? '',
|
|
name: name ?? '',
|
|
abbreviation: abbreviation ?? '',
|
|
isActive: isActive ?? true,
|
|
);
|
|
|
|
factory UnitDto.fromDomain(ProductUnit unit) => UnitDto(
|
|
id: unit.id,
|
|
organizationId: unit.organizationId,
|
|
name: unit.name,
|
|
abbreviation: unit.abbreviation,
|
|
isActive: unit.isActive,
|
|
);
|
|
|
|
/// Response `/units` belum tentu berbentuk sama di setiap versi backend —
|
|
/// bisa `data: [...]` atau `data: { units: [...] }`. Terima keduanya supaya
|
|
/// POS tidak kehilangan satuan hanya karena pembungkusnya berbeda.
|
|
static List<UnitDto> listFromResponse(dynamic data) {
|
|
if (data is List) {
|
|
return data
|
|
.whereType<Map<String, dynamic>>()
|
|
.map(UnitDto.fromJson)
|
|
.toList();
|
|
}
|
|
|
|
if (data is Map<String, dynamic>) {
|
|
for (final key in const ['units', 'items', 'data']) {
|
|
final value = data[key];
|
|
if (value is List) {
|
|
return value
|
|
.whereType<Map<String, dynamic>>()
|
|
.map(UnitDto.fromJson)
|
|
.toList();
|
|
}
|
|
}
|
|
}
|
|
|
|
return const [];
|
|
}
|
|
}
|