Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
actual-vt-capstone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danieljk
actual-vt-capstone
Commits
54559478
Unverified
Commit
54559478
authored
2 years ago
by
Rian McGuire
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix some YNAB4 importer bugs (#88)
parent
daf677e8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/import-ynab4/importer.js
+32
-31
32 additions, 31 deletions
packages/import-ynab4/importer.js
with
32 additions
and
31 deletions
packages/import-ynab4/importer.js
+
32
−
31
View file @
54559478
...
@@ -80,8 +80,10 @@ function getCurrentMonth() {
...
@@ -80,8 +80,10 @@ function getCurrentMonth() {
// Importer
// Importer
async
function
importAccounts
(
data
,
entityIdMap
)
{
async
function
importAccounts
(
data
,
entityIdMap
)
{
const
accounts
=
sortByKey
(
data
.
accounts
,
'
sortableIndex
'
);
return
Promise
.
all
(
return
Promise
.
all
(
data
.
accounts
.
map
(
async
account
=>
{
accounts
.
map
(
async
account
=>
{
if
(
!
account
.
isTombstone
)
{
if
(
!
account
.
isTombstone
)
{
const
id
=
await
actual
.
createAccount
({
const
id
=
await
actual
.
createAccount
({
type
:
mapAccountType
(
account
.
accountType
),
type
:
mapAccountType
(
account
.
accountType
),
...
@@ -182,6 +184,12 @@ async function importTransactions(data, entityIdMap) {
...
@@ -182,6 +184,12 @@ async function importTransactions(data, entityIdMap) {
// reliably resolve transfers
// reliably resolve transfers
for
(
let
transaction
of
data
.
transactions
)
{
for
(
let
transaction
of
data
.
transactions
)
{
entityIdMap
.
set
(
transaction
.
entityId
,
uuid
.
v4
());
entityIdMap
.
set
(
transaction
.
entityId
,
uuid
.
v4
());
if
(
transaction
.
subTransactions
)
{
for
(
let
subTransaction
of
transaction
.
subTransactions
)
{
entityIdMap
.
set
(
subTransaction
.
entityId
,
uuid
.
v4
());
}
}
}
}
let
sortOrder
=
1
;
let
sortOrder
=
1
;
...
@@ -198,17 +206,22 @@ async function importTransactions(data, entityIdMap) {
...
@@ -198,17 +206,22 @@ async function importTransactions(data, entityIdMap) {
}
}
let
id
=
entityIdMap
.
get
(
transaction
.
entityId
);
let
id
=
entityIdMap
.
get
(
transaction
.
entityId
);
let
transferId
=
entityIdMap
.
get
(
transaction
.
transferTransactionId
)
||
null
;
function
transferProperties
(
t
)
{
let
transferId
=
let
payee
=
null
;
entityIdMap
.
get
(
t
.
transferTransactionId
)
||
null
;
if
(
transferId
)
{
payee
=
payees
.
find
(
let
payee
=
null
;
p
=>
if
(
transferId
)
{
p
.
transfer_acct
===
entityIdMap
.
get
(
transaction
.
targetAccountId
)
payee
=
payees
.
find
(
).
id
;
p
=>
}
else
{
p
.
transfer_acct
===
entityIdMap
.
get
(
t
.
targetAccountId
)
payee
=
entityIdMap
.
get
(
transaction
.
payeeId
);
).
id
;
}
else
{
payee
=
entityIdMap
.
get
(
t
.
payeeId
);
}
return
{
transfer_id
:
transferId
,
payee
}
}
}
let
newTransaction
=
{
let
newTransaction
=
{
...
@@ -219,8 +232,7 @@ async function importTransactions(data, entityIdMap) {
...
@@ -219,8 +232,7 @@ async function importTransactions(data, entityIdMap) {
:
getCategory
(
transaction
.
categoryId
),
:
getCategory
(
transaction
.
categoryId
),
date
:
transaction
.
date
,
date
:
transaction
.
date
,
notes
:
transaction
.
memo
||
null
,
notes
:
transaction
.
memo
||
null
,
payee
,
...
transferProperties
(
transaction
),
transfer_id
:
transferId
};
};
newTransaction
.
subtransactions
=
newTransaction
.
subtransactions
=
...
@@ -228,8 +240,10 @@ async function importTransactions(data, entityIdMap) {
...
@@ -228,8 +240,10 @@ async function importTransactions(data, entityIdMap) {
transaction
.
subTransactions
.
map
((
t
,
i
)
=>
{
transaction
.
subTransactions
.
map
((
t
,
i
)
=>
{
return
{
return
{
amount
:
amountToInteger
(
t
.
amount
),
amount
:
amountToInteger
(
t
.
amount
),
category
:
getCategory
(
t
.
categoryId
)
category
:
getCategory
(
t
.
categoryId
),
};
notes
:
t
.
memo
||
null
,
...
transferProperties
(
t
),
};
});
});
return
newTransaction
;
return
newTransaction
;
...
@@ -266,12 +280,8 @@ function fillInBudgets(data, categoryBudgets) {
...
@@ -266,12 +280,8 @@ function fillInBudgets(data, categoryBudgets) {
async
function
importBudgets
(
data
,
entityIdMap
)
{
async
function
importBudgets
(
data
,
entityIdMap
)
{
let
budgets
=
sortByKey
(
data
.
monthlyBudgets
,
'
month
'
);
let
budgets
=
sortByKey
(
data
.
monthlyBudgets
,
'
month
'
);
let
earliestMonth
=
monthFromDate
(
budgets
[
0
].
month
);
let
currentMonth
=
getCurrentMonth
();
await
actual
.
batchBudgetUpdates
(
async
()
=>
{
await
actual
.
batchBudgetUpdates
(
async
()
=>
{
const
carryoverFlags
=
{};
for
(
let
budget
of
budgets
)
{
for
(
let
budget
of
budgets
)
{
let
filled
=
fillInBudgets
(
let
filled
=
fillInBudgets
(
data
,
data
,
...
@@ -290,17 +300,8 @@ async function importBudgets(data, entityIdMap) {
...
@@ -290,17 +300,8 @@ async function importBudgets(data, entityIdMap) {
await
actual
.
setBudgetAmount
(
month
,
catId
,
amount
);
await
actual
.
setBudgetAmount
(
month
,
catId
,
amount
);
if
(
catBudget
.
overspendingHandling
===
'
AffectsBuffer
'
)
{
if
(
catBudget
.
overspendingHandling
===
'
AffectsBuffer
'
)
{
// Turn off the carryover flag so it doesn't propagate
await
actual
.
setBudgetCarryover
(
month
,
catId
,
false
);
// to future months
}
else
if
(
catBudget
.
overspendingHandling
===
'
Confined
'
)
{
carryoverFlags
[
catId
]
=
false
;
}
else
if
(
catBudget
.
overspendingHandling
===
'
Confined
'
||
carryoverFlags
[
catId
]
)
{
// Overspending has switched to carryover, set the
// flag so it propagates to future months
carryoverFlags
[
catId
]
=
true
;
await
actual
.
setBudgetCarryover
(
month
,
catId
,
true
);
await
actual
.
setBudgetCarryover
(
month
,
catId
,
true
);
}
}
})
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment