Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a93dbbe30d |
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -188,6 +188,7 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
await meta.setLabelsForMany(
|
||||
targets,
|
||||
_draftLabelIds.toList(growable: false),
|
||||
matchPattern: toMatched ? _pattern : null,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
|
||||
Reference in New Issue
Block a user