mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-19 08:52:25 +01:00
(api) accounting: invoice.payment_details.payment_mean
This commit is contained in:
parent
4d7e09c98d
commit
40dd3f11b8
@ -14,8 +14,15 @@ class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc
|
|||||||
doc_for :index do
|
doc_for :index do
|
||||||
api :GET, "/#{API_VERSION}/accounting", 'Accounting lines'
|
api :GET, "/#{API_VERSION}/accounting", 'Accounting lines'
|
||||||
description 'All accounting lines, paginated (necessarily becauce there is a lot of data) with optional dates filtering. ' \
|
description 'All accounting lines, paginated (necessarily becauce there is a lot of data) with optional dates filtering. ' \
|
||||||
'Ordered by *date* descendant.<br><br>The field *status* indicates if the accounting data is being built ' \
|
'Ordered by *date* descendant.<br>' \
|
||||||
'or if the build is over. Possible status are: <i>building</i> or <i>built</i>.'
|
'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>.<br>' \
|
||||||
|
'The field *invoice.payment_details* is available if line_type=client. It will contain the following data:<br>' \
|
||||||
|
'· *payment_mean*, possible status are: <i>card</i>, <i>wallet</i> or <i>other</i>. *WARNING*: If an invoice was settled ' \
|
||||||
|
'using multiple payment means, this will only report the payment mean applicable to current line.<br>' \
|
||||||
|
'· *gateway_object_id*, if payment_mean=card, report the ID of the payment gateway related object<br>' \
|
||||||
|
'· *gateway_object_type*, if payment_mean=card, report the type of the payment gateway related object<br>' \
|
||||||
|
'· *wallet_transaction_id*, if payment_mean=wallet, report the ID of the wallet transaction<br>'
|
||||||
param_group :pagination
|
param_group :pagination
|
||||||
param :after, DateTime, optional: true, desc: 'Filter accounting lines to lines after the given date.'
|
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 :before, DateTime, optional: true, desc: 'Filter accounting lines to lines before the given date.'
|
||||||
@ -38,9 +45,17 @@ class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc
|
|||||||
"reference": "22010009/VL",
|
"reference": "22010009/VL",
|
||||||
"id": 274,
|
"id": 274,
|
||||||
"label": "Subscription of Dupont Marcel for 1 month starting from 2022, january 2nd",
|
"label": "Subscription of Dupont Marcel for 1 month starting from 2022, january 2nd",
|
||||||
"url": "/open_api/v1/invoices/247/download"
|
"url": "/open_api/v1/invoices/247/download",
|
||||||
|
"payment_details": {
|
||||||
|
"payment_mean": "card",
|
||||||
|
"gateway_object_id": "pi_3MA2PPW4kx8QemzC02ABBEbo",
|
||||||
|
"gateway_object_type": "Stripe::PaymentIntent"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"invoicing_profile_id": 6512,
|
||||||
|
"external_id": "U52-ALC4"
|
||||||
},
|
},
|
||||||
"user_invoicing_profile_id": 6512,
|
|
||||||
"debit": 1400,
|
"debit": 1400,
|
||||||
"credit": 0
|
"credit": 0
|
||||||
"currency": "EUR",
|
"currency": "EUR",
|
||||||
|
@ -161,14 +161,15 @@ class Invoice < PaymentDocument
|
|||||||
when :card
|
when :card
|
||||||
if paid_by_card?
|
if paid_by_card?
|
||||||
{
|
{
|
||||||
|
payment_mean: mean,
|
||||||
gateway_object_id: payment_gateway_object.gateway_object_id,
|
gateway_object_id: payment_gateway_object.gateway_object_id,
|
||||||
gateway_object_type: payment_gateway_object.gateway_object_type
|
gateway_object_type: payment_gateway_object.gateway_object_type
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
when :wallet
|
when :wallet
|
||||||
{ wallet_transaction_id: wallet_transaction_id } if paid_by_wallet?
|
{ payment_mean: mean, wallet_transaction_id: wallet_transaction_id } if paid_by_wallet?
|
||||||
else
|
else
|
||||||
{}
|
{ payment_mean: mean }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ json.lines @lines do |line|
|
|||||||
json.extract! line.invoice, :reference, :id
|
json.extract! line.invoice, :reference, :id
|
||||||
json.label Invoices::LabelService.build(line.invoice)
|
json.label Invoices::LabelService.build(line.invoice)
|
||||||
json.url download_open_api_v1_invoice_path(line.invoice)
|
json.url download_open_api_v1_invoice_path(line.invoice)
|
||||||
if @codes.values.include?(line.account_code)
|
if @codes.values.include?(line.account_code) # if this is a 'client' line
|
||||||
mean = @codes.select { |_key, value| value == line.account_code }
|
mean = @codes.select { |_key, value| value == line.account_code }
|
||||||
json.payment_details line.invoice.payment_details(mean.keys[0])
|
json.payment_details line.invoice.payment_details(mean.keys[0])
|
||||||
end
|
end
|
||||||
|
@ -92,6 +92,7 @@ class OpenApi::AccountingTest < ActionDispatch::IntegrationTest
|
|||||||
assert lines[:lines].count.positive?
|
assert lines[:lines].count.positive?
|
||||||
assert(lines[:lines].all? { |line| line[:line_type] == 'client' })
|
assert(lines[:lines].all? { |line| line[:line_type] == 'client' })
|
||||||
assert(lines[:lines].all? { |line| !line[:invoice][:payment_details].nil? })
|
assert(lines[:lines].all? { |line| !line[:invoice][:payment_details].nil? })
|
||||||
|
assert(lines[:lines].all? { |line| %w[card wallet other].include?(line[:invoice][:payment_details][:payment_mean]) })
|
||||||
assert(lines[:lines].filter { |line| line[:account_code] == card_code }
|
assert(lines[:lines].filter { |line| line[:account_code] == card_code }
|
||||||
.none? { |line| line[:invoice][:payment_details][:gateway_object_id].nil? })
|
.none? { |line| line[:invoice][:payment_details][:gateway_object_id].nil? })
|
||||||
assert(lines[:lines].filter { |line| line[:account_code] == card_code }
|
assert(lines[:lines].filter { |line| line[:account_code] == card_code }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user