categorize multiple tags
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user