Module: Validations::Sales::SetupValidations
- Includes:
- CollectionTimeHelper, Validations::SharedValidations
- Defined in:
- sales/setup_validations.rb
Instance Method Summary collapse
- #validate_merged_organisations_saledate(record) ⇒ Object
- #validate_organisation(record) ⇒ Object
- #validate_saledate_collection_year(record) ⇒ Object
- #validate_saledate_two_weeks(record) ⇒ Object
Instance Method Details
#validate_merged_organisations_saledate(record) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'sales/setup_validations.rb', line 27 def validate_merged_organisations_saledate(record) return unless record.saledate && date_valid?("saledate", record) if merged_owning_organisation_inactive?(record) record.errors.add :saledate, I18n.t("validations.setup.saledate.invalid_merged_organisations_saledate", owning_organisation: record.owning_organisation.name, owning_organisation_merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date), owning_absorbing_organisation: record.owning_organisation.absorbing_organisation.name) end if absorbing_owning_organisation_inactive?(record) record.errors.add :saledate, I18n.t("validations.setup.saledate.invalid_absorbing_organisations_saledate", owning_organisation: record.owning_organisation.name, owning_organisation_available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date)) end end |
#validate_organisation(record) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'sales/setup_validations.rb', line 44 def validate_organisation(record) return unless record.saledate && record.owning_organisation if record.owning_organisation.present? if record.owning_organisation&.merge_date.present? && record.owning_organisation.merge_date <= record.saledate record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_merged_organisation_sales", owning_organisation: record.owning_organisation.name, owning_organisation_merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date), owning_absorbing_organisation: record.owning_organisation.absorbing_organisation.name) elsif record.owning_organisation&.absorbed_organisations.present? && record.owning_organisation.available_from.present? && record.owning_organisation.available_from.to_date > record.saledate.to_date record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_absorbing_organisation_sales", owning_organisation: record.owning_organisation.name, owning_organisation_available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date)) end end end |
#validate_saledate_collection_year(record) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'sales/setup_validations.rb', line 5 def validate_saledate_collection_year(record) return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use? first_collection_start_date = if record.saledate_was.present? editable_collection_start_date else active_collection_start_date end unless record.saledate.between?(first_collection_start_date, current_collection_end_date) record.errors.add :saledate, end end |
#validate_saledate_two_weeks(record) ⇒ Object
19 20 21 22 23 24 25 |
# File 'sales/setup_validations.rb', line 19 def validate_saledate_two_weeks(record) return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use? if record.saledate > Time.zone.today + 14.days record.errors.add :saledate, I18n.t("validations.setup.saledate.later_than_14_days_after") end end |