Skip to content

Commit

Permalink
Auto mark invoices as paid only when transaction was newly finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
akadusei committed Aug 16, 2024
1 parent e809888 commit 2d68f7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Allowing manually setting `created_at` when finalizing documents

### Fixed
- Auto mark invoices as paid only when transaction was newly finalized

## [0.18.0] - 2024-07-27

### Added
Expand Down
5 changes: 3 additions & 2 deletions src/bill/operations/mixins/auto_mark_invoices_as_paid.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module Bill::AutoMarkInvoicesAsPaid
after_save mark_invoices_as_paid

private def mark_invoices_as_paid(transaction : Bill::Transaction)
return unless TransactionStatus.now_finalized?(status)

balance = Ledger.balance!(user_id = transaction.user_id)
return mark_all(user_id) unless balance.debit?
mark_for_debit(user_id, balance)
balance.debit? ? mark_for_debit(user_id, balance) : mark_all(user_id)
end

# A credit or zero balance means all invoices have been paid.
Expand Down

0 comments on commit 2d68f7c

Please sign in to comment.