feat(inventory): edit and delete existing lots

Lots could only be created; now they can be edited and removed:
- Repository: updateLot (LWW) + softDeleteLot (tombstone).
- Cubit: updateLot / deleteLot.
- The add-lot sheet is now a shared add/edit sheet — tapping a lot opens it
  prefilled (type, year, quantity), with a trash action to delete. The reactive
  detail view refreshes on save/delete.

Tests: repo updateLot/softDeleteLot + widget edit-lot and delete-lot. 42 green.
This commit is contained in:
vjrj 2026-07-08 11:10:43 +02:00
parent 7e92410728
commit f8d4d9a778
10 changed files with 192 additions and 16 deletions

View file

@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:tane/data/species_repository.dart';
import 'package:tane/data/variety_repository.dart';
import 'package:tane/db/database.dart';
import 'package:tane/db/enums.dart';
import '../support/test_support.dart';
@ -139,4 +140,35 @@ void main() {
await queue.cancel();
});
test('updateLot changes a lot\'s year, type and quantity', () async {
final id = await repo.addQuickVariety(label: 'Maize');
final lotId = await repo.addLot(
varietyId: id,
harvestYear: 2020,
quantity: const Quantity(kind: QuantityKind.packet, count: 1),
);
await repo.updateLot(
lotId: lotId,
type: LotType.plant,
harvestYear: 2024,
quantity: const Quantity(kind: QuantityKind.plant, count: 3),
);
final lot = (await repo.watchVariety(id).first)!.lots.single;
expect(lot.type, LotType.plant);
expect(lot.harvestYear, 2024);
expect(lot.quantity?.kind, QuantityKind.plant);
expect(lot.quantity?.count, 3);
});
test('softDeleteLot removes the lot from the variety', () async {
final id = await repo.addQuickVariety(label: 'Maize');
final lotId = await repo.addLot(varietyId: id, harvestYear: 2024);
await repo.softDeleteLot(lotId);
expect((await repo.watchVariety(id).first)!.lots, isEmpty);
});
}