1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(feat) clean accounting lines async before rebuilding

This commit is contained in:
Sylvain 2022-12-08 15:15:47 +01:00
parent 0ca7c8fb11
commit b7838db648
3 changed files with 6 additions and 2 deletions

View File

@ -26,7 +26,6 @@ class AdvancedAccounting < ApplicationRecord
raise TypeError "Unknown accountable_type #{accountable_type}"
end
ids = invoices.map(&:id)
AccountingLine.where(invoice_id: ids).destroy_all
AccountingWorker.perform_async(:invoices, ids)
end
end

View File

@ -77,7 +77,6 @@ class SettingService
def update_accounting_line(settings)
return unless settings.any? { |s| s.name.match(/^accounting_/) || s.name == 'advanced_accounting' }
AccountingLine.destroy_all
AccountingWorker.perform_async(:all)
end
end

View File

@ -14,12 +14,18 @@ class AccountingWorker
end
def invoices(invoices_ids)
# clean
AccountingLine.where(invoice_id: ids).destroy_all
# build
service = Accounting::AccountingService.new
invoices = Invoice.where(id: invoices_ids)
service.build_from_invoices(invoices)
end
def all
# clean
AccountingLine.destroy_all
# build
service = Accounting::AccountingService.new
service.build_from_invoices(Invoice.all)
end