Skip to content

Commit

Permalink
#264 validates if the scholarship level and the enrollment level are …
Browse files Browse the repository at this point in the history
…equal
  • Loading branch information
Carlos-Eduardo-Cabral-da-Cunha committed May 10, 2018
1 parent 43bb540 commit 435ab36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/scholarship_duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ScholarshipDuration < ApplicationRecord
#validates if scholarship isn't with another student
validate :if_scholarship_is_not_with_another_student

validate :scholarship_level_equals_enrollment_level

# #validates if a scholarship duration start date isn't before it's end date
validates_date :start_date, :on_or_before => :end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.attributes.start_date_after_end_date")
Expand Down Expand Up @@ -187,4 +188,10 @@ def update_end_and_cancel_dates
self.cancel_date = self.cancel_date.end_of_month unless self.cancel_date.nil?
end

def scholarship_level_equals_enrollment_level
if defined?(scholarship.level_id) && defined?(enrollment.level_id) && (scholarship.level_id != enrollment.level_id)
errors.add(:scholarship, I18n.t("activerecord.errors.models.scholarship_duration.the_levels_of_scholarship_and_enrollment_are_different"))
end
end

end
1 change: 1 addition & 0 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ pt-BR:
end_date:
on_or_after: "anterior a Data de Início"
scholarship_duration:
the_levels_of_scholarship_and_enrollment_are_different: "não pode ser alocado a esta Matrícula porque eles são de níveis diferentes"
end_date_after_scholarship_end_date: "posterior a Data de Fim de Bolsa"
end_date_before_scholarship_start_date: "anterior a Data de Início de Bolsa"
enrollment_and_scholarship_uniqueness: "já possui uma Bolsa alocada nesse período"
Expand Down

0 comments on commit 435ab36

Please sign in to comment.