fix: accrue ref rewards in finance log before batch processing#3476
Open
TaprootFreak wants to merge 1 commit intodevelopfrom
Open
fix: accrue ref rewards in finance log before batch processing#3476TaprootFreak wants to merge 1 commit intodevelopfrom
TaprootFreak wants to merge 1 commit intodevelopfrom
Conversation
Ref expenses jumped in the finance log because costs were only recognized when the batch job created RefReward records, not when refCredit was incremented on the user. Add accrued open credit (refCredit - paidRefCredit minus in-progress RefRewards) to the ref expense calculation so costs appear smoothly as they are earned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
createPendingRefRewards()createdRefRewardrecords — not whenrefCreditwas incremented on the userSUM(refCredit - paidRefCredit)minus in-progress RefRewards) and include it in the ref expense totalaccruedfield to the ref breakdown in the change log for transparency (amount= processed RefRewards,accrued= unprocessed open credit,fee= payout tx fees)How it works
amountSUM(amountInChf)fromRefRewardrecords this monthaccrued(totalOpenCredit - inProgressRefRewards) * EUR/CHFfeeSUM(feeAmountChf)fromPayoutOrder(REF_PAYOUT)Math.max(0, ...)prevents negative values from timing race conditions.Test plan
log-job.service.spec.tstests pass (9/9)accruedfield appears in/dashboard/financial/changesresponse