diff --git a/app/models/accounting_period.rb b/app/models/accounting_period.rb index ed94691c8..48d2f66e4 100644 --- a/app/models/accounting_period.rb +++ b/app/models/accounting_period.rb @@ -47,10 +47,12 @@ class AccountingPeriod < ActiveRecord::Base end def vat_rate(date) - first_rate = vat_history.first + @vat_rates = vat_history if @vat_rates.nil? + + first_rate = @vat_rates.first return first_rate[:rate] if date < first_rate[:date] - vat_history.each do |h| + @vat_rates.each do |h| return h[:rate] if h[:date] <= date end end @@ -118,7 +120,7 @@ class AccountingPeriod < ActiveRecord::Base def compute_footprint columns = AccountingPeriod.columns.map(&:name) - .delete_if { |c| %w[footprint updated_at].include? c } + .delete_if { |c| %w[id footprint created_at updated_at].include? c } sha256 = Digest::SHA256.new sha256.hexdigest "#{columns.map { |c| self[c] }.join}#{previous_period ? previous_period.footprint : ''}" diff --git a/app/validators/date_range_validator.rb b/app/validators/date_range_validator.rb index cb6db1fe5..fccd59092 100644 --- a/app/validators/date_range_validator.rb +++ b/app/validators/date_range_validator.rb @@ -3,10 +3,10 @@ # Validates that start_at is same or before end_at in the given record class DateRangeValidator < ActiveModel::Validator def validate(record) - the_end = record.start_at - the_start = record.end_at - return unless the_end.present? && the_end > the_start + the_end = record.end_at + the_start = record.start_at + return if the_end.present? && the_end >= the_start - record.errors[:end_at] << "The end date can't be before the start date. Pick a date after #{the_start}" + record.errors[:end_at] << I18n.t('errors.messages.end_before_start', START: the_start) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index d9c88a85a..b6fdb2374 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -40,6 +40,7 @@ en: cannot_encompass: "can't encompass an existing accounting period" in_closed_period: "can't be within a closed accounting period" invalid_footprint: "invoice's checksum is invalid" + end_before_start: "The end date can't be before the start date. Pick a date after %{START}" activemodel: errors: diff --git a/config/locales/es.yml b/config/locales/es.yml index 9a910571d..e1c9ae2b6 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -36,10 +36,11 @@ es: cannot_be_blank_at_same_time: "no puede estar vacío cuando %{field} también está vacío" cannot_be_in_the_past: "no puede estar en el pasado" cannot_be_before_previous_value: "No puede estar antes del valor anterior." - cannot_overlap: "can't overlap an existing accounting period" # missing translation - cannot_encompass: "can't encompass an existing accounting period" # missing translation - in_closed_period: "can't be within a closed accounting period" # missing translation - invalid_footprint: "invoice's checksum is invalid" # missing translation + cannot_overlap: "can't overlap an existing accounting period" # missing translation + cannot_encompass: "can't encompass an existing accounting period" # missing translation + in_closed_period: "can't be within a closed accounting period" # missing translation + invalid_footprint: "invoice's checksum is invalid" # missing translation + end_before_start: "The end date can't be before the start date. Pick a date after %{START}" # missing translation activemodel: errors: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3df828a0e..2fea6427b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -40,6 +40,7 @@ fr: cannot_encompass: "ne peut pas englober une période comptable existante" in_closed_period: "ne peut pas être dans une période comptable fermée" invalid_footprint: "la somme de contrôle de la facture est invalide" + end_before_start: "La date de fin ne peut pas être antérieure à la date de début. Choisissez une date après le %{START}" activemodel: errors: diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 0cc6cf9c0..7a1b0111d 100755 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -36,10 +36,11 @@ pt: cannot_be_blank_at_same_time: "Não pode ficar em branco quando %{field} estiver em branco também" cannot_be_in_the_past: "não pode ser no passado" cannot_be_before_previous_value: "não pode ser antes do valor anterior" - cannot_overlap: "can't overlap an existing accounting period" # missing translation - cannot_encompass: "can't encompass an existing accounting period" # missing translation - in_closed_period: "can't be within a closed accounting period" # missing translation - invalid_footprint: "invoice's checksum is invalid" # missing translation + cannot_overlap: "can't overlap an existing accounting period" # missing translation + cannot_encompass: "can't encompass an existing accounting period" # missing translation + in_closed_period: "can't be within a closed accounting period" # missing translation + invalid_footprint: "invoice's checksum is invalid" # missing translation + end_before_start: "The end date can't be before the start date. Pick a date after %{START}" # missing translation activemodel: errors: