gobl 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/data/tax/CO.json +420 -0
  3. data/data/tax/ES.json +61 -0
  4. data/lib/ext/hashme.rb +28 -0
  5. data/lib/gobl/bill/advances.rb +1 -77
  6. data/lib/gobl/bill/charge.rb +11 -65
  7. data/lib/gobl/bill/delivery.rb +5 -47
  8. data/lib/gobl/bill/discount.rb +11 -65
  9. data/lib/gobl/bill/exchange_rates.rb +1 -77
  10. data/lib/gobl/bill/invoice.rb +28 -104
  11. data/lib/gobl/bill/invoice_type.rb +3 -134
  12. data/lib/gobl/bill/line.rb +13 -65
  13. data/lib/gobl/bill/line_charge.rb +5 -47
  14. data/lib/gobl/bill/line_discount.rb +5 -47
  15. data/lib/gobl/bill/ordering.rb +2 -38
  16. data/lib/gobl/bill/outlay.rb +11 -59
  17. data/lib/gobl/bill/payment.rb +5 -47
  18. data/lib/gobl/bill/preceding.rb +12 -62
  19. data/lib/gobl/bill/scheme_keys.rb +1 -77
  20. data/lib/gobl/bill/tax.rb +4 -44
  21. data/lib/gobl/bill/totals.rb +17 -71
  22. data/lib/gobl/cal/date.rb +1 -90
  23. data/lib/gobl/cal/period.rb +5 -41
  24. data/lib/gobl/currency/code.rb +3 -134
  25. data/lib/gobl/currency/exchange_rate.rb +5 -41
  26. data/lib/gobl/document.rb +1 -58
  27. data/lib/gobl/dsig/digest.rb +5 -41
  28. data/lib/gobl/dsig/signature.rb +1 -90
  29. data/lib/gobl/enum.rb +81 -0
  30. data/lib/gobl/envelope.rb +9 -48
  31. data/lib/gobl/header.rb +10 -56
  32. data/lib/gobl/i18n/string.rb +1 -58
  33. data/lib/gobl/l10n/code.rb +1 -90
  34. data/lib/gobl/l10n/country_code.rb +3 -134
  35. data/lib/gobl/map.rb +62 -0
  36. data/lib/gobl/note/message.rb +5 -44
  37. data/lib/gobl/num/amount.rb +6 -35
  38. data/lib/gobl/object.rb +21 -0
  39. data/lib/gobl/operations.rb +3 -3
  40. data/lib/gobl/org/address.rb +18 -80
  41. data/lib/gobl/org/code.rb +1 -90
  42. data/lib/gobl/org/coordinates.rb +5 -47
  43. data/lib/gobl/org/email.rb +6 -47
  44. data/lib/gobl/org/inbox.rb +8 -50
  45. data/lib/gobl/org/item.rb +13 -65
  46. data/lib/gobl/org/item_code.rb +4 -41
  47. data/lib/gobl/org/key.rb +1 -90
  48. data/lib/gobl/org/meta.rb +1 -58
  49. data/lib/gobl/org/name.rb +12 -62
  50. data/lib/gobl/org/note.rb +6 -47
  51. data/lib/gobl/org/note_key.rb +3 -134
  52. data/lib/gobl/org/party.rb +14 -71
  53. data/lib/gobl/org/person.rb +9 -56
  54. data/lib/gobl/org/registration.rb +9 -59
  55. data/lib/gobl/org/source_key.rb +3 -134
  56. data/lib/gobl/org/tax_identity.rb +8 -53
  57. data/lib/gobl/org/telephone.rb +5 -44
  58. data/lib/gobl/org/unit.rb +1 -136
  59. data/lib/gobl/pay/advance.rb +11 -59
  60. data/lib/gobl/pay/card.rb +5 -41
  61. data/lib/gobl/pay/credit_transfer.rb +6 -50
  62. data/lib/gobl/pay/direct_debit.rb +4 -44
  63. data/lib/gobl/pay/due_date.rb +8 -50
  64. data/lib/gobl/pay/instructions.rb +11 -62
  65. data/lib/gobl/pay/method_key.rb +3 -134
  66. data/lib/gobl/pay/online.rb +4 -41
  67. data/lib/gobl/pay/term_key.rb +3 -134
  68. data/lib/gobl/pay/terms.rb +6 -47
  69. data/lib/gobl/stamp.rb +5 -41
  70. data/lib/gobl/struct.rb +15 -15
  71. data/lib/gobl/tax/category.rb +9 -50
  72. data/lib/gobl/tax/category_total.rb +11 -53
  73. data/lib/gobl/tax/combo.rb +6 -47
  74. data/lib/gobl/tax/localities.rb +1 -77
  75. data/lib/gobl/tax/locality.rb +6 -44
  76. data/lib/gobl/tax/rate.rb +8 -47
  77. data/lib/gobl/tax/rate_total.rb +9 -50
  78. data/lib/gobl/tax/rate_total_surcharge.rb +5 -41
  79. data/lib/gobl/tax/rate_value.rb +6 -47
  80. data/lib/gobl/tax/region.rb +12 -56
  81. data/lib/gobl/tax/scheme.rb +8 -50
  82. data/lib/gobl/tax/schemes.rb +1 -77
  83. data/lib/gobl/tax/set.rb +1 -77
  84. data/lib/gobl/tax/total.rb +4 -41
  85. data/lib/gobl/uuid/uuid.rb +1 -90
  86. data/lib/gobl/value.rb +58 -0
  87. data/lib/gobl/version.rb +1 -1
  88. data/lib/gobl.rb +3 -1
  89. data/lib/gobl_extensions/document_helper.rb +3 -3
  90. data/lib/gobl_extensions/envelope_helper.rb +5 -0
  91. data/lib/gobl_extensions/i18n/value_keys_helper.rb +3 -3
  92. data/lib/gobl_extensions/tax/region_helper.rb +3 -9
  93. metadata +12 -35
  94. data/lib/gobl/types.rb +0 -17
