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
@@ -293,6 +293,223 @@ abstract class _ListProductDto extends ListProductDto {
throw _privateConstructorUsedError;
}
ProductUnitDto _$ProductUnitDtoFromJson(Map<String, dynamic> json) {
return _ProductUnitDto.fromJson(json);
}
/// @nodoc
mixin _$ProductUnitDto {
@JsonKey(name: "id")
String? get id => throw _privateConstructorUsedError;
@JsonKey(name: "name")
String? get name => throw _privateConstructorUsedError;
@JsonKey(name: "abbreviation")
String? get abbreviation => throw _privateConstructorUsedError;
/// Serializes this ProductUnitDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of ProductUnitDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProductUnitDtoCopyWith<ProductUnitDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProductUnitDtoCopyWith<$Res> {
factory $ProductUnitDtoCopyWith(
ProductUnitDto value,
$Res Function(ProductUnitDto) then,
) = _$ProductUnitDtoCopyWithImpl<$Res, ProductUnitDto>;
@useResult
$Res call({
@JsonKey(name: "id") String? id,
@JsonKey(name: "name") String? name,
@JsonKey(name: "abbreviation") String? abbreviation,
});
}
/// @nodoc
class _$ProductUnitDtoCopyWithImpl<$Res, $Val extends ProductUnitDto>
implements $ProductUnitDtoCopyWith<$Res> {
_$ProductUnitDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProductUnitDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? name = freezed,
Object? abbreviation = freezed,
}) {
return _then(
_value.copyWith(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
abbreviation: freezed == abbreviation
? _value.abbreviation
: abbreviation // ignore: cast_nullable_to_non_nullable
as String?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$ProductUnitDtoImplCopyWith<$Res>
implements $ProductUnitDtoCopyWith<$Res> {
factory _$$ProductUnitDtoImplCopyWith(
_$ProductUnitDtoImpl value,
$Res Function(_$ProductUnitDtoImpl) then,
) = __$$ProductUnitDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "id") String? id,
@JsonKey(name: "name") String? name,
@JsonKey(name: "abbreviation") String? abbreviation,
});
}
/// @nodoc
class __$$ProductUnitDtoImplCopyWithImpl<$Res>
extends _$ProductUnitDtoCopyWithImpl<$Res, _$ProductUnitDtoImpl>
implements _$$ProductUnitDtoImplCopyWith<$Res> {
__$$ProductUnitDtoImplCopyWithImpl(
_$ProductUnitDtoImpl _value,
$Res Function(_$ProductUnitDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of ProductUnitDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? name = freezed,
Object? abbreviation = freezed,
}) {
return _then(
_$ProductUnitDtoImpl(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
abbreviation: freezed == abbreviation
? _value.abbreviation
: abbreviation // ignore: cast_nullable_to_non_nullable
as String?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$ProductUnitDtoImpl extends _ProductUnitDto {
const _$ProductUnitDtoImpl({
@JsonKey(name: "id") this.id,
@JsonKey(name: "name") this.name,
@JsonKey(name: "abbreviation") this.abbreviation,
}) : super._();
factory _$ProductUnitDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$ProductUnitDtoImplFromJson(json);
@override
@JsonKey(name: "id")
final String? id;
@override
@JsonKey(name: "name")
final String? name;
@override
@JsonKey(name: "abbreviation")
final String? abbreviation;
@override
String toString() {
return 'ProductUnitDto(id: $id, name: $name, abbreviation: $abbreviation)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProductUnitDtoImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.abbreviation, abbreviation) ||
other.abbreviation == abbreviation));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, id, name, abbreviation);
/// Create a copy of ProductUnitDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProductUnitDtoImplCopyWith<_$ProductUnitDtoImpl> get copyWith =>
__$$ProductUnitDtoImplCopyWithImpl<_$ProductUnitDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$ProductUnitDtoImplToJson(this);
}
}
abstract class _ProductUnitDto extends ProductUnitDto {
const factory _ProductUnitDto({
@JsonKey(name: "id") final String? id,
@JsonKey(name: "name") final String? name,
@JsonKey(name: "abbreviation") final String? abbreviation,
}) = _$ProductUnitDtoImpl;
const _ProductUnitDto._() : super._();
factory _ProductUnitDto.fromJson(Map<String, dynamic> json) =
_$ProductUnitDtoImpl.fromJson;
@override
@JsonKey(name: "id")
String? get id;
@override
@JsonKey(name: "name")
String? get name;
@override
@JsonKey(name: "abbreviation")
String? get abbreviation;
/// Create a copy of ProductUnitDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProductUnitDtoImplCopyWith<_$ProductUnitDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
ProductDto _$ProductDtoFromJson(Map<String, dynamic> json) {
return _ProductDto.fromJson(json);
}
@@ -333,6 +550,16 @@ mixin _$ProductDto {
String? get updatedAt => throw _privateConstructorUsedError;
@JsonKey(name: "variants")
List<ProductVariantDto>? get variants => throw _privateConstructorUsedError;
@JsonKey(name: "sell_by")
String? get sellBy => 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;
@JsonKey(name: "unit")
ProductUnitDto? get unit => throw _privateConstructorUsedError;
/// Serializes this ProductDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@@ -369,7 +596,14 @@ abstract class $ProductDtoCopyWith<$Res> {
@JsonKey(name: "created_at") String? createdAt,
@JsonKey(name: "updated_at") String? updatedAt,
@JsonKey(name: "variants") List<ProductVariantDto>? variants,
@JsonKey(name: "sell_by") String? sellBy,
@JsonKey(name: "unit_id") String? unitId,
@JsonKey(name: "unit_name") String? unitName,
@JsonKey(name: "unit_abbreviation") String? unitAbbreviation,
@JsonKey(name: "unit") ProductUnitDto? unit,
});
$ProductUnitDtoCopyWith<$Res>? get unit;
}
/// @nodoc
@@ -404,6 +638,11 @@ class _$ProductDtoCopyWithImpl<$Res, $Val extends ProductDto>
Object? createdAt = freezed,
Object? updatedAt = freezed,
Object? variants = freezed,
Object? sellBy = freezed,
Object? unitId = freezed,
Object? unitName = freezed,
Object? unitAbbreviation = freezed,
Object? unit = freezed,
}) {
return _then(
_value.copyWith(
@@ -475,10 +714,44 @@ class _$ProductDtoCopyWithImpl<$Res, $Val extends ProductDto>
? _value.variants
: variants // ignore: cast_nullable_to_non_nullable
as List<ProductVariantDto>?,
sellBy: freezed == sellBy
? _value.sellBy
: sellBy // ignore: cast_nullable_to_non_nullable
as String?,
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?,
unit: freezed == unit
? _value.unit
: unit // ignore: cast_nullable_to_non_nullable
as ProductUnitDto?,
)
as $Val,
);
}
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ProductUnitDtoCopyWith<$Res>? get unit {
if (_value.unit == null) {
return null;
}
return $ProductUnitDtoCopyWith<$Res>(_value.unit!, (value) {
return _then(_value.copyWith(unit: value) as $Val);
});
}
}
/// @nodoc
@@ -508,7 +781,15 @@ abstract class _$$ProductDtoImplCopyWith<$Res>
@JsonKey(name: "created_at") String? createdAt,
@JsonKey(name: "updated_at") String? updatedAt,
@JsonKey(name: "variants") List<ProductVariantDto>? variants,
@JsonKey(name: "sell_by") String? sellBy,
@JsonKey(name: "unit_id") String? unitId,
@JsonKey(name: "unit_name") String? unitName,
@JsonKey(name: "unit_abbreviation") String? unitAbbreviation,
@JsonKey(name: "unit") ProductUnitDto? unit,
});
@override
$ProductUnitDtoCopyWith<$Res>? get unit;
}
/// @nodoc
@@ -542,6 +823,11 @@ class __$$ProductDtoImplCopyWithImpl<$Res>
Object? createdAt = freezed,
Object? updatedAt = freezed,
Object? variants = freezed,
Object? sellBy = freezed,
Object? unitId = freezed,
Object? unitName = freezed,
Object? unitAbbreviation = freezed,
Object? unit = freezed,
}) {
return _then(
_$ProductDtoImpl(
@@ -613,6 +899,26 @@ class __$$ProductDtoImplCopyWithImpl<$Res>
? _value._variants
: variants // ignore: cast_nullable_to_non_nullable
as List<ProductVariantDto>?,
sellBy: freezed == sellBy
? _value.sellBy
: sellBy // ignore: cast_nullable_to_non_nullable
as String?,
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?,
unit: freezed == unit
? _value.unit
: unit // ignore: cast_nullable_to_non_nullable
as ProductUnitDto?,
),
);
}
@@ -639,6 +945,11 @@ class _$ProductDtoImpl extends _ProductDto {
@JsonKey(name: "created_at") this.createdAt,
@JsonKey(name: "updated_at") this.updatedAt,
@JsonKey(name: "variants") final List<ProductVariantDto>? variants,
@JsonKey(name: "sell_by") this.sellBy,
@JsonKey(name: "unit_id") this.unitId,
@JsonKey(name: "unit_name") this.unitName,
@JsonKey(name: "unit_abbreviation") this.unitAbbreviation,
@JsonKey(name: "unit") this.unit,
}) : _metadata = metadata,
_variants = variants,
super._();
@@ -713,9 +1024,25 @@ class _$ProductDtoImpl extends _ProductDto {
return EqualUnmodifiableListView(value);
}
@override
@JsonKey(name: "sell_by")
final String? sellBy;
@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
@JsonKey(name: "unit")
final ProductUnitDto? unit;
@override
String toString() {
return 'ProductDto(id: $id, organizationId: $organizationId, categoryId: $categoryId, sku: $sku, name: $name, description: $description, price: $price, cost: $cost, businessType: $businessType, imageUrl: $imageUrl, printerType: $printerType, printToChecker: $printToChecker, metadata: $metadata, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt, variants: $variants)';
return 'ProductDto(id: $id, organizationId: $organizationId, categoryId: $categoryId, sku: $sku, name: $name, description: $description, price: $price, cost: $cost, businessType: $businessType, imageUrl: $imageUrl, printerType: $printerType, printToChecker: $printToChecker, metadata: $metadata, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt, variants: $variants, sellBy: $sellBy, unitId: $unitId, unitName: $unitName, unitAbbreviation: $unitAbbreviation, unit: $unit)';
}
@override
@@ -749,12 +1076,19 @@ class _$ProductDtoImpl extends _ProductDto {
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt) &&
const DeepCollectionEquality().equals(other._variants, _variants));
const DeepCollectionEquality().equals(other._variants, _variants) &&
(identical(other.sellBy, sellBy) || other.sellBy == sellBy) &&
(identical(other.unitId, unitId) || other.unitId == unitId) &&
(identical(other.unitName, unitName) ||
other.unitName == unitName) &&
(identical(other.unitAbbreviation, unitAbbreviation) ||
other.unitAbbreviation == unitAbbreviation) &&
(identical(other.unit, unit) || other.unit == unit));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
int get hashCode => Object.hashAll([
runtimeType,
id,
organizationId,
@@ -773,7 +1107,12 @@ class _$ProductDtoImpl extends _ProductDto {
createdAt,
updatedAt,
const DeepCollectionEquality().hash(_variants),
);
sellBy,
unitId,
unitName,
unitAbbreviation,
unit,
]);
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.
@@ -808,6 +1147,11 @@ abstract class _ProductDto extends ProductDto {
@JsonKey(name: "created_at") final String? createdAt,
@JsonKey(name: "updated_at") final String? updatedAt,
@JsonKey(name: "variants") final List<ProductVariantDto>? variants,
@JsonKey(name: "sell_by") final String? sellBy,
@JsonKey(name: "unit_id") final String? unitId,
@JsonKey(name: "unit_name") final String? unitName,
@JsonKey(name: "unit_abbreviation") final String? unitAbbreviation,
@JsonKey(name: "unit") final ProductUnitDto? unit,
}) = _$ProductDtoImpl;
const _ProductDto._() : super._();
@@ -865,6 +1209,21 @@ abstract class _ProductDto extends ProductDto {
@override
@JsonKey(name: "variants")
List<ProductVariantDto>? get variants;
@override
@JsonKey(name: "sell_by")
String? get sellBy;
@override
@JsonKey(name: "unit_id")
String? get unitId;
@override
@JsonKey(name: "unit_name")
String? get unitName;
@override
@JsonKey(name: "unit_abbreviation")
String? get unitAbbreviation;
@override
@JsonKey(name: "unit")
ProductUnitDto? get unit;
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.