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
13 changes: 10 additions & 3 deletions lib/secretariat/trade_party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

module Secretariat
using ObjectExtensions

TradeParty = Struct.new('TradeParty',
:id,
:name, :street1, :street2, :city, :postal_code, :country_id, :vat_id, :global_id, :global_id_scheme_id, :tax_id,
:person_name,
:person_name, :legal_organization,
keyword_init: true,
) do
def to_xml(xml, exclude_tax: false, version: 2)
Expand All @@ -33,6 +33,13 @@ def to_xml(xml, exclude_tax: false, version: 2)
end
end
xml['ram'].Name name
if legal_organization.present?
xml['ram'].SpecifiedLegalOrganization do
xml['ram'].ID(schemeID: legal_organization[:scheme_id] || "0002") do
xml.text(legal_organization[:id])
end
end
end
if person_name
xml['ram'].DefinedTradeContact do
xml['ram'].PersonName person_name
Expand Down Expand Up @@ -64,4 +71,4 @@ def to_xml(xml, exclude_tax: false, version: 2)
end
end

# assert_match(%r{<ram:DefinedTradeContact>\s*<ram:PersonName>Max Mustermann</ram:PersonName>\s*</ram:DefinedTradeContact>}, xml)
# assert_match(%r{<ram:DefinedTradeContact>\s*<ram:PersonName>Max Mustermann</ram:PersonName>\s*</ram:DefinedTradeContact>}, xml)
67 changes: 67 additions & 0 deletions test/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,67 @@ def make_negative_de_invoice
)
end

def make_fr_invoice
seller = TradeParty.new(
name: 'France inc',
legal_organization: { id: '304755032', scheme_id: '0002' },
street1: '1 rue de Rivoli',
city: 'PARIS',
postal_code: '75001',
country_id: 'FR',
vat_id: 'FR304755032'
)
buyer = TradeParty.new(
name: 'France inc',
person_name: 'Max Mustermann',
street1: '1 rue de Rivoli',
city: 'PARIS',
postal_code: '75001',
country_id: 'FR',
vat_id: 'FR304755032'
)
line_item = LineItem.new(
name: 'Depfu Starter Plan',
quantity: 1,
unit: :PIECE,
gross_amount: BigDecimal('29'),
net_amount: BigDecimal('20'),
charge_amount: BigDecimal('20'),
discount_amount: BigDecimal('9'),
discount_reason: 'Rabatt',
tax_category: :STANDARDRATE,
tax_percent: '19',
tax_amount: BigDecimal("3.80"),
origin_country_code: 'DE',
currency_code: 'EUR'
)
Invoice.new(
id: '12345',
issue_date: Date.today,
service_period_start: Date.today,
service_period_end: Date.today + 30,
seller: seller,
buyer: buyer,
ship_to: false,
buyer_reference: "112233",
line_items: [line_item],
currency_code: 'USD',
payment_type: :CREDITCARD,
payment_text: 'Kreditkarte',
payment_reference: 'INV 123123123',
payment_iban: 'DE02120300000000202051',
payment_terms_text: "Zahlbar innerhalb von 14 Tagen ohne Abzug",
tax_category: :STANDARDRATE,
tax_amount: BigDecimal('3.80'),
basis_amount: BigDecimal('20'),
grand_total_amount: BigDecimal('23.80'),
due_amount: 0,
paid_amount: BigDecimal('23.80'),
payment_due_date: Date.today + 14
)
end


def test_simple_eu_invoice_v2
begin
xml = make_eu_invoice.to_xml(version: 2)
Expand Down Expand Up @@ -792,6 +853,12 @@ def test_invoice_object_extensions
assert_match(%r{<ram:DefinedTradeContact>\s*<ram:PersonName>Max Mustermann</ram:PersonName>\s*</ram:DefinedTradeContact>}, xml)
end

def test_fr_invoice
invoice = make_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_invoice_with_quantity_causing_sub_cent_amounts
errors = []

Expand Down