@@ -9,7 +9,7 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Defines an invoice type according to a subset of the UNTDID 1001 standard list.
12
- class InvoiceType < GOBL::Struct
12
+ class InvoiceType < GOBL::Enum
13
13
  # The Schema ID of the GOBL InvoiceType structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/InvoiceType'
15
15
 
@@ -24,139 +24,8 @@ module GOBL
24
24
  'self-billed' => 'Self billed invoice'
25
25
  }.freeze
26
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
27
+ def strict_enum?
28
+ true
160
29
  end
161
30
  end
162
31
  end
@@ -9,113 +9,61 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Line is a single row in an invoice.
12
- class Line < GOBL::Struct
12
+ class Line < GOBL::Object
13
13
  # The Schema ID of the GOBL Line structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Line'
15
15
 
16
16
  # @!attribute [r] uuid
17
17
  # Unique identifier for this line
18
18
  # @return [GOBL::UUID::UUID]
19
- attribute? :uuid, GOBL::UUID::UUID.optional
19
+ property :uuid, GOBL::UUID::UUID
20
20
 
21
21
  # @!attribute [r] i
22
22
  # Line number inside the parent (calculated)
23
23
  # @return [Integer]
24
- attribute? :i, GOBL::Types::Int.optional
24
+ property :i, Integer
25
25
 
26
26
  # @!attribute [r] quantity
27
27
  # Number of items
28
28
  # @return [GOBL::Num::Amount]
29
- attribute :quantity, GOBL::Types.Constructor(GOBL::Num::Amount)
29
+ property :quantity, GOBL::Num::Amount
30
+ validates :quantity, presence: true
30
31
 
31
32
  # @!attribute [r] item
32
33
  # Details about what is being sold
33
34
  # @return [GOBL::Org::Item]
34
- attribute :item, GOBL::Org::Item
35
+ property :item, GOBL::Org::Item
36
+ validates :item, presence: true
35
37
 
36
38
  # @!attribute [r] sum
37
39
  # Result of quantity multiplied by the item's price (calculated)
38
40
  # @return [GOBL::Num::Amount]
39
- attribute? :sum, GOBL::Types.Constructor(GOBL::Num::Amount).optional
41
+ property :sum, GOBL::Num::Amount
40
42
 
41
43
  # @!attribute [r] discounts
42
44
  # Discounts applied to this line
43
45
  # @return [Array<LineDiscount>]
