Closed ekeih closed 7 months ago
Thanks for this detailed report.
You are indeed correct, this is a bug. Transactions from off-budget to on-budget accounts without an Envelope need to be considered for .income
of the /v4/months
endpoint.
The transaction filtering again has a different understanding, which I have come to consider wrong, too.
I thought about this for a while and arrived at the conclusion that we'll need two different filters, one direction filter and one type filter.
direction: purely for internal/external account considerations
Has the following filter values
type: For the effect a transaction has on the budget
Has the following filter values
I'm not yet happy with incoming and income being named this similarly. Any suggestions to improve this are very welcome.
I think Where("source_account.external = 1"). in budget.go should be Where("accounts_source.on_budget = true AND accounts_destination.on_budget = false"). instead.
@ekeih I think you meant that it should be
Where("source_account.on_budget = false AND destination_account.on_budget = true").
instead, right? You had the true
and false
condititons the other way around.
I used the updated version in #1023, which resolves this issue.
I moved the changes to transaction filtering to #1024 to handle them separately.
Oh, yes you are right, I mixed that up 😬 Thanks for the fix! 🚀
Describe the bug
/v4/months
returns an attribute.income
which is documented in the source asThe total income for the month (sum of all incoming transactions without an Envelope)
..available
if it is not transferred to an envelope.Where("source_account.external = 1 OR source_account.on_budget = 0").
. But after thinking about it a bit more I think the query needs to be more specific. Because there are also cases liketransferring off-budget to off-budget
to consider and maybe more.~INCOMING
direction filter for transactions in https://github.com/envelope-zero/backend/blob/ca55deb7a440570889eb681b6b7fd6b33a5309c3/pkg/controllers/v4/transaction.go#L240-L246 I thinkWhere("source_account.external = 1").
inbudget.go
should beWhere("accounts_source.on_budget = true AND accounts_destination.on_budget = false").
instead.INCOMING
direction filter should exclude transactions that are allocated to an envelope right away?)To Reproduce
.income
attribute of/api/v4/months
of the budget..income
again. It is the same as in step 2, but I believe it should have increased by the transferred amount.Expected behavior Off-budget to on-budget transactions without an envelope are included in the
.income
calculation ofv4/months
.Additional context
.income
as far as I can see..income
in the frontend. I could work around this by quering transactions (filtered fordirection=INCOMING
andenvelope=
) and adding their amounts. But after thinking about this for an hour and looking at the backend source I think this is a bug in the backend.