Class: Einvoicing::Party

Inherits:
Data
  • Object
show all
Defined in:
lib/einvoicing/party.rb

Overview

Represents a seller or buyer on an invoice.

Examples:

Einvoicing::Party.new(
  name: "Acme SAS",
  street: "1 rue de la Paix",
  city: "Paris",
  postal_code: "75001",
  country_code: "FR",
  siren: "123456789",
  vat_number: "FR12123456789"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, street: nil, city: nil, postal_code: nil, country_code: "FR", siren: nil, siret: nil, vat_number: nil, email: nil, endpoint_id: nil, endpoint_scheme: nil) ⇒ Party

Returns a new instance of Party.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/einvoicing/party.rb', line 19

def initialize(name:, street: nil, city: nil, postal_code: nil,
               country_code: "FR", siren: nil, siret: nil,
               vat_number: nil, email: nil,
               endpoint_id: nil, endpoint_scheme: nil)
  # Peppol endpoint: prefer explicit endpoint_id, then SIRET (scheme 0002 = FR standard),
  # then email (scheme EM). "EM" is not in the Peppol EAS codelist so it won't pass
  # Peppol validation — callers should provide endpoint_id + endpoint_scheme explicitly
  # or ensure siret is set for French parties.
  resolved_endpoint_id = endpoint_id || siret || email
  resolved_endpoint_scheme = if endpoint_scheme
                               endpoint_scheme
  elsif endpoint_id
                               nil  # caller must supply scheme when explicit
  elsif siret
                               "0002"  # SIRET scheme — Peppol EAS FR standard
  elsif email
                               "EM"    # email fallback (not in Peppol EAS, use for non-Peppol)
  end
  super(name: name, street: street, city: city, postal_code: postal_code,
        country_code: country_code, siren: siren, siret: siret,
        vat_number: vat_number, email: email,
        endpoint_id: resolved_endpoint_id, endpoint_scheme: resolved_endpoint_scheme)
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city

Returns:

  • (Object)

    the current value of city



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def city
  @city
end

#country_codeObject (readonly)

Returns the value of attribute country_code

Returns:

  • (Object)

    the current value of country_code



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def country_code
  @country_code
end

#emailObject (readonly)

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def email
  @email
end

#endpoint_idObject (readonly)

Returns the value of attribute endpoint_id

Returns:

  • (Object)

    the current value of endpoint_id



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def endpoint_id
  @endpoint_id
end

#endpoint_schemeObject (readonly)

Returns the value of attribute endpoint_scheme

Returns:

  • (Object)

    the current value of endpoint_scheme



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def endpoint_scheme
  @endpoint_scheme
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def name
  @name
end

#postal_codeObject (readonly)

Returns the value of attribute postal_code

Returns:

  • (Object)

    the current value of postal_code



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def postal_code
  @postal_code
end

#sirenObject (readonly)

Returns the value of attribute siren

Returns:

  • (Object)

    the current value of siren



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def siren
  @siren
end

#siretObject (readonly)

Returns the value of attribute siret

Returns:

  • (Object)

    the current value of siret



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def siret
  @siret
end

#streetObject (readonly)

Returns the value of attribute street

Returns:

  • (Object)

    the current value of street



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def street
  @street
end

#vat_numberObject (readonly)

Returns the value of attribute vat_number

Returns:

  • (Object)

    the current value of vat_number



16
17
18
# File 'lib/einvoicing/party.rb', line 16

def vat_number
  @vat_number
end

Instance Method Details

#fetch_siret!Party

Look up SIRET via the Sirene API and return a new Party with siret filled in. No-op (returns self) if siren is blank or siret is already set.

Returns:

  • (Party)

    self or new Party with siret populated



52
53
54
55
56
57
58
59
# File 'lib/einvoicing/party.rb', line 52

def fetch_siret!
  return self unless siren_number && siret.nil?

  result = SiretLookup.find(siren_number)
  return self unless result

  with(siret: result[:siret])
end

#siren_numberObject

The 9-digit SIREN derived from SIRET if siren not provided directly.



44
45
46
# File 'lib/einvoicing/party.rb', line 44

def siren_number
  siren || (siret && siret[0, 9])
end