2019-02-12 17:38:44 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Validates that all invoices in the current accounting period are chained with footprints which ensure their integrity
|
|
|
|
class PeriodIntegrityValidator < ActiveModel::Validator
|
|
|
|
def validate(record)
|
2021-06-07 14:15:39 +02:00
|
|
|
invoices = record.invoices.includes(:invoice_items)
|
2019-02-12 17:38:44 +01:00
|
|
|
|
|
|
|
invoices.each do |i|
|
2023-02-24 17:26:55 +01:00
|
|
|
record.errors.add("invoice_#{i.reference}".to_sym, I18n.t('errors.messages.invalid_footprint')) unless i.check_footprint
|
2019-02-12 17:38:44 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|