categorize multiple tags

This commit is contained in:
davmar
2026-10-15 18:33:04 +02:00
parent 22a535a6fd
commit a93dbbe30d
2 changed files with 24 additions and 2 deletions
+23 -2
View File
@@ -521,10 +521,15 @@ class TxMetaController extends ChangeNotifier {
}
/// Replace labels on every transaction in [txs] (per-id overrides).
///
/// When [matchPattern] is set (apply-to-matched), also refreshes the
/// merchant rule so future transactions matching the pattern inherit the
/// full label set (parent + sub-labels).
Future<void> setLabelsForMany(
List<BankTransaction> txs,
List<String> labelIds,
) async {
List<String> labelIds, {
String? matchPattern,
}) async {
if (txs.isEmpty) return;
final expanded = expandWithAncestors([
@@ -545,6 +550,22 @@ class TxMetaController extends ChangeNotifier {
: current.copyWith(labelIds: unique);
}
_byId = nextById;
final pattern = (matchPattern ?? '').trim().toLowerCase();
if (pattern.isNotEmpty) {
final nextRules = Map<String, List<String>>.of(_labelsByMerchant);
if (unique.isEmpty) {
nextRules.remove(pattern);
for (final tx in txs) {
nextRules.remove(tx.merchantKey);
nextRules.remove(tx.descriptionKey);
}
} else {
nextRules[pattern] = unique;
}
_labelsByMerchant = nextRules;
}
_schedulePersist();
}