From 811d7288e7bde810a8a2083a3667a04165f2db5c Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 11 Mar 2019 13:49:16 +0100 Subject: [PATCH] fix chain_record methods --- app/models/invoice.rb | 1 + app/models/invoice_item.rb | 1 + lib/tasks/fablab/setup.rake | 10 ++-------- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 4754ab089..33d75144c 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -218,6 +218,7 @@ class Invoice < ActiveRecord::Base def chain_record self.footprint = compute_footprint + save! end def check_footprint diff --git a/app/models/invoice_item.rb b/app/models/invoice_item.rb index caa02bee8..3d0cb940f 100644 --- a/app/models/invoice_item.rb +++ b/app/models/invoice_item.rb @@ -8,6 +8,7 @@ class InvoiceItem < ActiveRecord::Base def chain_record self.footprint = compute_footprint + save! end def check_footprint diff --git a/lib/tasks/fablab/setup.rake b/lib/tasks/fablab/setup.rake index 891c7cd2c..4375ae9c2 100644 --- a/lib/tasks/fablab/setup.rake +++ b/lib/tasks/fablab/setup.rake @@ -6,20 +6,14 @@ namespace :fablab do task chain_invoices_records: :environment do raise "Footprints were already generated, won't regenerate" if Invoice.where.not(footprint: nil).count.positive? - Invoice.order(:created_at).all.each do |i| - i.chain_record - i.save! - end + Invoice.order(:created_at).all.each(&:chain_record) 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? - InvoiceItem.order(:created_at).all.each do |i| - i.chain_record - i.save! - end + InvoiceItem.order(:created_at).all.each(&:chain_record) end desc 'assign environment value to all invoices'