Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ProgressiveBilling) - automated CreditNote generation at the periodic invoice if needed #2475

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Calculate taxes for credit note
  • Loading branch information
nudded committed Aug 26, 2024
commit 406533ef86b7e607ab29535e9379a2c25c97986a
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def call

CreditNotes::CreateService.new(
invoice: progressive_billing_invoice,
credit_amount_cents: amount,
credit_amount_cents: creditable_amount_cents(amount, items),
items:,
reason:,
automatic: true
@@ -57,5 +57,18 @@ def calculate_items!

items
end

def creditable_amount_cents(amount, items)
taxes_result = CreditNotes::ApplyTaxesService.call(
invoice: progressive_billing_invoice,
items: items.map { |item| CreditNoteItem.new(fee_id: item[:fee_id], precise_amount_cents: item[:amount_cents]) }
)

(
amount.truncate(CreditNote::DB_PRECISION_SCALE) -
taxes_result.coupons_adjustment_amount_cents +
taxes_result.taxes_amount_cents
).round
end
end
end