fix : ticket order new

This commit is contained in:
kbe
2025-09-17 16:34:41 +02:00
parent 8103629370
commit 70aa9e9e2a
13 changed files with 96 additions and 90 deletions

View File

@@ -31,14 +31,6 @@ class Payout < ApplicationRecord
end
end
validate :net_earnings_greater_than_zero, if: :pending?
def net_earnings_greater_than_zero
if event.net_earnings_cents <= 0
errors.add(:base, "net earnings must be greater than 0")
end
end
def unique_pending_event_id
if Payout.pending.where(event_id: event_id).where.not(id: id).exists?
errors.add(:base, "only one pending payout allowed per event")
@@ -52,6 +44,7 @@ class Payout < ApplicationRecord
scope :processing, -> { where(status: :processing) }
scope :rejected, -> { where(status: :rejected) }
scope :failed, -> { where(status: :failed) }
scope :eligible_for_payout, -> { joins(:event).where(events: { state: 'published' }) }
# === Callbacks ===
after_create :calculate_refunded_orders_count
@@ -157,4 +150,10 @@ class Payout < ApplicationRecord
count = event.orders.where(status: paid_statuses).where(id: refunded_order_ids).count
update_column(:refunded_orders_count, count)
end
private
def update_earnings_status
event.earnings.where(status: 0).update_all(status: 1) # pending to paid
end
end