1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/validators/closed_period_validator.rb
2023-03-22 16:05:25 +01:00

17 lines
501 B
Ruby

# frozen_string_literal: true
# Validates the current invoice is not generated within a closed accounting period
class ClosedPeriodValidator < ActiveModel::Validator
def validate(record)
date = if record.is_a?(Avoir)
record.avoir_date
else
Time.current
end
AccountingPeriod.find_each do |period|
record.errors.add(:date, I18n.t('errors.messages.in_closed_period')) if date >= period.start_at && date <= period.end_at
end
end
end