Skip to content
Closed
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
28 changes: 26 additions & 2 deletions lib/secretariat/trade_party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ 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,
:contact_name, :contact_phone, :contact_email,
keyword_init: true,
) do
# BG-6 / BG-9 contact. contact_name is the fork's name for upstream's
# person_name (BT-56); both feed the single DefinedTradeContact element.
def contact?
contact_person_name.present? || contact_phone.present? || contact_email.present?
end

def contact_person_name
contact_name.present? ? contact_name : person_name
end

def to_xml(xml, exclude_tax: false, version: 2)
if id && !exclude_tax
xml['ram'].ID id # BT-46
Expand All @@ -40,9 +51,22 @@ def to_xml(xml, exclude_tax: false, version: 2)
end
end
end
if person_name
if version == 2 && contact?
# EN16931 BG-6 SELLER CONTACT (required by XRechnung CIUS rule BR-DE-2)
xml['ram'].DefinedTradeContact do
xml['ram'].PersonName person_name
if contact_person_name.present?
xml['ram'].PersonName contact_person_name
end
if contact_phone.present?
xml['ram'].TelephoneUniversalCommunication do
xml['ram'].CompleteNumber contact_phone
end
end
if contact_email.present?
xml['ram'].EmailURIUniversalCommunication do
xml['ram'].URIID contact_email
end
end
end
end
xml['ram'].PostalTradeAddress do
Expand Down
15 changes: 14 additions & 1 deletion test/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ def make_de_invoice
city: 'Hamburg',
postal_code: '20253',
country_id: 'DE',
vat_id: 'DE304755032'
vat_id: 'DE304755032',
contact_name: 'Depfu Buchhaltung',
contact_phone: '+49 40 123456',
contact_email: 'billing@depfu.com'
)
buyer = TradeParty.new(
name: 'Depfu inc',
Expand Down Expand Up @@ -709,6 +712,16 @@ def test_simple_eu_invoice_with_attachment_against_schematron
assert_equal [], errors
end

def test_seller_contact_is_rendered_for_v2
xml = make_de_invoice.to_xml(version: 2)
doc = Nokogiri::XML(xml)
contact = doc.at_xpath('//ram:SellerTradeParty/ram:DefinedTradeContact', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100')
assert contact, 'expected DefinedTradeContact to be rendered'
assert_equal 'Depfu Buchhaltung', contact.at_xpath('ram:PersonName', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100').text
assert_equal '+49 40 123456', contact.at_xpath('ram:TelephoneUniversalCommunication/ram:CompleteNumber', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100').text
assert_equal 'billing@depfu.com', contact.at_xpath('ram:EmailURIUniversalCommunication/ram:URIID', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100').text
end

def test_simple_de_invoice_v2
xml = make_de_invoice.to_xml(version: 2)
v = Validator.new(xml, version: 2)
Expand Down
Loading