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:
efrilm
2026-09-06 23:03:31 +07:00
co-authored by Claude Opus 5
parent 9777f63426
commit 1505a83dd3
72 changed files with 5388 additions and 584 deletions
@@ -1177,6 +1177,14 @@ mixin _$OrderItemDto {
String? get categoryId => throw _privateConstructorUsedError;
@JsonKey(name: "category_name")
String? get categoryName => throw _privateConstructorUsedError;
@JsonKey(name: "weight")
double? get weight => throw _privateConstructorUsedError;
@JsonKey(name: "unit_id")
String? get unitId => throw _privateConstructorUsedError;
@JsonKey(name: "unit_name")
String? get unitName => throw _privateConstructorUsedError;
@JsonKey(name: "unit_abbreviation")
String? get unitAbbreviation => throw _privateConstructorUsedError;
/// Serializes this OrderItemDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@@ -1215,6 +1223,10 @@ abstract class $OrderItemDtoCopyWith<$Res> {
@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,
});
}
@@ -1252,6 +1264,10 @@ class _$OrderItemDtoCopyWithImpl<$Res, $Val extends OrderItemDto>
Object? paidQuantity = freezed,
Object? categoryId = freezed,
Object? categoryName = freezed,
Object? weight = freezed,
Object? unitId = freezed,
Object? unitName = freezed,
Object? unitAbbreviation = freezed,
}) {
return _then(
_value.copyWith(
@@ -1331,6 +1347,22 @@ class _$OrderItemDtoCopyWithImpl<$Res, $Val extends OrderItemDto>
? _value.categoryName
: categoryName // ignore: cast_nullable_to_non_nullable
as String?,
weight: freezed == weight
? _value.weight
: weight // ignore: cast_nullable_to_non_nullable
as double?,
unitId: freezed == unitId
? _value.unitId
: unitId // ignore: cast_nullable_to_non_nullable
as String?,
unitName: freezed == unitName
? _value.unitName
: unitName // ignore: cast_nullable_to_non_nullable
as String?,
unitAbbreviation: freezed == unitAbbreviation
? _value.unitAbbreviation
: unitAbbreviation // ignore: cast_nullable_to_non_nullable
as String?,
)
as $Val,
);
@@ -1366,6 +1398,10 @@ abstract class _$$OrderItemDtoImplCopyWith<$Res>
@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,
});
}
@@ -1402,6 +1438,10 @@ class __$$OrderItemDtoImplCopyWithImpl<$Res>
Object? paidQuantity = freezed,
Object? categoryId = freezed,
Object? categoryName = freezed,
Object? weight = freezed,
Object? unitId = freezed,
Object? unitName = freezed,
Object? unitAbbreviation = freezed,
}) {
return _then(
_$OrderItemDtoImpl(
@@ -1481,6 +1521,22 @@ class __$$OrderItemDtoImplCopyWithImpl<$Res>
? _value.categoryName
: categoryName // ignore: cast_nullable_to_non_nullable
as String?,
weight: freezed == weight
? _value.weight
: weight // ignore: cast_nullable_to_non_nullable
as double?,
unitId: freezed == unitId
? _value.unitId
: unitId // ignore: cast_nullable_to_non_nullable
as String?,
unitName: freezed == unitName
? _value.unitName
: unitName // ignore: cast_nullable_to_non_nullable
as String?,
unitAbbreviation: freezed == unitAbbreviation
? _value.unitAbbreviation
: unitAbbreviation // ignore: cast_nullable_to_non_nullable
as String?,
),
);
}
@@ -1509,6 +1565,10 @@ class _$OrderItemDtoImpl extends _OrderItemDto {
@JsonKey(name: "paid_quantity") this.paidQuantity,
@JsonKey(name: "category_id") this.categoryId,
@JsonKey(name: "category_name") this.categoryName,
@JsonKey(name: "weight") this.weight,
@JsonKey(name: "unit_id") this.unitId,
@JsonKey(name: "unit_name") this.unitName,
@JsonKey(name: "unit_abbreviation") this.unitAbbreviation,
}) : _modifiers = modifiers,
super._();
@@ -1580,10 +1640,22 @@ class _$OrderItemDtoImpl extends _OrderItemDto {
@override
@JsonKey(name: "category_name")
final String? categoryName;
@override
@JsonKey(name: "weight")
final double? weight;
@override
@JsonKey(name: "unit_id")
final String? unitId;
@override
@JsonKey(name: "unit_name")
final String? unitName;
@override
@JsonKey(name: "unit_abbreviation")
final String? unitAbbreviation;
@override
String toString() {
return 'OrderItemDto(id: $id, orderId: $orderId, productId: $productId, productName: $productName, productVariantId: $productVariantId, productVariantName: $productVariantName, quantity: $quantity, unitPrice: $unitPrice, totalPrice: $totalPrice, modifiers: $modifiers, notes: $notes, status: $status, createdAt: $createdAt, updatedAt: $updatedAt, printerType: $printerType, printToChecker: $printToChecker, paidQuantity: $paidQuantity, categoryId: $categoryId, categoryName: $categoryName)';
return 'OrderItemDto(id: $id, orderId: $orderId, productId: $productId, productName: $productName, productVariantId: $productVariantId, productVariantName: $productVariantName, quantity: $quantity, unitPrice: $unitPrice, totalPrice: $totalPrice, modifiers: $modifiers, notes: $notes, status: $status, createdAt: $createdAt, updatedAt: $updatedAt, printerType: $printerType, printToChecker: $printToChecker, paidQuantity: $paidQuantity, categoryId: $categoryId, categoryName: $categoryName, weight: $weight, unitId: $unitId, unitName: $unitName, unitAbbreviation: $unitAbbreviation)';
}
@override
@@ -1626,7 +1698,13 @@ class _$OrderItemDtoImpl extends _OrderItemDto {
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId) &&
(identical(other.categoryName, categoryName) ||
other.categoryName == categoryName));
other.categoryName == categoryName) &&
(identical(other.weight, weight) || other.weight == weight) &&
(identical(other.unitId, unitId) || other.unitId == unitId) &&
(identical(other.unitName, unitName) ||
other.unitName == unitName) &&
(identical(other.unitAbbreviation, unitAbbreviation) ||
other.unitAbbreviation == unitAbbreviation));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -1652,6 +1730,10 @@ class _$OrderItemDtoImpl extends _OrderItemDto {
paidQuantity,
categoryId,
categoryName,
weight,
unitId,
unitName,
unitAbbreviation,
]);
/// Create a copy of OrderItemDto
@@ -1689,6 +1771,10 @@ abstract class _OrderItemDto extends OrderItemDto {
@JsonKey(name: "paid_quantity") final int? paidQuantity,
@JsonKey(name: "category_id") final String? categoryId,
@JsonKey(name: "category_name") final String? categoryName,
@JsonKey(name: "weight") final double? weight,
@JsonKey(name: "unit_id") final String? unitId,
@JsonKey(name: "unit_name") final String? unitName,
@JsonKey(name: "unit_abbreviation") final String? unitAbbreviation,
}) = _$OrderItemDtoImpl;
const _OrderItemDto._() : super._();
@@ -1752,6 +1838,18 @@ abstract class _OrderItemDto extends OrderItemDto {
@override
@JsonKey(name: "category_name")
String? get categoryName;
@override
@JsonKey(name: "weight")
double? get weight;
@override
@JsonKey(name: "unit_id")
String? get unitId;
@override
@JsonKey(name: "unit_name")
String? get unitName;
@override
@JsonKey(name: "unit_abbreviation")
String? get unitAbbreviation;
/// Create a copy of OrderItemDto
/// with the given fields replaced by the non-null parameter values.
@@ -2136,6 +2234,8 @@ mixin _$OrderItemRequestDto {
int? get unitPrice => throw _privateConstructorUsedError;
@JsonKey(name: "notes")
String? get notes => throw _privateConstructorUsedError;
@JsonKey(name: "weight")
double? get weight => throw _privateConstructorUsedError;
/// Serializes this OrderItemRequestDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@@ -2160,6 +2260,7 @@ abstract class $OrderItemRequestDtoCopyWith<$Res> {
@JsonKey(name: "quantity") int? quantity,
@JsonKey(name: "unit_price") int? unitPrice,
@JsonKey(name: "notes") String? notes,
@JsonKey(name: "weight") double? weight,
});
}
@@ -2183,6 +2284,7 @@ class _$OrderItemRequestDtoCopyWithImpl<$Res, $Val extends OrderItemRequestDto>
Object? quantity = freezed,
Object? unitPrice = freezed,
Object? notes = freezed,
Object? weight = freezed,
}) {
return _then(
_value.copyWith(
@@ -2206,6 +2308,10 @@ class _$OrderItemRequestDtoCopyWithImpl<$Res, $Val extends OrderItemRequestDto>
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
weight: freezed == weight
? _value.weight
: weight // ignore: cast_nullable_to_non_nullable
as double?,
)
as $Val,
);
@@ -2227,6 +2333,7 @@ abstract class _$$OrderItemRequestDtoImplCopyWith<$Res>
@JsonKey(name: "quantity") int? quantity,
@JsonKey(name: "unit_price") int? unitPrice,
@JsonKey(name: "notes") String? notes,
@JsonKey(name: "weight") double? weight,
});
}
@@ -2249,6 +2356,7 @@ class __$$OrderItemRequestDtoImplCopyWithImpl<$Res>
Object? quantity = freezed,
Object? unitPrice = freezed,
Object? notes = freezed,
Object? weight = freezed,
}) {
return _then(
_$OrderItemRequestDtoImpl(
@@ -2272,6 +2380,10 @@ class __$$OrderItemRequestDtoImplCopyWithImpl<$Res>
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
weight: freezed == weight
? _value.weight
: weight // ignore: cast_nullable_to_non_nullable
as double?,
),
);
}
@@ -2286,6 +2398,7 @@ class _$OrderItemRequestDtoImpl extends _OrderItemRequestDto {
@JsonKey(name: "quantity") this.quantity,
@JsonKey(name: "unit_price") this.unitPrice,
@JsonKey(name: "notes") this.notes,
@JsonKey(name: "weight") this.weight,
}) : super._();
factory _$OrderItemRequestDtoImpl.fromJson(Map<String, dynamic> json) =>
@@ -2306,10 +2419,13 @@ class _$OrderItemRequestDtoImpl extends _OrderItemRequestDto {
@override
@JsonKey(name: "notes")
final String? notes;
@override
@JsonKey(name: "weight")
final double? weight;
@override
String toString() {
return 'OrderItemRequestDto(productId: $productId, productVariantId: $productVariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes)';
return 'OrderItemRequestDto(productId: $productId, productVariantId: $productVariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes, weight: $weight)';
}
@override
@@ -2325,7 +2441,8 @@ class _$OrderItemRequestDtoImpl extends _OrderItemRequestDto {
other.quantity == quantity) &&
(identical(other.unitPrice, unitPrice) ||
other.unitPrice == unitPrice) &&
(identical(other.notes, notes) || other.notes == notes));
(identical(other.notes, notes) || other.notes == notes) &&
(identical(other.weight, weight) || other.weight == weight));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -2337,6 +2454,7 @@ class _$OrderItemRequestDtoImpl extends _OrderItemRequestDto {
quantity,
unitPrice,
notes,
weight,
);
/// Create a copy of OrderItemRequestDto
@@ -2363,6 +2481,7 @@ abstract class _OrderItemRequestDto extends OrderItemRequestDto {
@JsonKey(name: "quantity") final int? quantity,
@JsonKey(name: "unit_price") final int? unitPrice,
@JsonKey(name: "notes") final String? notes,
@JsonKey(name: "weight") final double? weight,
}) = _$OrderItemRequestDtoImpl;
const _OrderItemRequestDto._() : super._();
@@ -2384,6 +2503,9 @@ abstract class _OrderItemRequestDto extends OrderItemRequestDto {
@override
@JsonKey(name: "notes")
String? get notes;
@override
@JsonKey(name: "weight")
double? get weight;
/// Create a copy of OrderItemRequestDto
/// with the given fields replaced by the non-null parameter values.
@@ -4025,6 +4147,8 @@ mixin _$AddItemOrderRequestDto {
int? get unitPrice => throw _privateConstructorUsedError;
@JsonKey(name: 'notes')
String? get notes => throw _privateConstructorUsedError;
@JsonKey(name: 'weight')
double? get weight => throw _privateConstructorUsedError;
/// Serializes this AddItemOrderRequestDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@@ -4049,6 +4173,7 @@ abstract class $AddItemOrderRequestDtoCopyWith<$Res> {
@JsonKey(name: 'quantity') int? quantity,
@JsonKey(name: 'unit_price') int? unitPrice,
@JsonKey(name: 'notes') String? notes,
@JsonKey(name: 'weight') double? weight,
});
}
@@ -4075,6 +4200,7 @@ class _$AddItemOrderRequestDtoCopyWithImpl<
Object? quantity = freezed,
Object? unitPrice = freezed,
Object? notes = freezed,
Object? weight = freezed,
}) {
return _then(
_value.copyWith(
@@ -4098,6 +4224,10 @@ class _$AddItemOrderRequestDtoCopyWithImpl<
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
weight: freezed == weight
? _value.weight
: weight // ignore: cast_nullable_to_non_nullable
as double?,
)
as $Val,
);
@@ -4119,6 +4249,7 @@ abstract class _$$AddItemOrderRequestDtoImplCopyWith<$Res>
@JsonKey(name: 'quantity') int? quantity,
@JsonKey(name: 'unit_price') int? unitPrice,
@JsonKey(name: 'notes') String? notes,
@JsonKey(name: 'weight') double? weight,
});
}
@@ -4142,6 +4273,7 @@ class __$$AddItemOrderRequestDtoImplCopyWithImpl<$Res>
Object? quantity = freezed,
Object? unitPrice = freezed,
Object? notes = freezed,
Object? weight = freezed,
}) {
return _then(
_$AddItemOrderRequestDtoImpl(
@@ -4165,6 +4297,10 @@ class __$$AddItemOrderRequestDtoImplCopyWithImpl<$Res>
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
weight: freezed == weight
? _value.weight
: weight // ignore: cast_nullable_to_non_nullable
as double?,
),
);
}
@@ -4179,6 +4315,7 @@ class _$AddItemOrderRequestDtoImpl extends _AddItemOrderRequestDto {
@JsonKey(name: 'quantity') this.quantity,
@JsonKey(name: 'unit_price') this.unitPrice,
@JsonKey(name: 'notes') this.notes,
@JsonKey(name: 'weight') this.weight,
}) : super._();
factory _$AddItemOrderRequestDtoImpl.fromJson(Map<String, dynamic> json) =>
@@ -4199,10 +4336,13 @@ class _$AddItemOrderRequestDtoImpl extends _AddItemOrderRequestDto {
@override
@JsonKey(name: 'notes')
final String? notes;
@override
@JsonKey(name: 'weight')
final double? weight;
@override
String toString() {
return 'AddItemOrderRequestDto(productId: $productId, productvariantId: $productvariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes)';
return 'AddItemOrderRequestDto(productId: $productId, productvariantId: $productvariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes, weight: $weight)';
}
@override
@@ -4218,7 +4358,8 @@ class _$AddItemOrderRequestDtoImpl extends _AddItemOrderRequestDto {
other.quantity == quantity) &&
(identical(other.unitPrice, unitPrice) ||
other.unitPrice == unitPrice) &&
(identical(other.notes, notes) || other.notes == notes));
(identical(other.notes, notes) || other.notes == notes) &&
(identical(other.weight, weight) || other.weight == weight));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -4230,6 +4371,7 @@ class _$AddItemOrderRequestDtoImpl extends _AddItemOrderRequestDto {
quantity,
unitPrice,
notes,
weight,
);
/// Create a copy of AddItemOrderRequestDto
@@ -4257,6 +4399,7 @@ abstract class _AddItemOrderRequestDto extends AddItemOrderRequestDto {
@JsonKey(name: 'quantity') final int? quantity,
@JsonKey(name: 'unit_price') final int? unitPrice,
@JsonKey(name: 'notes') final String? notes,
@JsonKey(name: 'weight') final double? weight,
}) = _$AddItemOrderRequestDtoImpl;
const _AddItemOrderRequestDto._() : super._();
@@ -4278,6 +4421,9 @@ abstract class _AddItemOrderRequestDto extends AddItemOrderRequestDto {
@override
@JsonKey(name: 'notes')
String? get notes;
@override
@JsonKey(name: 'weight')
double? get weight;
/// Create a copy of AddItemOrderRequestDto
/// with the given fields replaced by the non-null parameter values.