gobl 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/data/tax/ES.json +841 -0
  3. data/data/tax/FR.json +47 -0
  4. data/data/tax/GB.json +56 -0
  5. data/data/tax/NL.json +60 -0
  6. data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +30 -0
  7. data/lib/extensions.rb +12 -0
  8. data/lib/gobl/bill/advances.rb +90 -0
  9. data/lib/gobl/bill/charge.rb +121 -0
  10. data/lib/gobl/bill/delivery.rb +79 -0
  11. data/lib/gobl/bill/discount.rb +121 -0
  12. data/lib/gobl/bill/exchange_rates.rb +90 -0
  13. data/lib/gobl/bill/invoice.rb +209 -0
  14. data/lib/gobl/bill/invoice_type.rb +163 -0
  15. data/lib/gobl/bill/line.rb +121 -0
  16. data/lib/gobl/bill/line_charge.rb +79 -0
  17. data/lib/gobl/bill/line_discount.rb +79 -0
  18. data/lib/gobl/bill/ordering.rb +58 -0
  19. data/lib/gobl/bill/outlay.rb +107 -0
  20. data/lib/gobl/bill/payment.rb +79 -0
  21. data/lib/gobl/bill/preceding.rb +114 -0
  22. data/lib/gobl/bill/scheme_keys.rb +90 -0
  23. data/lib/gobl/bill/tax.rb +72 -0
  24. data/lib/gobl/bill/totals.rb +135 -0
  25. data/lib/gobl/cal/date.rb +106 -0
  26. data/lib/gobl/cal/period.rb +63 -0
  27. data/lib/gobl/config.rb +14 -0
  28. data/lib/gobl/currency/code.rb +322 -0
  29. data/lib/gobl/currency/exchange_rate.rb +65 -0
  30. data/lib/gobl/document.rb +70 -0
  31. data/lib/gobl/dsig/digest.rb +65 -0
  32. data/lib/gobl/dsig/signature.rb +106 -0
  33. data/lib/gobl/envelope.rb +77 -0
  34. data/lib/gobl/header.rb +98 -0
  35. data/lib/gobl/i18n/string.rb +72 -0
  36. data/lib/gobl/id.rb +80 -0
  37. data/lib/gobl/l10n/code.rb +106 -0
  38. data/lib/gobl/l10n/country_code.rb +405 -0
  39. data/lib/gobl/note/message.rb +72 -0
  40. data/lib/gobl/num/amount.rb +248 -0
  41. data/lib/gobl/num/percentage.rb +84 -0
  42. data/lib/gobl/operations/service_error.rb +10 -0
  43. data/lib/gobl/operations/validation_result.rb +46 -0
  44. data/lib/gobl/operations.rb +170 -0
  45. data/lib/gobl/org/address.rb +156 -0
  46. data/lib/gobl/org/code.rb +106 -0
  47. data/lib/gobl/org/coordinates.rb +79 -0
  48. data/lib/gobl/org/email.rb +79 -0
  49. data/lib/gobl/org/inbox.rb +86 -0
  50. data/lib/gobl/org/item.rb +121 -0
  51. data/lib/gobl/org/item_code.rb +65 -0
  52. data/lib/gobl/org/key.rb +106 -0
  53. data/lib/gobl/org/meta.rb +72 -0
  54. data/lib/gobl/org/name.rb +114 -0
  55. data/lib/gobl/org/note.rb +79 -0
  56. data/lib/gobl/org/note_key.rb +181 -0
  57. data/lib/gobl/org/party.rb +135 -0
  58. data/lib/gobl/org/person.rb +100 -0
  59. data/lib/gobl/org/registration.rb +99 -0
  60. data/lib/gobl/org/source_key.rb +161 -0
  61. data/lib/gobl/org/tax_identity.rb +93 -0
  62. data/lib/gobl/org/telephone.rb +72 -0
  63. data/lib/gobl/org/unit.rb +204 -0
  64. data/lib/gobl/pay/advance.rb +107 -0
  65. data/lib/gobl/pay/card.rb +65 -0
  66. data/lib/gobl/pay/credit_transfer.rb +86 -0
  67. data/lib/gobl/pay/direct_debit.rb +72 -0
  68. data/lib/gobl/pay/due_date.rb +86 -0
  69. data/lib/gobl/pay/instructions.rb +114 -0
  70. data/lib/gobl/pay/method_key.rb +163 -0
  71. data/lib/gobl/pay/online.rb +65 -0
  72. data/lib/gobl/pay/term_key.rb +166 -0
  73. data/lib/gobl/pay/terms.rb +79 -0
  74. data/lib/gobl/stamp.rb +63 -0
  75. data/lib/gobl/struct.rb +48 -0
  76. data/lib/gobl/tax/category.rb +83 -0
  77. data/lib/gobl/tax/category_total.rb +87 -0
  78. data/lib/gobl/tax/combo.rb +79 -0
  79. data/lib/gobl/tax/localities.rb +90 -0
  80. data/lib/gobl/tax/locality.rb +72 -0
  81. data/lib/gobl/tax/rate.rb +77 -0
  82. data/lib/gobl/tax/rate_total.rb +82 -0
  83. data/lib/gobl/tax/rate_total_surcharge.rb +63 -0
  84. data/lib/gobl/tax/rate_value.rb +79 -0
  85. data/lib/gobl/tax/region.rb +100 -0
  86. data/lib/gobl/tax/scheme.rb +86 -0
  87. data/lib/gobl/tax/schemes.rb +90 -0
  88. data/lib/gobl/tax/set.rb +90 -0
  89. data/lib/gobl/tax/total.rb +65 -0
  90. data/lib/gobl/types.rb +17 -0
  91. data/lib/gobl/uuid/uuid.rb +106 -0
  92. data/lib/gobl/version.rb +5 -0
  93. data/lib/gobl.rb +41 -0
  94. data/lib/gobl_extensions/document_helper.rb +45 -0
  95. data/lib/gobl_extensions/envelope_helper.rb +15 -0
  96. data/lib/gobl_extensions/i18n/value_keys_helper.rb +27 -0
  97. data/lib/gobl_extensions/tax/region_helper.rb +41 -0
  98. metadata +225 -0
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ ## DO NOT EDIT - This file was generated automatically.
5
+ ##
6
+ ## Generated with GOBL v0.30.4
7
+ ##
8
+
9
+ module GOBL
10
+ module Bill
11
+ # ExchangeRates represents an array of currency exchange rates.
12
+ class ExchangeRates < GOBL::Struct
13
+ extend Forwardable
14
+ include Enumerable
15
+
16
+ # The Schema ID of the GOBL ExchangeRates structure
17
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/ExchangeRates'
18
+
19
+ attribute :_ary, GOBL::Types::Array.of(GOBL::Currency::ExchangeRate)
20
+
21
+ # @!method [](*args)
22
+ # Returns elements from the array
23
+ # @overload [](index)
24
+ # Returns the element in a specific position
25
+ # @param index [Integer] the position of the object
26
+ # @return [GOBL::Currency::ExchangeRate] the element in the `index` position
27
+ # @overload [](start, length)
28
+ # Returns all the elements within a range of positions
29
+ # @param start [Integer] start position of the range
30
+ # @param length [Integer] length of the range
31
+ # @return [Array<GOBL::Currency::ExchangeRate>] the elements in the range
32
+ # @overload [](range)
33
+ # Returns all the elements within a range
34
+ # @param range [Range] start and end positions of the range
35
+ # @return [Array<GOBL::Currency::ExchangeRate>] the elements in the range
36
+ #
37
+ # @!method each
38
+ # Iterates over the array elements
39
+ # @overload each(&block)
40
+ # Calls the given block with each element in the array
41
+ # @yield [element] element of the array
42
+ # @return [self] the object itself
43
+ # @overload each
44
+ # Returns an Enumerator that iterates over the array elements
45
+ # @return [Enumerator] the enumerator of the array elements
46
+ #
47
+ # @!method empty?
48
+ # Returns `true` if the number of elements in the array is zero, `false` otherwise.
49
+ # @return [Boolean] whether the array is empty or not
50
+ #
51
+ # @!method length
52
+ # Returns the number of elements in the array
53
+ # @return [Integer] the number of elements in the array
54
+ def_delegators :_ary, :[], :each, :empty?, :length
55
+
56
+ # Creates a new object from an array of GOBL data
57
+ #
58
+ # @param data [Array] an array of GOBL data
59
+ #
60
+ # @return [ExchangeRates] the object created from the given data
61
+ def self.from_gobl!(data)
62
+ new(_ary: data&.map { |item| GOBL::Currency::ExchangeRate.from_gobl!(item) })
63
+ end
64
+
65
+ # Returns an array of GOBL data representing the current object
66
+ #
67
+ # @return [Array<Hash>] the array of GOBL data that represents the current object
68
+ def to_gobl
69
+ _ary.map(&:to_gobl)
70
+ end
71
+
72
+ # Returns a {ExchangeRates} object from a given array of structs. The array may
73
+ # contain {GOBL::Currency::ExchangeRate} objects or hashes. If hashes are provided, the constructor
74
+ # will call `GOBL::Currency::ExchangeRate#new` to generate the objects that will be part of the
75
+ # returned {ExchangeRates} object
76
+ #
77
+ # @param object [Array<GOBL::Currency::ExchangeRate, Hash>] the array containing the structs
78
+ #
79
+ # @return [ExchangeRates] the object corresponding to the given input
80
+ def self.new(object)
81
+ case object
82
+ when Array
83
+ super _ary: object
84
+ else # internal use, not to be used in public calls
85
+ super
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,209 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ ## DO NOT EDIT - This file was generated automatically.
5
+ ##
6
+ ## Generated with GOBL v0.30.4
7
+ ##
8
+
9
+ module GOBL
10
+ module Bill
11
+ # Invoice represents a payment claim for goods or services supplied under conditions agreed between the supplier and the customer.
12
+ class Invoice < GOBL::Struct
13
+ # The Schema ID of the GOBL Invoice structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique document ID. Not required, but always recommended in addition to the Code.
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] code
22
+ # Sequential code used to identify this invoice in tax declarations.
23
+ # @return [String]
24
+ attribute :code, GOBL::Types::String
25
+
26
+ # @!attribute [r] series
27
+ # Used in addition to the Code in some regions.
28
+ # @return [String]
29
+ attribute? :series, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] type
32
+ # Optional invoice type, leave empty unless needed for a specific situation.
33
+ # @return [InvoiceType]
34
+ attribute? :type, InvoiceType.optional
35
+
36
+ # @!attribute [r] currency
37
+ # Currency for all invoice totals.
38
+ # @return [GOBL::Currency::Code]
39
+ attribute :currency, GOBL::Currency::Code
40
+
41
+ # @!attribute [r] exchange_rates
42
+ # Exchange rates to be used when converting the invoices monetary values into other currencies.
43
+ # @return [ExchangeRates]
44
+ attribute? :exchange_rates, ExchangeRates.optional
45
+
46
+ # @!attribute [r] tax
47
+ # Special tax configuration for billing.
48
+ # @return [Tax]
49
+ attribute? :tax, Tax.optional
50
+
51
+ # @!attribute [r] preceding
52
+ # Key information regarding a previous invoice and potentially details as to why it was corrected.
53
+ # @return [Preceding]
54
+ attribute? :preceding, Preceding.optional
55
+
56
+ # @!attribute [r] issue_date
57
+ # When the invoice was created.
58
+ # @return [GOBL::Cal::Date]
59
+ attribute :issue_date, GOBL::Cal::Date
60
+
61
+ # @!attribute [r] op_date
62
+ # Date when the operation defined by the invoice became effective.
63
+ # @return [GOBL::Cal::Date]
64
+ attribute? :op_date, GOBL::Cal::Date.optional
65
+
66
+ # @!attribute [r] value_date
67
+ # When the taxes of this invoice become accountable, if none set, the issue date is used.
68
+ # @return [GOBL::Cal::Date]
69
+ attribute? :value_date, GOBL::Cal::Date.optional
70
+
71
+ # @!attribute [r] supplier
72
+ # The taxable entity supplying the goods or services.
73
+ # @return [GOBL::Org::Party]
74
+ attribute :supplier, GOBL::Org::Party
75
+
76
+ # @!attribute [r] customer
77
+ # Legal entity receiving the goods or services, may be empty in certain circumstances such as simplified invoices.
78
+ # @return [GOBL::Org::Party]
79
+ attribute? :customer, GOBL::Org::Party.optional
80
+
81
+ # @!attribute [r] lines
82
+ # List of invoice lines representing each of the items sold to the customer.
83
+ # @return [Array<Line>]
84
+ attribute? :lines, GOBL::Types::Array.of(Line).optional
85
+
86
+ # @!attribute [r] discounts
87
+ # Discounts or allowances applied to the complete invoice
88
+ # @return [Array<Discount>]
89
+ attribute? :discounts, GOBL::Types::Array.of(Discount).optional
90
+
91
+ # @!attribute [r] charges
92
+ # Charges or surcharges applied to the complete invoice
93
+ # @return [Array<Charge>]
94
+ attribute? :charges, GOBL::Types::Array.of(Charge).optional
95
+
96
+ # @!attribute [r] outlays
97
+ # Expenses paid for by the supplier but invoiced directly to the customer.
98
+ # @return [Array<Outlay>]
99
+ attribute? :outlays, GOBL::Types::Array.of(Outlay).optional
100
+
101
+ # @!attribute [r] ordering
102
+ # @return [Ordering]
103
+ attribute? :ordering, Ordering.optional
104
+
105
+ # @!attribute [r] payment
106
+ # @return [Payment]
107
+ attribute? :payment, Payment.optional
108
+
109
+ # @!attribute [r] delivery
110
+ # @return [Delivery]
111
+ attribute? :delivery, Delivery.optional
112
+
113
+ # @!attribute [r] totals
114
+ # Summary of all the invoice totals, including taxes (calculated).
115
+ # @return [Totals]
116
+ attribute? :totals, Totals.optional
117
+
118
+ # @!attribute [r] notes
119
+ # Unstructured information that is relevant to the invoice, such as correction or additional legal details.
120
+ # @return [Array<GOBL::Org::Note>]
121
+ attribute? :notes, GOBL::Types::Array.of(GOBL::Org::Note).optional
122
+
123
+ # @!attribute [r] meta
124
+ # Additional semi-structured data that doesn't fit into the body of the invoice.
125
+ # @return [GOBL::Org::Meta]
126
+ attribute? :meta, GOBL::Org::Meta.optional
127
+
128
+ # Creates a new object from a hash of GOBL data
129
+ #
130
+ # @param data [Hash] a hash of GOBL data
131
+ #
132
+ # @return [Invoice] the object created from the given data
133
+ def self.from_gobl!(data)
134
+ data = GOBL::Types::Hash[data]
135
+
136
+ new(
137
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
138
+ code: data['code'],
139
+ series: data['series'],
140
+ type: data['type'] ? InvoiceType.from_gobl!(data['type']) : nil,
141
+ currency: GOBL::Currency::Code.from_gobl!(data['currency']),
142
+ exchange_rates: data['exchange_rates'] ? ExchangeRates.from_gobl!(data['exchange_rates']) : nil,
143
+ tax: data['tax'] ? Tax.from_gobl!(data['tax']) : nil,
144
+ preceding: data['preceding'] ? Preceding.from_gobl!(data['preceding']) : nil,
145
+ issue_date: GOBL::Cal::Date.from_gobl!(data['issue_date']),
146
+ op_date: data['op_date'] ? GOBL::Cal::Date.from_gobl!(data['op_date']) : nil,
147
+ value_date: data['value_date'] ? GOBL::Cal::Date.from_gobl!(data['value_date']) : nil,
148
+ supplier: GOBL::Org::Party.from_gobl!(data['supplier']),
149
+ customer: data['customer'] ? GOBL::Org::Party.from_gobl!(data['customer']) : nil,
150
+ lines: data['lines']&.map { |item| Line.from_gobl!(item) },
151
+ discounts: data['discounts']&.map { |item| Discount.from_gobl!(item) },
152
+ charges: data['charges']&.map { |item| Charge.from_gobl!(item) },
153
+ outlays: data['outlays']&.map { |item| Outlay.from_gobl!(item) },
154
+ ordering: data['ordering'] ? Ordering.from_gobl!(data['ordering']) : nil,
155
+ payment: data['payment'] ? Payment.from_gobl!(data['payment']) : nil,
156
+ delivery: data['delivery'] ? Delivery.from_gobl!(data['delivery']) : nil,
157
+ totals: data['totals'] ? Totals.from_gobl!(data['totals']) : nil,
158
+ notes: data['notes']&.map { |item| GOBL::Org::Note.from_gobl!(item) },
159
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
160
+ )
161
+ end
162
+
163
+ # Returns a hash of GOBL data representing the current object
164
+ #
165
+ # @return [Hash] the array of GOBL data that represents the current object
166
+ def to_gobl
167
+ {
168
+ 'uuid' => attributes[:uuid]&.to_gobl,
169
+ 'code' => attributes[:code],
170
+ 'series' => attributes[:series],
171
+ 'type' => attributes[:type]&.to_gobl,
172
+ 'currency' => attributes[:currency]&.to_gobl,
173
+ 'exchange_rates' => attributes[:exchange_rates]&.to_gobl,
174
+ 'tax' => attributes[:tax]&.to_gobl,
175
+ 'preceding' => attributes[:preceding]&.to_gobl,
176
+ 'issue_date' => attributes[:issue_date]&.to_gobl,
177
+ 'op_date' => attributes[:op_date]&.to_gobl,
178
+ 'value_date' => attributes[:value_date]&.to_gobl,
179
+ 'supplier' => attributes[:supplier]&.to_gobl,
180
+ 'customer' => attributes[:customer]&.to_gobl,
181
+ 'lines' => attributes[:lines]&.map { |item| item&.to_gobl },
182
+ 'discounts' => attributes[:discounts]&.map { |item| item&.to_gobl },
183
+ 'charges' => attributes[:charges]&.map { |item| item&.to_gobl },
184
+ 'outlays' => attributes[:outlays]&.map { |item| item&.to_gobl },
185
+ 'ordering' => attributes[:ordering]&.to_gobl,
186
+ 'payment' => attributes[:payment]&.to_gobl,
187
+ 'delivery' => attributes[:delivery]&.to_gobl,
188
+ 'totals' => attributes[:totals]&.to_gobl,
189
+ 'notes' => attributes[:notes]&.map { |item| item&.to_gobl },
190
+ 'meta' => attributes[:meta]&.to_gobl
191
+ }.compact
192
+ end
193
+
194
+ # @!method self.new(attrs)
195
+ #
196
+ # Returns a {Invoice} object from a given hash of attributes. Nested
197
+ # attributes are supported: the constructor will instantiate the proper GOBL
198
+ # objects when nested hashes or arrays are given as part of the `attrs`
199
+ # parameter.
200
+ #
201
+ # The `new` method will only allow to create a new object if all attributes
202
+ # marked as mandatory and not calculated in the JSON schema are provided.
203
+ #
204
+ # @param attrs [Hash] the hash of attributes
205
+ #
206
+ # @return [Invoice] the object corresponding to the given input
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ ## DO NOT EDIT - This file was generated automatically.
5
+ ##
6
+ ## Generated with GOBL v0.30.4
7
+ ##
8
+
9
+ module GOBL
10
+ module Bill
11
+ # Defines an invoice type according to a subset of the UNTDID 1001 standard list.
12
+ class InvoiceType < GOBL::Struct
13
+ # The Schema ID of the GOBL InvoiceType structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/InvoiceType'
15
+
16
+ # The enumeration of values of the object and their descriptions (Values different to these are not allowed)
17
+ ENUM = {
18
+ 'proforma' => 'Proforma invoice, for a clients validation before sending a final invoice.',
19
+ 'simplified' => 'Simplified invoice or receipt typically used for small transactions that dont require customer details.t require customer details.',
20
+ 'partial' => 'Partial invoice',
21
+ 'commercial' => 'Commercial invoice, usually cross-border transactions requiring an invoice for customs.',
22
+ 'corrected' => 'Corrected invoice',
23
+ 'credit-note' => 'Credit note',
24
+ 'self-billed' => 'Self billed invoice'
25
+ }.freeze
26
+
27
+ attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
28
+ private :_value
29
+
30
+ # Creates a new object from a GOBL value
31
+ #
32
+ # @param data [String] the GOBL value
33
+ #
34
+ # @return [InvoiceType] the object created from the given data
35
+ def self.from_gobl!(data)
36
+ new(_value: data)
37
+ end
38
+
39
+ # Returns a GOBL value representing the current object
40
+ #
41
+ # @return [String] the GOBL value that represents the current object
42
+ def to_gobl
43
+ _value
44
+ end
45
+
46
+ # Returns a {InvoiceType} that corresponds to a given object. The object can be a
47
+ # `Symbol`, a `String` or anything coercible into one (via `#to_s`).
48
+ #
49
+ # @param object [Symbol, String, #to_s] the value of the object.
50
+ #
51
+ # @return [InvoiceType] the object corresponding to the given value.
52
+ #
53
+ # @example Instantiating from a symbol
54
+ # invoice_type = GOBL::Bill::InvoiceType.new(:proforma)
55
+ #
56
+ # @example Instantiating from a string
57
+ # invoice_type = GOBL::Bill::InvoiceType.new('proforma')
58
+ def self.new(object)
59
+ case object
60
+ when Hash, self # internal use, not to be used in public calls
61
+ super
62
+ when Symbol
63
+ new find_by_sym(object)
64
+ else
65
+ super _value: object.to_s
66
+ end
67
+ end
68
+
69
+ # Returns the string representation of the current object
70
+ #
71
+ # @return [String] the string representation of the current object
72
+ def to_s
73
+ _value.to_s
74
+ end
75
+
76
+ # Returns the symbol representation of the current object
77
+ #
78
+ # @return [Symbol] the symbol representation of the current object
79
+ def to_sym
80
+ to_s.parameterize.underscore.to_sym
81
+ end
82
+
83
+ # Returns whether the current object is equivalent to a given one. In addition
84
+ # to {InvoiceType} objects, the current object can be compared to a `Symbol`, a
85
+ # `String` or anything coercible into one (via `#to_s`)
86
+ #
87
+ # @param other [InvoiceType, Symbol, String, #to_s] the other object to compare to
88
+ #
89
+ # @return [Boolean] `true` if the objects are equivalent, `false` otherwise
90
+ #
91
+ # @example Comparing to another {InvoiceType} object
92
+ # invoice_type = GOBL::Bill::InvoiceType.new('proforma')
93
+ # invoice_type == GOBL::Bill::InvoiceType.new('proforma') #=> true
94
+ # invoice_type == GOBL::Bill::InvoiceType.new('simplified') #=> false
95
+ #
96
+ # @example Comparing to a string
97
+ # invoice_type = GOBL::Bill::InvoiceType.new('proforma')
98
+ # invoice_type == 'proforma' #=> true
99
+ # invoice_type == 'simplified' #=> false
100
+ #
101
+ # @example Comparing to a symbol
102
+ # invoice_type = GOBL::Bill::InvoiceType.new('proforma')
103
+ # invoice_type == :proforma #=> true
104
+ # invoice_type == :simplified #=> false
105
+ def ==(other)
106
+ case other
107
+ when self.class
108
+ super
109
+ when Symbol
110
+ to_sym == other
111
+ else
112
+ to_s == other.to_s
113
+ end
114
+ end
115
+
116
+ # Returns an array with all the enumerated objects of this type
117
+ #
118
+ # @return [Array<InvoiceType>] the array of enumerated objects
119
+ def self.all
120
+ ENUM.keys.map { |key| new(key) }
121
+ end
122
+
123
+ # @api private
124
+ def self.find_by_sym(sym)
125
+ all.find { |object| object.to_sym == sym }
126
+ end
127
+
128
+ # @api private
129
+ def self.find_by_inquirer(method_name)
130
+ method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
131
+ end
132
+
133
+ # Returns the description of the current object
134
+ #
135
+ # @return [String] the description of the current object
136
+ def description
137
+ ENUM.fetch(_value, _value)
138
+ end
139
+
140
+ # @api private
141
+ def respond_to_missing?(method_name, include_private = false)
142
+ self.class.find_by_inquirer(method_name) || super
143
+ end
144
+
145
+ # Enables dynamic value inquirers like `InvoiceType#proforma?` for
146
+ # each of the declared enum values (see {ENUM}). Each inquirer returns a
147
+ # `Boolean` denoting whether the value equals the enquired value (`true`) or
148
+ # not (`false`)
149
+ #
150
+ # @example
151
+ # invoice_type = GOBL::Bill::InvoiceType.new('proforma')
152
+ # invoice_type.proforma? # => true
153
+ # invoice_type.simplified? # => false
154
+ def method_missing(method_name, *args, &block)
155
+ if value = self.class.find_by_inquirer(method_name)
156
+ self == value
157
+ else
158
+ super
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ ## DO NOT EDIT - This file was generated automatically.
5
+ ##
6
+ ## Generated with GOBL v0.30.4
7
+ ##
8
+
9
+ module GOBL
10
+ module Bill
11
+ # Line is a single row in an invoice.
12
+ class Line < GOBL::Struct
13
+ # The Schema ID of the GOBL Line structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Line'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique identifier for this line
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] i
22
+ # Line number inside the parent (calculated)
23
+ # @return [Integer]
24
+ attribute? :i, GOBL::Types::Int.optional
25
+
26
+ # @!attribute [r] quantity
27
+ # Number of items
28
+ # @return [GOBL::Num::Amount]
29
+ attribute :quantity, GOBL::Types.Constructor(GOBL::Num::Amount)
30
+
31
+ # @!attribute [r] item
32
+ # Details about what is being sold
33
+ # @return [GOBL::Org::Item]
34
+ attribute :item, GOBL::Org::Item
35
+
36
+ # @!attribute [r] sum
37
+ # Result of quantity multiplied by the item's price (calculated)
38
+ # @return [GOBL::Num::Amount]
39
+ attribute? :sum, GOBL::Types.Constructor(GOBL::Num::Amount).optional
40
+
41
+ # @!attribute [r] discounts
42
+ # Discounts applied to this line
43
+ # @return [Array<LineDiscount>]
44
+ attribute? :discounts, GOBL::Types::Array.of(LineDiscount).optional
45
+
46
+ # @!attribute [r] charges
47
+ # Charges applied to this line
48
+ # @return [Array<LineCharge>]
49
+ attribute? :charges, GOBL::Types::Array.of(LineCharge).optional
50
+
51
+ # @!attribute [r] taxes
52
+ # Map of taxes to be applied and used in the invoice totals
53
+ # @return [GOBL::Tax::Set]
54
+ attribute? :taxes, GOBL::Tax::Set.optional
55
+
56
+ # @!attribute [r] total
57
+ # Total line amount after applying discounts to the sum (calculated).
58
+ # @return [GOBL::Num::Amount]
59
+ attribute? :total, GOBL::Types.Constructor(GOBL::Num::Amount).optional
60
+
61
+ # @!attribute [r] notes
62
+ # Set of specific notes for this line that may be required for clarification.
63
+ # @return [Array<GOBL::Org::Note>]
64
+ attribute? :notes, GOBL::Types::Array.of(GOBL::Org::Note).optional
65
+
66
+ # Creates a new object from a hash of GOBL data
67
+ #
68
+ # @param data [Hash] a hash of GOBL data
69
+ #
70
+ # @return [Line] the object created from the given data
71
+ def self.from_gobl!(data)
72
+ data = GOBL::Types::Hash[data]
73
+
74
+ new(
75
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
76
+ i: data['i'],
77
+ quantity: data['quantity'],
78
+ item: GOBL::Org::Item.from_gobl!(data['item']),
79
+ sum: data['sum'] || nil,
80
+ discounts: data['discounts']&.map { |item| LineDiscount.from_gobl!(item) },
81
+ charges: data['charges']&.map { |item| LineCharge.from_gobl!(item) },
82
+ taxes: data['taxes'] ? GOBL::Tax::Set.from_gobl!(data['taxes']) : nil,
83
+ total: data['total'] || nil,
84
+ notes: data['notes']&.map { |item| GOBL::Org::Note.from_gobl!(item) }
85
+ )
86
+ end
87
+
88
+ # Returns a hash of GOBL data representing the current object
89
+ #
90
+ # @return [Hash] the array of GOBL data that represents the current object
91
+ def to_gobl
92
+ {
93
+ 'uuid' => attributes[:uuid]&.to_gobl,
94
+ 'i' => attributes[:i],
95
+ 'quantity' => attributes[:quantity]&.to_gobl,
96
+ 'item' => attributes[:item]&.to_gobl,
97
+ 'sum' => attributes[:sum]&.to_gobl,
98
+ 'discounts' => attributes[:discounts]&.map { |item| item&.to_gobl },
99
+ 'charges' => attributes[:charges]&.map { |item| item&.to_gobl },
100
+ 'taxes' => attributes[:taxes]&.to_gobl,
101
+ 'total' => attributes[:total]&.to_gobl,
102
+ 'notes' => attributes[:notes]&.map { |item| item&.to_gobl }
103
+ }.compact
104
+ end
105
+
106
+ # @!method self.new(attrs)
107
+ #
108
+ # Returns a {Line} object from a given hash of attributes. Nested
109
+ # attributes are supported: the constructor will instantiate the proper GOBL
110
+ # objects when nested hashes or arrays are given as part of the `attrs`
111
+ # parameter.
112
+ #
113
+ # The `new` method will only allow to create a new object if all attributes
114
+ # marked as mandatory and not calculated in the JSON schema are provided.
115
+ #
116
+ # @param attrs [Hash] the hash of attributes
117
+ #
118
+ # @return [Line] the object corresponding to the given input
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ ## DO NOT EDIT - This file was generated automatically.
5
+ ##
6
+ ## Generated with GOBL v0.30.4
7
+ ##
8
+
9
+ module GOBL
10
+ module Bill
11
+ # LineCharge represents an amount added to the line, and will be applied before taxes.
12
+ class LineCharge < GOBL::Struct
13
+ # The Schema ID of the GOBL LineCharge structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/LineCharge'
15
+
16
+ # @!attribute [r] percent
17
+ # Percentage if fixed amount not applied
18
+ # @return [GOBL::Num::Percentage]
19
+ attribute? :percent, GOBL::Types.Constructor(GOBL::Num::Percentage).optional
20
+
21
+ # @!attribute [r] amount
22
+ # Fixed or resulting charge amount to apply (calculated if percent present).
23
+ # @return [GOBL::Num::Amount]
24
+ attribute? :amount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
25
+
26
+ # @!attribute [r] code
27
+ # Reference code.
28
+ # @return [String]
29
+ attribute? :code, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] reason
32
+ # Text description as to why the charge was applied
33
+ # @return [String]
34
+ attribute? :reason, GOBL::Types::String.optional
35
+
36
+ # Creates a new object from a hash of GOBL data
37
+ #
38
+ # @param data [Hash] a hash of GOBL data
39
+ #
40
+ # @return [LineCharge] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ percent: data['percent'] || nil,
46
+ amount: data['amount'] || nil,
47
+ code: data['code'],
48
+ reason: data['reason']
49
+ )
50
+ end
51
+
52
+ # Returns a hash of GOBL data representing the current object
53
+ #
54
+ # @return [Hash] the array of GOBL data that represents the current object
55
+ def to_gobl
56
+ {
57
+ 'percent' => attributes[:percent]&.to_gobl,
58
+ 'amount' => attributes[:amount]&.to_gobl,
59
+ 'code' => attributes[:code],
60
+ 'reason' => attributes[:reason]
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {LineCharge} object from a given hash of attributes. Nested
67
+ # attributes are supported: the constructor will instantiate the proper GOBL
68
+ # objects when nested hashes or arrays are given as part of the `attrs`
69
+ # parameter.
70
+ #
71
+ # The `new` method will only allow to create a new object if all attributes
72
+ # marked as mandatory and not calculated in the JSON schema are provided.
73
+ #
74
+ # @param attrs [Hash] the hash of attributes
75
+ #
76
+ # @return [LineCharge] the object corresponding to the given input
77
+ end
78
+ end
79
+ end