1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

[bug] when generating an Avoir at a previous date, the resulting checksum may be invalid

This commit is contained in:
Sylvain 2019-05-27 11:11:21 +02:00
parent b4d491b346
commit 6f2483a51f
4 changed files with 40 additions and 12 deletions

View File

@ -1,5 +1,9 @@
# Changelog Fab Manager
- Fix a bug: when generating an Avoir at a previous date, the resulting checksum may be invalid
- [TODO DEPLOY] `rake fablab:setup:chain_invoices_items_records`
- [TODO DEPLOY] `rake fablab:setup:chain_invoices_records`
## v3.1.1 2019 April 8
- Fix a bug: when paying a reservation with wallet, the invoice footprint is not correctly updated

View File

@ -285,9 +285,8 @@ class Invoice < ActiveRecord::Base
end
def compute_footprint
max_date = created_at || DateTime.now
previous = Invoice.where('created_at < ?', max_date)
.order('created_at DESC')
previous = Invoice.where('id < ?', id)
.order('id DESC')
.limit(1)
columns = Invoice.columns.map(&:name)

View File

@ -23,9 +23,8 @@ class InvoiceItem < ActiveRecord::Base
private
def compute_footprint
max_date = created_at || Time.current
previous = InvoiceItem.where('created_at < ?', max_date)
.order('created_at DESC')
previous = InvoiceItem.where('id < ?', id)
.order('id DESC')
.limit(1)
columns = InvoiceItem.columns.map(&:name)

View File

@ -4,23 +4,49 @@ namespace :fablab do
namespace :setup do
desc 'assign all footprints to existing Invoice records'
task chain_invoices_records: :environment do
raise "Footprints were already generated, won't regenerate" if Invoice.where.not(footprint: nil).count.positive?
if Invoice.where.not(footprint: nil).count.positive?
print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
confirm = STDIN.gets.chomp
next unless confirm == 'y'
end
Invoice.order(:created_at).all.each(&:chain_record)
if AccountingPeriod.count.positive?
last_period = AccountingPeriod.order(start_at: 'DESC').first
puts "Regenerating from #{last_period.end_at}..."
Invoice.where('created_at > ?', last_period.end_at).order(:id).each(&:chain_record)
else
puts '(Re)generating all footprint...'
Invoice.order(:id).all.each(&:chain_record)
end
end
desc 'assign all footprints to existing InvoiceItem records'
task chain_invoices_items_records: :environment do
raise "Footprints were already generated, won't regenerate" if InvoiceItem.where.not(footprint: nil).count.positive?
if InvoiceItem.where.not(footprint: nil).count.positive?
print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
confirm = STDIN.gets.chomp
next unless confirm == 'y'
end
InvoiceItem.order(:created_at).all.each(&:chain_record)
if AccountingPeriod.count.positive?
last_period = AccountingPeriod.order(start_at: 'DESC').first
InvoiceItem.where('created_at > ?', last_period.end_at).order(:id).each(&:chain_record)
puts "Regenerating from #{last_period.end_at}..."
else
puts '(Re)generating all footprint...'
InvoiceItem.order(:id).all.each(&:chain_record)
end
end
desc 'assign all footprints to existing HistoryValue records'
task chain_history_values_records: :environment do
raise "Footprints were already generated, won't regenerate" if HistoryValue.where.not(footprint: nil).count.positive?
if HistoryValue.where.not(footprint: nil).count.positive?
print 'WARNING: Footprints were already generated. Regenerate? (y/n) '
confirm = STDIN.gets.chomp
next unless confirm == 'y'
end
HistoryValue.order(:created_at).all.each(&:chain_record)
HistoryValue.order(:id).all.each(&:chain_record)
end
desc 'assign environment value to all invoices'