44
- attribute? :discounts, GOBL::Types::Array.of(LineDiscount).optional
46
+ property :discounts, [LineDiscount]
45
47
 
46
48
  # @!attribute [r] charges
47
49
  # Charges applied to this line
48
50
  # @return [Array<LineCharge>]
49
- attribute? :charges, GOBL::Types::Array.of(LineCharge).optional
51
+ property :charges, [LineCharge]
50
52
 
51
53
  # @!attribute [r] taxes
52
54
  # Map of taxes to be applied and used in the invoice totals
53
55
  # @return [GOBL::Tax::Set]
54
- attribute? :taxes, GOBL::Tax::Set.optional
56
+ property :taxes, GOBL::Tax::Set
55
57
 
56
58
  # @!attribute [r] total
57
59
  # Total line amount after applying discounts to the sum (calculated).
58
60
  # @return [GOBL::Num::Amount]
59
- attribute? :total, GOBL::Types.Constructor(GOBL::Num::Amount).optional
61
+ property :total, GOBL::Num::Amount
60
62
 
61
63
  # @!attribute [r] notes
62
64
  # Set of specific notes for this line that may be required for clarification.
63
65
  # @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
66
+ property :notes, [GOBL::Org::Note]
119
67
  end
120
68
  end
121
69
  end
@@ -9,71 +9,29 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # LineCharge represents an amount added to the line, and will be applied before taxes.
12
- class LineCharge < GOBL::Struct
12
+ class LineCharge < GOBL::Object
13
13
  # The Schema ID of the GOBL LineCharge structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/LineCharge'
15
15
 
16
16
  # @!attribute [r] percent
17
17
  # Percentage if fixed amount not applied
18
18
  # @return [GOBL::Num::Percentage]
19
- attribute? :percent, GOBL::Types.Constructor(GOBL::Num::Percentage).optional
19
+ property :percent, GOBL::Num::Percentage
20
20
 
21
21
  # @!attribute [r] amount
22
22
  # Fixed or resulting charge amount to apply (calculated if percent present).
23
23
  # @return [GOBL::Num::Amount]
24
- attribute? :amount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
24
+ property :amount, GOBL::Num::Amount
25
25
 
26
26
  # @!attribute [r] code
27
27
  # Reference code.
28
28
  # @return [String]
29
- attribute? :code, GOBL::Types::String.optional
29
+ property :code, String
30
30
 
31
31
  # @!attribute [r] reason
32
32
  # Text description as to why the charge was applied
33
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
34
+ property :reason, String
77
35
  end
78
36
  end
79
37
  end
@@ -9,71 +9,29 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # LineDiscount represents an amount deducted from the line, and will be applied before taxes.
12
- class LineDiscount < GOBL::Struct
12
+ class LineDiscount < GOBL::Object
13
13
  # The Schema ID of the GOBL LineDiscount structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/LineDiscount'
15
15
 
16
16
  # @!attribute [r] percent
17
17
  # Percentage if fixed amount not applied
18
18
  # @return [GOBL::Num::Percentage]
19
- attribute? :percent, GOBL::Types.Constructor(GOBL::Num::Percentage).optional
19
+ property :percent, GOBL::Num::Percentage
20
20
 
21
21
  # @!attribute [r] amount
22
22
  # Fixed discount amount to apply (calculated if percent present).
23
23
  # @return [GOBL::Num::Amount]
24
- attribute? :amount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
24
+ property :amount, GOBL::Num::Amount
25
25
 
26
26
  # @!attribute [r] code
27
27
  # Reason code.
28
28
  # @return [String]
29
- attribute? :code, GOBL::Types::String.optional
29
+ property :code, String
30
30
 
31
31
  # @!attribute [r] reason
32
32
  # Text description as to why the discount was applied
33
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 [LineDiscount] 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 {LineDiscount} 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 [LineDiscount] the object corresponding to the given input
34
+ property :reason, String
77
35
  end
78
36
  end
79
37
  end
@@ -9,50 +9,14 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Ordering allows additional order details to be appended
12
- class Ordering < GOBL::Struct
12
+ class Ordering < GOBL::Object
13
13
  # The Schema ID of the GOBL Ordering structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Ordering'
15
15
 
16
16
  # @!attribute [r] seller
