Skip to content
Merged
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
7 changes: 5 additions & 2 deletions lib/secretariat/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ def to_xml(xml, line_item_index, version: 2, validate: true)
if (version == 2)
xml['ram'].SpecifiedTradeProduct do
xml['ram'].Name name
xml['ram'].OriginTradeCountry do
xml['ram'].ID origin_country_code
# BT-159 is optional; it describes where goods were made, which a service doesn't have.
unless origin_country_code.to_s.empty?
xml['ram'].OriginTradeCountry do
xml['ram'].ID origin_country_code
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,20 @@ def test_fr_invoice
assert_match(%r{<ram:SpecifiedLegalOrganization>\s*<ram:ID schemeID="0002">304755032</ram:ID>\s*</ram:SpecifiedLegalOrganization>}, xml)
end

def test_origin_country_is_written_when_given
xml = make_de_invoice.to_xml(version: 2)
assert_match(%r{<ram:OriginTradeCountry>\s*<ram:ID>DE</ram:ID>\s*</ram:OriginTradeCountry>}, xml)
end

def test_line_without_origin_country
invoice = make_eu_invoice
invoice.line_items.each { |line_item| line_item.origin_country_code = nil }
xml = invoice.to_xml(version: 2)

refute_match(/OriginTradeCountry/, xml)
assert_equal [], Validator.new(xml, version: 2).validate_against_schematron
end

def test_invoice_with_quantity_causing_sub_cent_amounts
errors = []

Expand Down
Loading