mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-07-03 04:38:38 -04:00
testing: Test creating reports
This commit is contained in:
@ -117,6 +117,14 @@ func (t *TestData) Initialize() (*TestData, error) {
|
||||
t2.transactions = append(t2.transactions, *tt2)
|
||||
}
|
||||
|
||||
for _, report := range t.reports {
|
||||
r2, err := createReport(t2.clients[report.UserId], &report)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t2.reports = append(t2.reports, *r2)
|
||||
}
|
||||
|
||||
t2.initialized = true
|
||||
return &t2, nil
|
||||
}
|
||||
@ -310,5 +318,61 @@ var data = []TestData{
|
||||
},
|
||||
},
|
||||
},
|
||||
reports: []handlers.Report{
|
||||
handlers.Report{
|
||||
UserId: 0,
|
||||
Name: "",
|
||||
Lua: `
|
||||
function account_series_map(accounts, tabulation)
|
||||
map = {}
|
||||
|
||||
for i=1,100 do -- we're not messing with accounts more than 100 levels deep
|
||||
all_handled = true
|
||||
for id, acct in pairs(accounts) do
|
||||
if not map[id] then
|
||||
all_handled = false
|
||||
if not acct.parent then
|
||||
map[id] = tabulation:series(acct.name)
|
||||
elseif map[acct.parent.accountid] then
|
||||
map[id] = map[acct.parent.accountid]:series(acct.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
if all_handled then
|
||||
return map
|
||||
end
|
||||
end
|
||||
|
||||
error("Accounts nested (at least) 100 levels deep")
|
||||
end
|
||||
|
||||
function generate()
|
||||
year = date.now().year
|
||||
account_type = account.Expense
|
||||
|
||||
accounts = get_accounts()
|
||||
t = tabulation.new(12)
|
||||
t:title(year .. " Monthly Expenses")
|
||||
series_map = account_series_map(accounts, t)
|
||||
|
||||
for month=1,12 do
|
||||
begin_date = date.new(year, month, 1)
|
||||
end_date = date.new(year, month+1, 1)
|
||||
|
||||
t:label(month, tostring(begin_date))
|
||||
|
||||
for id, acct in pairs(accounts) do
|
||||
series = series_map[id]
|
||||
if acct.type == account_type then
|
||||
balance = acct:balance(begin_date, end_date)
|
||||
series:value(month, balance.amount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
end`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user