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

(bug) Accouning Line in duplicate

This commit is contained in:
Du Peng 2023-07-03 17:43:27 +02:00
parent 11a079b3e2
commit e50c90b30d
4 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,8 @@
# Changelog Fab-manager
- Fix a bug: unable to refresh machine/space/training calender after pay an reservation
- Fix a bug: Accouning Line in duplicate
- [TODO DEPLOY] `rails fablab:setup:build_accounting_lines`
## v6.0.7 2023 June 20

View File

@ -269,6 +269,8 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.14.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.14.3-x86_64-linux)
racc (~> 1.4)
oauth2 (1.4.4)
@ -524,6 +526,7 @@ GEM
zeitwerk (2.6.7)
PLATFORMS
x86_64-darwin-20
x86_64-linux
DEPENDENCIES

View File

@ -22,11 +22,19 @@ class Accounting::AccountingService
lines = []
processed = []
invoices.find_each do |i|
Rails.logger.debug { "processing invoice #{i.id}..." } unless Rails.env.test?
Rails.logger.debug { "[AccountLine] processing invoice #{i.id}..." } unless Rails.env.test?
if i.main_item.nil?
Rails.logger.error { "[AccountLine] invoice #{i.id} main_item is nil" } unless Rails.env.test?
else
lines.concat(generate_lines(i))
processed.push(i.id)
end
end
ActiveRecord::Base.transaction do
ids = invoices.map(&:id)
AccountingLine.where(invoice_id: ids).delete_all
AccountingLine.create!(lines)
end
processed
end

View File

@ -27,8 +27,6 @@ class AccountingWorker
end
def invoices(invoices_ids)
# clean
AccountingLine.where(invoice_id: invoices_ids).delete_all
# build
service = Accounting::AccountingService.new
invoices = Invoice.where(id: invoices_ids)
@ -37,8 +35,6 @@ class AccountingWorker
end
def all
# clean
AccountingLine.delete_all
# build
service = Accounting::AccountingService.new
ids = service.build_from_invoices(Invoice.all)