17
17
  # Party who is selling the goods and is not responsible for taxes
18
18
  # @return [GOBL::Org::Party]
19
- attribute? :seller, GOBL::Org::Party.optional
20
-
21
- # Creates a new object from a hash of GOBL data
22
- #
23
- # @param data [Hash] a hash of GOBL data
24
- #
25
- # @return [Ordering] the object created from the given data
26
- def self.from_gobl!(data)
27
- data = GOBL::Types::Hash[data]
28
-
29
- new(
30
- seller: data['seller'] ? GOBL::Org::Party.from_gobl!(data['seller']) : nil
31
- )
32
- end
33
-
34
- # Returns a hash of GOBL data representing the current object
35
- #
36
- # @return [Hash] the array of GOBL data that represents the current object
37
- def to_gobl
38
- {
39
- 'seller' => attributes[:seller]&.to_gobl
40
- }.compact
41
- end
42
-
43
- # @!method self.new(attrs)
44
- #
45
- # Returns a {Ordering} object from a given hash of attributes. Nested
46
- # attributes are supported: the constructor will instantiate the proper GOBL
47
- # objects when nested hashes or arrays are given as part of the `attrs`
48
- # parameter.
49
- #
50
- # The `new` method will only allow to create a new object if all attributes
51
- # marked as mandatory and not calculated in the JSON schema are provided.
52
- #
53
- # @param attrs [Hash] the hash of attributes
54
- #
55
- # @return [Ordering] the object corresponding to the given input
19
+ property :seller, GOBL::Org::Party
56
20
  end
57
21
  end
58
22
  end
@@ -9,99 +9,51 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Outlay represents a reimbursable expense that was paid for by the supplier and invoiced separately by the third party directly to the customer.
12
- class Outlay < GOBL::Struct
12
+ class Outlay < GOBL::Object
13
13
  # The Schema ID of the GOBL Outlay structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Outlay'
15
15
 
16
16
  # @!attribute [r] uuid
17
17
  # Unique identity for this outlay.
18
18
  # @return [GOBL::UUID::UUID]
19
- attribute? :uuid, GOBL::UUID::UUID.optional
19
+ property :uuid, GOBL::UUID::UUID
20
20
 
21
21
  # @!attribute [r] i
22
22
  # Outlay number index inside the invoice for ordering (calculated).
23
23
  # @return [Integer]
24
- attribute? :i, GOBL::Types::Int.optional
24
+ property :i, Integer
25
25
 
26
26
  # @!attribute [r] date
27
27
  # When was the outlay made.
28
28
  # @return [GOBL::Cal::Date]
29
- attribute? :date, GOBL::Cal::Date.optional
29
+ property :date, GOBL::Cal::Date
30
30
 
31
31
  # @!attribute [r] code
32
32
  # Invoice number or other reference detail used to identify the outlay.
33
33
  # @return [String]
34
- attribute? :code, GOBL::Types::String.optional
34
+ property :code, String
35
35
 
36
36
  # @!attribute [r] series
37
37
  # Series of the outlay invoice.
38
38
  # @return [String]
39
- attribute? :series, GOBL::Types::String.optional
39
+ property :series, String
40
40
 
41
41
  # @!attribute [r] desc
42
42
  # Details on what the outlay was.
43
43
  # @return [String]
44
- attribute :desc, GOBL::Types::String
44
+ property :desc, String
45
+ validates :desc, presence: true
45
46
 
46
47
  # @!attribute [r] supplier
47
48
  # Who was the supplier of the outlay
48
49
  # @return [GOBL::Org::Party]
49
- attribute? :supplier, GOBL::Org::Party.optional
50
+ property :supplier, GOBL::Org::Party
50
51
 
51
52
  # @!attribute [r] amount
52
53
  # Amount paid by the supplier.
53
54
  # @return [GOBL::Num::Amount]
