From 9e39a0517cd0b55696ccfa0035d5eec09561f0e0 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 3 Apr 2019 16:56:47 +0200 Subject: [PATCH] [bug] vat rat in archives may be wrong --- CHANGELOG.md | 3 +++ app/models/accounting_period.rb | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 129132ec7..ca1a25e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog Fab Manager +- Improved end-user message when closing an accounting period +- Improved date checks before closing an accounting period +- Fix a bug: when VAT has changed during fab-manager's lifecycle, this may not be reflected in archives - Fix a bug: using a quote in event category's name results in angular $parse:syntax Error ## v3.0.1 2019 April 1st diff --git a/app/models/accounting_period.rb b/app/models/accounting_period.rb index 0ee4e389c..3909eaf43 100644 --- a/app/models/accounting_period.rb +++ b/app/models/accounting_period.rb @@ -62,8 +62,8 @@ class AccountingPeriod < ActiveRecord::Base first_rate = @vat_rates.first return first_rate[:rate] if date < first_rate[:date] - @vat_rates.each do |h| - return h[:rate] if h[:date] <= date + @vat_rates.each_index do |i| + return @vat_rates[i][:rate] if date >= @vat_rates[i][:date] && (@vat_rates[i + 1].nil? || date < @vat_rates[i + 1][:date]) end end @@ -105,7 +105,7 @@ class AccountingPeriod < ActiveRecord::Base end def archive_closed_data - data = invoices.includes(:invoice_items) + data = invoices.includes(:invoice_items).order(id: :asc) previous_file = previous_period&.archive_file last_archive_checksum = previous_file ? Checksum.file(previous_file) : nil json_data = to_json_archive(data, previous_file, last_archive_checksum)