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:
@@ -0,0 +1,23 @@
|
||||
part of '../unit.dart';
|
||||
|
||||
/// Satuan timbangan milik organisasi — ons, kg, gram.
|
||||
///
|
||||
/// [abbreviation] yang dipakai POS untuk mencetak `4,2 ons` di struk.
|
||||
@freezed
|
||||
class ProductUnit with _$ProductUnit {
|
||||
const factory ProductUnit({
|
||||
required String id,
|
||||
required String organizationId,
|
||||
required String name,
|
||||
required String abbreviation,
|
||||
required bool isActive,
|
||||
}) = _ProductUnit;
|
||||
|
||||
factory ProductUnit.empty() => const ProductUnit(
|
||||
id: '',
|
||||
organizationId: '',
|
||||
name: '',
|
||||
abbreviation: '',
|
||||
isActive: false,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
part of '../unit.dart';
|
||||
|
||||
@freezed
|
||||
sealed class UnitFailure with _$UnitFailure {
|
||||
const factory UnitFailure.serverError(ApiFailure failure) = _ServerError;
|
||||
const factory UnitFailure.unexpectedError() = _UnexpectedError;
|
||||
const factory UnitFailure.empty() = _Empty;
|
||||
const factory UnitFailure.localStorageError(String erroMessage) =
|
||||
_LocalStorageError;
|
||||
const factory UnitFailure.dynamicErrorMessage(String erroMessage) =
|
||||
_DynamicErrorMessage;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
part of '../unit.dart';
|
||||
|
||||
abstract class IUnitRepository {
|
||||
/// Ambil satuan dari server lalu simpan ke cache lokal.
|
||||
/// Bila server tidak terjangkau, kembalikan isi cache supaya POS tetap bisa
|
||||
/// mencetak `4,2 ons` saat offline.
|
||||
Future<Either<UnitFailure, List<ProductUnit>>> getUnits({
|
||||
bool forceRefresh = false,
|
||||
});
|
||||
|
||||
Future<List<ProductUnit>> cachedUnits();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../common/api/api_failure.dart';
|
||||
|
||||
part 'unit.freezed.dart';
|
||||
|
||||
part 'entities/unit_entity.dart';
|
||||
part 'failures/unit_failure.dart';
|
||||
part 'repositories/i_unit_repository.dart';
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user