feat(promotion-code): Complete promotion code integration and testing
- Add comprehensive promotion code methods to Order model - Implement Stripe invoice integration for promotion code discounts - Display promotion codes on invoice with proper discount breakdown - Fix and enhance all unit tests for promotion code functionality - Add discount calculation with capping to prevent negative totals - Ensure promotion codes work across entire order lifecycle 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ class Order < ApplicationRecord
|
||||
discount_total = promotion_codes.sum(:discount_amount_cents)
|
||||
|
||||
# Ensure total doesn't go below zero
|
||||
final_total = [ticket_total - discount_total, 0].max
|
||||
final_total = [ ticket_total - discount_total, 0 ].max
|
||||
update!(total_amount_cents: final_total)
|
||||
end
|
||||
|
||||
@@ -110,9 +110,9 @@ class Order < ApplicationRecord
|
||||
subtotal_amount_cents / 100.0
|
||||
end
|
||||
|
||||
# Total discount amount from all promotion codes
|
||||
# Total discount amount from all promotion codes (capped at subtotal)
|
||||
def discount_amount_cents
|
||||
promotion_codes.sum(:discount_amount_cents)
|
||||
[ promotion_codes.sum(:discount_amount_cents), subtotal_amount_cents ].min
|
||||
end
|
||||
|
||||
# Discount amount in euros
|
||||
|
||||
Reference in New Issue
Block a user