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

Can only update a competition's currency code if there are no unrefunded payments #10497

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Loading