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
10 changes: 10 additions & 0 deletions lib/secretariat/trade_party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Secretariat
:id,
:name, :street1, :street2, :city, :postal_code, :country_id, :vat_id, :global_id, :global_id_scheme_id, :tax_id,
:person_name, :legal_organization,
:electronic_address, :electronic_address_scheme_id,
keyword_init: true,
) do
def to_xml(xml, exclude_tax: false, version: 2)
Expand Down Expand Up @@ -54,6 +55,15 @@ def to_xml(xml, exclude_tax: false, version: 2)
xml['ram'].CityName city
xml['ram'].CountryID country_id
end
# EN16931 BT-34 / BT-49, the scheme (BT-34-1 / BT-49-1) is mandatory (BR-62, BR-63).
# Like the ID, it is left out of the ShipToTradeParty, where it is not used.
if version == 2 && !exclude_tax && electronic_address.present? && electronic_address_scheme_id.present?
xml['ram'].URIUniversalCommunication do
xml['ram'].URIID(schemeID: electronic_address_scheme_id) do
xml.text(electronic_address)
end
end
end
if !exclude_tax && vat_id.present?
xml['ram'].SpecifiedTaxRegistration do
xml['ram'].ID(schemeID: 'VA') do
Expand Down
25 changes: 25 additions & 0 deletions test/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,32 @@ def test_fr_invoice
xml = invoice.to_xml(version: 2)
assert_match(%r{<ram:SpecifiedLegalOrganization>\s*<ram:ID schemeID="0002">304755032</ram:ID>\s*</ram:SpecifiedLegalOrganization>}, xml)
end

def test_electronic_addresses_of_seller_and_buyer
invoice = make_eu_invoice
invoice.seller.electronic_address = 'invoices@depfu.com'
invoice.seller.electronic_address_scheme_id = 'EM'
invoice.buyer.electronic_address = 'accounting@example.se'
invoice.buyer.electronic_address_scheme_id = 'EM'
xml = invoice.to_xml(version: 2)

assert_match(%r{</ram:PostalTradeAddress>\s*<ram:URIUniversalCommunication>\s*<ram:URIID schemeID="EM">invoices@depfu.com</ram:URIID>\s*</ram:URIUniversalCommunication>\s*<ram:SpecifiedTaxRegistration>}, xml)
assert_equal 1, xml.scan('accounting@example.se').size # not repeated in the ShipToTradeParty
assert_equal [], Validator.new(xml, version: 2).validate_against_schematron
end

def test_electronic_address_without_scheme_is_omitted
invoice = make_de_invoice
invoice.seller.electronic_address = 'invoices@depfu.com'
xml = invoice.to_xml(version: 2)
refute_match(/<ram:URIUniversalCommunication>/, xml)
end

def test_no_electronic_address_by_default
xml = make_de_invoice.to_xml(version: 2)
refute_match(/<ram:URIUniversalCommunication>/, 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)
Expand Down
Loading