1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

(api) accounting: filter by type

This commit is contained in:
Sylvain 2022-12-08 16:24:40 +01:00
parent 3a05398c8c
commit 9b5cf8842e
3 changed files with 12 additions and 0 deletions

View File

@ -13,6 +13,7 @@ class OpenAPI::V1::AccountingController < OpenAPI::V1::BaseController
@lines = @lines.where('date >= ?', DateTime.parse(params[:after])) if params[:after].present?
@lines = @lines.where('date <= ?', DateTime.parse(params[:before])) if params[:before].present?
@lines = @lines.where(invoice_id: may_array(params[:invoice_id])) if params[:invoice_id].present?
@lines = @lines.where(line_type: may_array(params[:type])) if params[:type].present?
@lines = @lines.page(page).per(per_page)
paginate @lines, per_page: per_page

View File

@ -20,6 +20,7 @@ class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc
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.'
param :invoice_id, [Integer, Array], optional: true, desc: 'Scope the request to one or various invoices.'
param :type, %w[client vat item], optional: true, desc: 'Filter accounting lines by line type.'
example <<-LINES
# /open_api/v1/accounting?after=2022-01-01T00:00:00+02:00&page=1&per_page=3

View File

@ -67,4 +67,14 @@ class OpenApi::AccountingTest < ActionDispatch::IntegrationTest
assert lines[:lines].count.positive?
assert(lines[:lines].all? { |line| [1, 2, 3].include?(line[:invoice][:id]) })
end
test 'list all accounting lines with type filtering' do
get '/open_api/v1/accounting?type=[client,vat]', headers: open_api_headers(@token)
assert_response :success
assert_equal Mime[:json], response.content_type
lines = json_response(response.body)
assert lines[:lines].count.positive?
assert(lines[:lines].all? { |line| %w[client vat].include?(line[:line_type]) })
end
end