54
- attribute :amount, GOBL::Types.Constructor(GOBL::Num::Amount)
55
-
56
- # Creates a new object from a hash of GOBL data
57
- #
58
- # @param data [Hash] a hash of GOBL data
59
- #
60
- # @return [Outlay] the object created from the given data
61
- def self.from_gobl!(data)
62
- data = GOBL::Types::Hash[data]
63
-
64
- new(
65
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
66
- i: data['i'],
67
- date: data['date'] ? GOBL::Cal::Date.from_gobl!(data['date']) : nil,
68
- code: data['code'],
69
- series: data['series'],
70
- desc: data['desc'],
71
- supplier: data['supplier'] ? GOBL::Org::Party.from_gobl!(data['supplier']) : nil,
72
- amount: data['amount']
73
- )
74
- end
75
-
76
- # Returns a hash of GOBL data representing the current object
77
- #
78
- # @return [Hash] the array of GOBL data that represents the current object
79
- def to_gobl
80
- {
81
- 'uuid' => attributes[:uuid]&.to_gobl,
82
- 'i' => attributes[:i],
83
- 'date' => attributes[:date]&.to_gobl,
84
- 'code' => attributes[:code],
85
- 'series' => attributes[:series],
86
- 'desc' => attributes[:desc],
87
- 'supplier' => attributes[:supplier]&.to_gobl,
88
- 'amount' => attributes[:amount]&.to_gobl
89
- }.compact
90
- end
91
-
92
- # @!method self.new(attrs)
93
- #
94
- # Returns a {Outlay} object from a given hash of attributes. Nested
95
- # attributes are supported: the constructor will instantiate the proper GOBL
96
- # objects when nested hashes or arrays are given as part of the `attrs`
97
- # parameter.
98
- #
99
- # The `new` method will only allow to create a new object if all attributes
100
- # marked as mandatory and not calculated in the JSON schema are provided.
101
- #
102
- # @param attrs [Hash] the hash of attributes
103
- #
104
- # @return [Outlay] the object corresponding to the given input
55
+ property :amount, GOBL::Num::Amount
56
+ validates :amount, presence: true
105
57
  end
106
58
  end
107
59
  end
@@ -9,71 +9,29 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Payment contains details as to how the invoice should be paid.
12
- class Payment < GOBL::Struct
12
+ class Payment < GOBL::Object
13
13
  # The Schema ID of the GOBL Payment structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Payment'
15
15
 
16
16
  # @!attribute [r] payer
17
17
  # The party responsible for paying for the invoice, if not the customer.
18
18
  # @return [GOBL::Org::Party]
19
- attribute? :payer, GOBL::Org::Party.optional
19
+ property :payer, GOBL::Org::Party
20
20
 
21
21
  # @!attribute [r] terms
22
22
  # Payment terms or conditions.
23
23
  # @return [GOBL::Pay::Terms]
24
- attribute? :terms, GOBL::Pay::Terms.optional
24
+ property :terms, GOBL::Pay::Terms
25
25
 
26
26
  # @!attribute [r] advances
27
27
  # Any amounts that have been paid in advance and should be deducted from the amount due.
28
28
  # @return [Advances]
29
- attribute? :advances, Advances.optional
29
+ property :advances, Advances
30
30
 
31
31
  # @!attribute [r] instructions
32
32
  # Details on how payment should be made.
33
33
  # @return [GOBL::Pay::Instructions]
34
- attribute? :instructions, GOBL::Pay::Instructions.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 [Payment] the object created from the given data
41
- def self.from_gobl!(data)
42
- data = GOBL::Types::Hash[data]
43
-
44
- new(
45
- payer: data['payer'] ? GOBL::Org::Party.from_gobl!(data['payer']) : nil,
46
- terms: data['terms'] ? GOBL::Pay::Terms.from_gobl!(data['terms']) : nil,
47
- advances: data['advances'] ? Advances.from_gobl!(data['advances']) : nil,
48
- instructions: data['instructions'] ? GOBL::Pay::Instructions.from_gobl!(data['instructions']) : nil
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
- 'payer' => attributes[:payer]&.to_gobl,
58
- 'terms' => attributes[:terms]&.to_gobl,
59
- 'advances' => attributes[:advances]&.to_gobl,
60
- 'instructions' => attributes[:instructions]&.to_gobl
61
- }.compact
62
- end
63
-
64
- # @!method self.new(attrs)
65
- #
66
- # Returns a {Payment} 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 [Payment] the object corresponding to the given input
34
+ property :instructions, GOBL::Pay::Instructions
77
35
  end
78
36
  end
79
37
  end