diff --git a/app/models/competition.rb b/app/models/competition.rb index ede34a6315..e508af64bc 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -353,6 +353,12 @@ def advancement_condition_must_be_present_for_all_non_final_rounds end end + validate :payments_nil_to_change_currency + private def payments_nil_to_change_currency + return unless currency_code_changed? + errors.add(:currency_code, I18n.t('competitions.errors.currency_cant_change')) if total_payment_amount != 0 + end + def has_any_round_per_event? competition_events.map(&:rounds).none?(&:empty?) end @@ -2688,6 +2694,10 @@ def disconnect_all_payment_integrations competition_payment_integrations.destroy_all end + def total_payment_amount + registrations.joins(:registration_payments).sum('registration_payments.amount_lowest_denomination') + end + # Our React date picker unfortunately behaves weirdly in terms of backend data def self.date_json_schema(string_format) { diff --git a/config/locales/en.yml b/config/locales/en.yml index 0f74f38849..efb518ec8f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1933,6 +1933,7 @@ en: -6002: "You need to finish your registration before you can pay" #context: and when an error occured errors: + currency_cant_change: "You cannot change the currency until all outstanding payments have been refunded." invalid_name_message: "must end with a year and must contain only alphanumeric characters, dashes(-), ampersands(&), periods(.), colons(:), apostrophes('), and spaces( )" cannot_manage: "Cannot manage competition." cannot_delete_public: "Cannot delete a competition that is publicly visible."