Skip to content
Snippets Groups Projects
Unverified Commit 771c01c8 authored by Matt Fiddaman's avatar Matt Fiddaman Committed by GitHub
Browse files

Move bank sync payee name normalisation from `actual` to `actual-server` (#2721)

parent 9f72b438
No related branches found
No related tags found
No related merge requests found
...@@ -255,55 +255,11 @@ async function normalizeBankSyncTransactions(transactions, acctId) { ...@@ -255,55 +255,11 @@ async function normalizeBankSyncTransactions(transactions, acctId) {
throw new Error('`date` is required when adding a transaction'); throw new Error('`date` is required when adding a transaction');
} }
let payee_name; if (trans.payeeName == null) {
// When the amount is equal to 0, we need to determine throw new Error('`payeeName` is required when adding a transaction');
// if this is a "Credited" or "Debited" transaction. This means
// that it matters whether the amount is a positive or negative zero.
if (trans.amount > 0 || Object.is(Number(trans.amount), 0)) {
const nameParts = [];
const name =
trans.debtorName ||
trans.remittanceInformationUnstructured ||
(trans.remittanceInformationUnstructuredArray || []).join(', ') ||
trans.additionalInformation;
if (name) {
nameParts.push(title(name));
}
if (trans.debtorAccount && trans.debtorAccount.iban) {
nameParts.push(
'(' +
trans.debtorAccount.iban.slice(0, 4) +
' XXX ' +
trans.debtorAccount.iban.slice(-4) +
')',
);
}
payee_name = nameParts.join(' ');
} else {
const nameParts = [];
const name =
trans.creditorName ||
trans.remittanceInformationUnstructured ||
(trans.remittanceInformationUnstructuredArray || []).join(', ') ||
trans.additionalInformation;
if (name) {
nameParts.push(title(name));
}
if (trans.creditorAccount && trans.creditorAccount.iban) {
nameParts.push(
'(' +
trans.creditorAccount.iban.slice(0, 4) +
' XXX ' +
trans.creditorAccount.iban.slice(-4) +
')',
);
}
payee_name = nameParts.join(' ');
} }
trans.imported_payee = trans.imported_payee || payee_name; trans.imported_payee = trans.imported_payee || trans.payeeName;
if (trans.imported_payee) { if (trans.imported_payee) {
trans.imported_payee = trans.imported_payee.trim(); trans.imported_payee = trans.imported_payee.trim();
} }
...@@ -312,12 +268,12 @@ async function normalizeBankSyncTransactions(transactions, acctId) { ...@@ -312,12 +268,12 @@ async function normalizeBankSyncTransactions(transactions, acctId) {
// when rules are run, they have the right data. Resolving payees // when rules are run, they have the right data. Resolving payees
// also simplifies the payee creation process // also simplifies the payee creation process
trans.account = acctId; trans.account = acctId;
trans.payee = await resolvePayee(trans, payee_name, payeesToCreate); trans.payee = await resolvePayee(trans, trans.payeeName, payeesToCreate);
trans.cleared = Boolean(trans.booked); trans.cleared = Boolean(trans.booked);
normalized.push({ normalized.push({
payee_name, payee_name: trans.payeeName,
trans: { trans: {
amount: amountToInteger(trans.amount), amount: amountToInteger(trans.amount),
payee: trans.payee, payee: trans.payee,
......
---
category: Maintenance
authors: [matt-fidd]
---
Move bank sync payee name normalization from actual to actual-server
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment