feat: credit realization by turip · Pull Request #3886 · openmeterio/openmeter

@turip

Overview

Fixes #(issue)

Notes for reviewer

@coderabbitai

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/charges-credit-realizations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

turip

Comment on lines +447 to +469

// Let's find out the service period for the credit realization
servicePeriod := timeutil.ClosedPeriod{
From: input.Charge.Intent.ServicePeriod.From,
To: input.AsOf,
}

lastRealizedPeriod := input.Charge.Realizations.Credit.LastRealizedPeriod()
if lastRealizedPeriod != nil {
servicePeriod.From = lastRealizedPeriod.To
}

h.customerAccountBalance -= amountToRealize.InexactFloat64()

// Note: we are also realizing the 0 value to make sure that we signify that in that period there was no usage
// in this setup the ledger transaction should not be created.

return []charges.CreditRealizationCreateInput{
{
Amount: amountToRealize,
ServicePeriod: servicePeriod,
},
}, nil
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: store the realization state inside the charge object and pass it to the handler as an already calculated value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also allows us to not to create 0 amount credit realizations, which will be good for the db schema as we can mandate the transaction group id

@turip