Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a93dbbe30d |
@@ -521,10 +521,15 @@ class TxMetaController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Replace labels on every transaction in [txs] (per-id overrides).
|
/// 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(
|
Future<void> setLabelsForMany(
|
||||||
List<BankTransaction> txs,
|
List<BankTransaction> txs,
|
||||||
List<String> labelIds,
|
List<String> labelIds, {
|
||||||
) async {
|
String? matchPattern,
|
||||||
|
}) async {
|
||||||
if (txs.isEmpty) return;
|
if (txs.isEmpty) return;
|
||||||
|
|
||||||
final expanded = expandWithAncestors([
|
final expanded = expandWithAncestors([
|
||||||
@@ -545,6 +550,22 @@ class TxMetaController extends ChangeNotifier {
|
|||||||
: current.copyWith(labelIds: unique);
|
: current.copyWith(labelIds: unique);
|
||||||
}
|
}
|
||||||
_byId = nextById;
|
_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();
|
_schedulePersist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
|||||||
await meta.setLabelsForMany(
|
await meta.setLabelsForMany(
|
||||||
targets,
|
targets,
|
||||||
_draftLabelIds.toList(growable: false),
|
_draftLabelIds.toList(growable: false),
|
||||||
|
matchPattern: toMatched ? _pattern : null,
|
||||||
);
|
);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
Reference in New Issue
Block a user