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

(api) accounting: report build status

This commit is contained in:
Sylvain 2022-12-08 16:14:59 +01:00
parent b7838db648
commit 3a05398c8c
4 changed files with 14 additions and 3 deletions

View File

@ -14,7 +14,8 @@ class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc
doc_for :index do
api :GET, "/#{API_VERSION}/accounting", 'Accounting lines'
description 'All accounting lines, paginated (necessarily becauce there is a lot of data) with optional dates filtering. ' \
'Ordered by *date* descendant.'
'Ordered by *date* descendant.<br><br>The field *status* indicates if the accounting data is being built ' \
'or if the build is over. Possible status are: <i>building</i> or <i>built</i>.'
param_group :pagination
param :after, DateTime, optional: true, desc: 'Filter accounting lines to lines after the given date.'
param :before, DateTime, optional: true, desc: 'Filter accounting lines to lines before the given date.'
@ -84,7 +85,8 @@ class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc
"currency": "EUR",
"summary": "Dupont Marcel, 22010009/VL, subscr."
}
]
],
"status": "built"
}
LINES
end

View File

@ -28,6 +28,14 @@ class Accounting::AccountingService
AccountingLine.create!(lines)
end
def self.status
workers = Sidekiq::Workers.new
workers.each do |_process_id, _thread_id, work|
return 'building' if work['payload']['class'] == 'AccountingWorker'
end
'built'
end
private
def generate_lines(invoice)

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
json.lines @lines do |line|
json.extract! line, :id, :line_type, :journal_code, :date, :account_code, :account_label, :analytical_code, :debit, :credit, :currency, :summary
json.invoice do
@ -10,3 +9,4 @@ json.lines @lines do |line|
end
json.user_invoicing_profile_id line.invoicing_profile_id
end
json.status Accounting::AccountingService.status

View File

@ -33,6 +33,7 @@ class OpenApi::AccountingTest < ActionDispatch::IntegrationTest
assert_not_nil lines[:lines][0][:credit]
assert_not_empty lines[:lines][0][:currency]
assert_not_empty lines[:lines][0][:summary]
assert_equal 'built', lines[:status]
end
test 'list all accounting lines with pagination' do