1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

fix accounting period checksum + improved period validation

This commit is contained in:
Sylvain 2019-03-12 15:26:17 +01:00
parent 4f418cc3fb
commit 857b1cebba
6 changed files with 21 additions and 15 deletions

View File

@ -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 : ''}"

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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: