From 8103629370fac1c4b608a1c1869510964c069644 Mon Sep 17 00:00:00 2001 From: kbe Date: Wed, 17 Sep 2025 12:01:59 +0200 Subject: [PATCH] fix: add missing total_earnings_cents method and payout method to Event model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add alias total_earnings_cents for total_gross_cents for template compatibility - Add payout method to get the latest payout for an event - Fixes NoMethodError in promoter events earnings preview template 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app/models/event.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/event.rb b/app/models/event.rb index 837b172..e9bf80e 100755 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -76,6 +76,9 @@ class Event < ApplicationRecord tickets.active.sum(:price_cents) end + # Alias for template compatibility + alias_method :total_earnings_cents, :total_gross_cents + def total_fees_cents earnings.pending.sum(:fee_cents) end @@ -88,6 +91,11 @@ class Event < ApplicationRecord event_ended? && (net_earnings_cents > 0) && user.is_professionnal? && payouts.pending.empty? end + # Get the latest payout for this event + def payout + payouts.order(created_at: :desc).first + end + # Check if coordinates were successfully geocoded or are fallback coordinates def geocoding_successful? coordinates_look_valid?