Class: Einvoicing::Party
- Inherits:
-
Data
- Object
- Data
- Einvoicing::Party
- Defined in:
- lib/einvoicing/party.rb
Overview
Represents a seller or buyer on an invoice.
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#endpoint_id ⇒ Object
readonly
Returns the value of attribute endpoint_id.
-
#endpoint_scheme ⇒ Object
readonly
Returns the value of attribute endpoint_scheme.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#postal_code ⇒ Object
readonly
Returns the value of attribute postal_code.
-
#siren ⇒ Object
readonly
Returns the value of attribute siren.
-
#siret ⇒ Object
readonly
Returns the value of attribute siret.
-
#street ⇒ Object
readonly
Returns the value of attribute street.
-
#vat_number ⇒ Object
readonly
Returns the value of attribute vat_number.
Instance Method Summary collapse
-
#fetch_siret! ⇒ Party
Look up SIRET via the Sirene API and return a new Party with siret filled in.
-
#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
constructor
A new instance of Party.
-
#siren_number ⇒ Object
The 9-digit SIREN derived from SIRET if siren not provided directly.
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
#city ⇒ Object (readonly)
Returns the value of attribute city
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def city @city end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def country_code @country_code end |
#email ⇒ Object (readonly)
Returns the value of attribute email
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def email @email end |
#endpoint_id ⇒ Object (readonly)
Returns the value of attribute endpoint_id
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def endpoint_id @endpoint_id end |
#endpoint_scheme ⇒ Object (readonly)
Returns the value of attribute endpoint_scheme
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def endpoint_scheme @endpoint_scheme end |
#name ⇒ Object (readonly)
Returns the value of attribute name
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def name @name end |
#postal_code ⇒ Object (readonly)
Returns the value of attribute postal_code
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def postal_code @postal_code end |
#siren ⇒ Object (readonly)
Returns the value of attribute siren
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def siren @siren end |
#siret ⇒ Object (readonly)
Returns the value of attribute siret
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def siret @siret end |
#street ⇒ Object (readonly)
Returns the value of attribute street
16 17 18 |
# File 'lib/einvoicing/party.rb', line 16 def street @street end |
#vat_number ⇒ Object (readonly)
Returns the value of attribute 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.
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_number ⇒ Object
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 |