Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/secretariat/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ module Secretariat
:TON => "TNE",
:WEEK => "WEE"
}

SPECIFICATION_IDS = {
:XRECHNUNG_3_0 => "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"
}

BUSINESS_PROCESS_IDS = {
:PEPPOL_BILLING => "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"
}
end
9 changes: 8 additions & 1 deletion lib/secretariat/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Secretariat
using ObjectExtensions

Invoice = Struct.new("Invoice",
:specification_id,
:business_process_id,
:id,
:issue_date,
:service_period_start,
Expand Down Expand Up @@ -199,9 +201,14 @@ def to_xml(version: 1, validate: true)
context = by_version(version, 'SpecifiedExchangedDocumentContext', 'ExchangedDocumentContext')

xml['rsm'].send(context) do
if business_process_id.present?
xml['ram'].BusinessProcessSpecifiedDocumentContextParameter do
xml['ram'].ID business_process_id
end
end
xml['ram'].GuidelineSpecifiedDocumentContextParameter do
version_id = by_version(version, 'urn:ferd:CrossIndustryDocument:invoice:1p0:comfort', 'urn:cen.eu:en16931:2017')
xml['ram'].ID version_id
xml['ram'].ID specification_id || version_id
end
end

Expand Down
23 changes: 23 additions & 0 deletions test/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -884,5 +884,28 @@ def test_invoice_with_quantity_causing_sub_cent_amounts
end
assert_equal [], errors
end

def test_default_specification_id
xml = make_de_invoice.to_xml(version: 2)

assert_match(/<ram:GuidelineSpecifiedDocumentContextParameter>\s*<ram:ID>urn:cen.eu:en16931:2017<\/ram:ID>/, xml)
end

def test_custom_specification_id
invoice = make_de_invoice
invoice.specification_id = SPECIFICATION_IDS[:XRECHNUNG_3_0]
xml = invoice.to_xml(version: 2)

assert_match(/<ram:ID>#{Regexp.escape(SPECIFICATION_IDS[:XRECHNUNG_3_0])}<\/ram:ID>/, xml)
end

def test_business_process_id
invoice = make_de_invoice
invoice.business_process_id = BUSINESS_PROCESS_IDS[:PEPPOL_BILLING]
xml = invoice.to_xml(version: 2)

assert_match(/<ram:BusinessProcessSpecifiedDocumentContextParameter>\s*<ram:ID>#{Regexp.escape(BUSINESS_PROCESS_IDS[:PEPPOL_BILLING])}<\/ram:ID>/, xml)
assert_equal [], Validator.new(xml, version: 2).validate_against_schema
end
end
end