gobl 0.1.2 → 0.2.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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ext/hashme.rb +28 -0
  3. data/lib/gobl/bill/advances.rb +1 -77
  4. data/lib/gobl/bill/charge.rb +11 -65
  5. data/lib/gobl/bill/delivery.rb +5 -47
  6. data/lib/gobl/bill/discount.rb +11 -65
  7. data/lib/gobl/bill/exchange_rates.rb +1 -77
  8. data/lib/gobl/bill/invoice.rb +28 -104
  9. data/lib/gobl/bill/invoice_type.rb +3 -134
  10. data/lib/gobl/bill/line.rb +13 -65
  11. data/lib/gobl/bill/line_charge.rb +5 -47
  12. data/lib/gobl/bill/line_discount.rb +5 -47
  13. data/lib/gobl/bill/ordering.rb +2 -38
  14. data/lib/gobl/bill/outlay.rb +11 -59
  15. data/lib/gobl/bill/payment.rb +5 -47
  16. data/lib/gobl/bill/preceding.rb +12 -62
  17. data/lib/gobl/bill/scheme_keys.rb +1 -77
  18. data/lib/gobl/bill/tax.rb +4 -44
  19. data/lib/gobl/bill/totals.rb +17 -71
  20. data/lib/gobl/cal/date.rb +1 -90
  21. data/lib/gobl/cal/period.rb +5 -41
  22. data/lib/gobl/currency/code.rb +3 -134
  23. data/lib/gobl/currency/exchange_rate.rb +5 -41
  24. data/lib/gobl/document.rb +1 -58
  25. data/lib/gobl/dsig/digest.rb +5 -41
  26. data/lib/gobl/dsig/signature.rb +1 -90
  27. data/lib/gobl/enum.rb +81 -0
  28. data/lib/gobl/envelope.rb +9 -48
  29. data/lib/gobl/header.rb +10 -56
  30. data/lib/gobl/i18n/string.rb +1 -58
  31. data/lib/gobl/l10n/code.rb +1 -90
  32. data/lib/gobl/l10n/country_code.rb +3 -134
  33. data/lib/gobl/map.rb +62 -0
  34. data/lib/gobl/note/message.rb +5 -44
  35. data/lib/gobl/num/amount.rb +6 -35
  36. data/lib/gobl/object.rb +21 -0
  37. data/lib/gobl/operations.rb +3 -3
  38. data/lib/gobl/org/address.rb +18 -80
  39. data/lib/gobl/org/code.rb +1 -90
  40. data/lib/gobl/org/coordinates.rb +5 -47
  41. data/lib/gobl/org/email.rb +6 -47
  42. data/lib/gobl/org/inbox.rb +8 -50
  43. data/lib/gobl/org/item.rb +13 -65
  44. data/lib/gobl/org/item_code.rb +4 -41
  45. data/lib/gobl/org/key.rb +1 -90
  46. data/lib/gobl/org/meta.rb +1 -58
  47. data/lib/gobl/org/name.rb +12 -62
  48. data/lib/gobl/org/note.rb +6 -47
  49. data/lib/gobl/org/note_key.rb +3 -134
  50. data/lib/gobl/org/party.rb +14 -71
  51. data/lib/gobl/org/person.rb +9 -56
  52. data/lib/gobl/org/registration.rb +9 -59
  53. data/lib/gobl/org/source_key.rb +3 -134
  54. data/lib/gobl/org/tax_identity.rb +8 -53
  55. data/lib/gobl/org/telephone.rb +5 -44
  56. data/lib/gobl/org/unit.rb +1 -136
  57. data/lib/gobl/pay/advance.rb +11 -59
  58. data/lib/gobl/pay/card.rb +5 -41
  59. data/lib/gobl/pay/credit_transfer.rb +6 -50
  60. data/lib/gobl/pay/direct_debit.rb +4 -44
  61. data/lib/gobl/pay/due_date.rb +8 -50
  62. data/lib/gobl/pay/instructions.rb +11 -62
  63. data/lib/gobl/pay/method_key.rb +3 -134
  64. data/lib/gobl/pay/online.rb +4 -41
  65. data/lib/gobl/pay/term_key.rb +3 -134
  66. data/lib/gobl/pay/terms.rb +6 -47
  67. data/lib/gobl/stamp.rb +5 -41
  68. data/lib/gobl/struct.rb +15 -15
  69. data/lib/gobl/tax/category.rb +9 -50
  70. data/lib/gobl/tax/category_total.rb +11 -53
  71. data/lib/gobl/tax/combo.rb +6 -47
  72. data/lib/gobl/tax/localities.rb +1 -77
  73. data/lib/gobl/tax/locality.rb +6 -44
  74. data/lib/gobl/tax/rate.rb +8 -47
  75. data/lib/gobl/tax/rate_total.rb +9 -50
  76. data/lib/gobl/tax/rate_total_surcharge.rb +5 -41
  77. data/lib/gobl/tax/rate_value.rb +6 -47
  78. data/lib/gobl/tax/region.rb +12 -56
  79. data/lib/gobl/tax/scheme.rb +8 -50
  80. data/lib/gobl/tax/schemes.rb +1 -77
  81. data/lib/gobl/tax/set.rb +1 -77
  82. data/lib/gobl/tax/total.rb +4 -41
  83. data/lib/gobl/uuid/uuid.rb +1 -90
  84. data/lib/gobl/value.rb +58 -0
  85. data/lib/gobl/version.rb +1 -1
  86. data/lib/gobl.rb +3 -1
  87. data/lib/gobl_extensions/document_helper.rb +3 -3
  88. data/lib/gobl_extensions/envelope_helper.rb +5 -0
  89. data/lib/gobl_extensions/i18n/value_keys_helper.rb +3 -3
  90. data/lib/gobl_extensions/tax/region_helper.rb +3 -9
  91. metadata +11 -36
  92. data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +0 -30
  93. data/lib/gobl/types.rb +0 -17
@@ -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
@@ -9,106 +9,56 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Preceding allows for information to be provided about a previous invoice that this one will replace or subtract from.
12
- class Preceding < GOBL::Struct
12
+ class Preceding < GOBL::Object
13
13
  # The Schema ID of the GOBL Preceding structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Preceding'
15
15
 
16
16
  # @!attribute [r] uuid
17
17
  # Preceding document's UUID if available can be useful for tracing.
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] code
22
22
  # Identity code of the previous invoice.
23
23
  # @return [String]
24
- attribute :code, GOBL::Types::String
24
+ property :code, String
25
+ validates :code, presence: true
25
26
 
26
27
  # @!attribute [r] series
27
28
  # Additional identification details
28
29
  # @return [String]
29
- attribute? :series, GOBL::Types::String.optional
30
+ property :series, String
30
31
 
31
32
  # @!attribute [r] issue_date
32
33
  # When the preceding invoice was issued.
33
34
  # @return [GOBL::Cal::Date]
34
- attribute :issue_date, GOBL::Cal::Date
35
+ property :issue_date, GOBL::Cal::Date
36
+ validates :issue_date, presence: true
35
37
 
36
38
  # @!attribute [r] period
37
39
  # Tax period in which the previous invoice has an effect.
38
40
  # @return [GOBL::Cal::Period]
39
- attribute? :period, GOBL::Cal::Period.optional
41
+ property :period, GOBL::Cal::Period
40
42
 
41
43
  # @!attribute [r] corrections
42
44
  # Specific codes for the corrections made.
43
45
  # @return [Array<String>]
44
- attribute? :corrections, GOBL::Types::Array.of(GOBL::Types::String).optional
46
+ property :corrections, [String]
45
47
 
46
48
  # @!attribute [r] correction_method
47
49
  # How has the previous invoice been corrected?
48
50
  # @return [String]
49
- attribute? :correction_method, GOBL::Types::String.optional
51
+ property :correction_method, String
50
52
 
51
53
  # @!attribute [r] notes
52
54
  # Additional details regarding preceding invoice
53
55
  # @return [String]
54
- attribute? :notes, GOBL::Types::String.optional
56
+ property :notes, String
55
57
 
56
58
  # @!attribute [r] meta
57
59
  # Additional semi-structured data that may be useful in specific regions
58
60
  # @return [GOBL::Org::Meta]
59
- attribute? :meta, GOBL::Org::Meta.optional
60
-
61
- # Creates a new object from a hash of GOBL data
62
- #
63
- # @param data [Hash] a hash of GOBL data
64
- #
65
- # @return [Preceding] the object created from the given data
66
- def self.from_gobl!(data)
67
- data = GOBL::Types::Hash[data]
68
-
69
- new(
70
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
71
- code: data['code'],
72
- series: data['series'],
73
- issue_date: GOBL::Cal::Date.from_gobl!(data['issue_date']),
74
- period: data['period'] ? GOBL::Cal::Period.from_gobl!(data['period']) : nil,
75
- corrections: data['corrections']&.map { |item| item },
76
- correction_method: data['correction_method'],
77
- notes: data['notes'],
78
- meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
79
- )
80
- end
81
-
82
- # Returns a hash of GOBL data representing the current object
83
- #
84
- # @return [Hash] the array of GOBL data that represents the current object
85
- def to_gobl
86
- {
87
- 'uuid' => attributes[:uuid]&.to_gobl,
88
- 'code' => attributes[:code],
89
- 'series' => attributes[:series],
90
- 'issue_date' => attributes[:issue_date]&.to_gobl,
91
- 'period' => attributes[:period]&.to_gobl,
92
- 'corrections' => attributes[:corrections]&.map { |item| item },
93
- 'correction_method' => attributes[:correction_method],
94
- 'notes' => attributes[:notes],
95
- 'meta' => attributes[:meta]&.to_gobl
96
- }.compact
97
- end
98
-
99
- # @!method self.new(attrs)
100
- #
101
- # Returns a {Preceding} object from a given hash of attributes. Nested
102
- # attributes are supported: the constructor will instantiate the proper GOBL
103
- # objects when nested hashes or arrays are given as part of the `attrs`
104
- # parameter.
105
- #
106
- # The `new` method will only allow to create a new object if all attributes
107
- # marked as mandatory and not calculated in the JSON schema are provided.
108
- #
109
- # @param attrs [Hash] the hash of attributes
110
- #
111
- # @return [Preceding] the object corresponding to the given input
61
+ property :meta, GOBL::Org::Meta
112
62
  end
113
63
  end
114
64
  end
@@ -9,82 +9,6 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # SchemeKeys stores a list of keys that makes it easier to perform matches.
12
- class SchemeKeys < GOBL::Struct
13
- extend Forwardable
14
- include Enumerable
15
-
16
- # The Schema ID of the GOBL SchemeKeys structure
17
- SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/SchemeKeys'
18
-
19
- attribute :_ary, GOBL::Types::Array.of(GOBL::Org::Key)
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::Org::Key] 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::Org::Key>] 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::Org::Key>] 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 [SchemeKeys] the object created from the given data
61
- def self.from_gobl!(data)
62
- new(_ary: data&.map { |item| GOBL::Org::Key.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 {SchemeKeys} object from a given array of structs. The array may
73
- # contain {GOBL::Org::Key} objects or hashes. If hashes are provided, the constructor
74
- # will call `GOBL::Org::Key#new` to generate the objects that will be part of the
75
- # returned {SchemeKeys} object
76
- #
77
- # @param object [Array<GOBL::Org::Key, Hash>] the array containing the structs
78
- #
79
- # @return [SchemeKeys] 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
12
+ SchemeKeys = [GOBL::Org::Key] # rubocop:disable Naming/ConstantName, Style/MutableConstant
89
13
  end
90
14
  end
data/lib/gobl/bill/tax.rb CHANGED
@@ -9,64 +9,24 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Tax defines a summary of the taxes which may be applied to an invoice.
12
- class Tax < GOBL::Struct
12
+ class Tax < GOBL::Object
13
13
  # The Schema ID of the GOBL Tax structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Tax'
15
15
 
16
16
  # @!attribute [r] prices_include
17
17
  # Category of the tax already included in the line item prices, especially useful for B2C retailers with customers who prefer final prices inclusive of tax.
18
18
  # @return [GOBL::Org::Code]
19
- attribute? :prices_include, GOBL::Org::Code.optional
19
+ property :prices_include, GOBL::Org::Code
20
20
 
21
21
  # @!attribute [r] schemes
22
22
  # Special tax schemes that apply to this invoice according to local requirements.
23
23
  # @return [SchemeKeys]
24
- attribute? :schemes, SchemeKeys.optional
24
+ property :schemes, SchemeKeys
25
25
 
26
26
  # @!attribute [r] meta
27
27
  # Any additional data that may be required for processing, but should never be relied upon by recipients.
28
28
  # @return [GOBL::Org::Meta]
29
- attribute? :meta, GOBL::Org::Meta.optional
30
-
31
- # Creates a new object from a hash of GOBL data
32
- #
33
- # @param data [Hash] a hash of GOBL data
34
- #
35
- # @return [Tax] the object created from the given data
36
- def self.from_gobl!(data)
37
- data = GOBL::Types::Hash[data]
38
-
39
- new(
40
- prices_include: data['prices_include'] ? GOBL::Org::Code.from_gobl!(data['prices_include']) : nil,
41
- schemes: data['schemes'] ? SchemeKeys.from_gobl!(data['schemes']) : nil,
42
- meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
43
- )
44
- end
45
-
46
- # Returns a hash of GOBL data representing the current object
47
- #
48
- # @return [Hash] the array of GOBL data that represents the current object
49
- def to_gobl
50
- {
51
- 'prices_include' => attributes[:prices_include]&.to_gobl,
52
- 'schemes' => attributes[:schemes]&.to_gobl,
53
- 'meta' => attributes[:meta]&.to_gobl
54
- }.compact
55
- end
56
-
57
- # @!method self.new(attrs)
58
- #
59
- # Returns a {Tax} object from a given hash of attributes. Nested
60
- # attributes are supported: the constructor will instantiate the proper GOBL
61
- # objects when nested hashes or arrays are given as part of the `attrs`
62
- # parameter.
63
- #
64
- # The `new` method will only allow to create a new object if all attributes
65
- # marked as mandatory and not calculated in the JSON schema are provided.
66
- #
67
- # @param attrs [Hash] the hash of attributes
68
- #
69
- # @return [Tax] the object corresponding to the given input
29
+ property :meta, GOBL::Org::Meta
70
30
  end
71
31
  end
72
32
  end
@@ -9,127 +9,73 @@
9
9
  module GOBL
10
10
  module Bill
11
11
  # Totals contains the summaries of all calculations for the invoice.
12
- class Totals < GOBL::Struct
12
+ class Totals < GOBL::Object
13
13
  # The Schema ID of the GOBL Totals structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Totals'
15
15
 
16
16
  # @!attribute [r] sum
17
17
  # Sum of all line item sums
18
18
  # @return [GOBL::Num::Amount]
19
- attribute :sum, GOBL::Types.Constructor(GOBL::Num::Amount)
19
+ property :sum, GOBL::Num::Amount
20
+ validates :sum, presence: true
20
21
 
21
22
  # @!attribute [r] discount
22
23
  # Sum of all document level discounts
23
24
  # @return [GOBL::Num::Amount]
24
- attribute? :discount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
25
+ property :discount, GOBL::Num::Amount
25
26
 
26
27
  # @!attribute [r] charge
27
28
  # Sum of all document level charges
28
29
  # @return [GOBL::Num::Amount]
29
- attribute? :charge, GOBL::Types.Constructor(GOBL::Num::Amount).optional
30
+ property :charge, GOBL::Num::Amount
30
31
 
31
32
  # @!attribute [r] tax_included
32
33
  # If prices include tax, this is the total tax included in the price.
33
34
  # @return [GOBL::Num::Amount]
34
- attribute? :tax_included, GOBL::Types.Constructor(GOBL::Num::Amount).optional
35
+ property :tax_included, GOBL::Num::Amount
35
36
 
36
37
  # @!attribute [r] total
37
38
  # Sum of all line sums minus the discounts, plus the charges, without tax.
38
39
  # @return [GOBL::Num::Amount]
39
- attribute :total, GOBL::Types.Constructor(GOBL::Num::Amount)
40
+ property :total, GOBL::Num::Amount
41
+ validates :total, presence: true
40
42
 
41
43
  # @!attribute [r] taxes
42
44
  # Summary of all the taxes included in the invoice.
43
45
  # @return [GOBL::Tax::Total]
44
- attribute? :taxes, GOBL::Tax::Total.optional
46
+ property :taxes, GOBL::Tax::Total
45
47
 
46
48
  # @!attribute [r] tax
47
49
  # Total amount of tax to apply to the invoice.
48
50
  # @return [GOBL::Num::Amount]
49
- attribute? :tax, GOBL::Types.Constructor(GOBL::Num::Amount).optional
51
+ property :tax, GOBL::Num::Amount
50
52
 
51
53
  # @!attribute [r] total_with_tax
52
54
  # Grand total after all taxes have been applied.
53
55
  # @return [GOBL::Num::Amount]
54
- attribute :total_with_tax, GOBL::Types.Constructor(GOBL::Num::Amount)
56
+ property :total_with_tax, GOBL::Num::Amount
57
+ validates :total_with_tax, presence: true
55
58
 
56
59
  # @!attribute [r] outlays
57
60
  # Total paid in outlays that need to be reimbursed
58
61
  # @return [GOBL::Num::Amount]
59
- attribute? :outlays, GOBL::Types.Constructor(GOBL::Num::Amount).optional
62
+ property :outlays, GOBL::Num::Amount
60
63
 
61
64
  # @!attribute [r] payable
62
65
  # Total amount to be paid after applying taxes and outlays.
63
66
  # @return [GOBL::Num::Amount]
64
- attribute :payable, GOBL::Types.Constructor(GOBL::Num::Amount)
67
+ property :payable, GOBL::Num::Amount
68
+ validates :payable, presence: true
65
69
 
66
70
  # @!attribute [r] advance
67
71
  # Total amount already paid in advance.
68
72
  # @return [GOBL::Num::Amount]
69
- attribute? :advance, GOBL::Types.Constructor(GOBL::Num::Amount).optional
73
+ property :advance, GOBL::Num::Amount
70
74
 
71
75
  # @!attribute [r] due
72
76
  # How much actually needs to be paid now.
73
77
  # @return [GOBL::Num::Amount]
74
- attribute? :due, GOBL::Types.Constructor(GOBL::Num::Amount).optional
75
-
76
- # Creates a new object from a hash of GOBL data
77
- #
78
- # @param data [Hash] a hash of GOBL data
79
- #
80
- # @return [Totals] the object created from the given data
81
- def self.from_gobl!(data)
82
- data = GOBL::Types::Hash[data]
83
-
84
- new(
85
- sum: data['sum'],
86
- discount: data['discount'] || nil,
87
- charge: data['charge'] || nil,
88
- tax_included: data['tax_included'] || nil,
89
- total: data['total'],
90
- taxes: data['taxes'] ? GOBL::Tax::Total.from_gobl!(data['taxes']) : nil,
91
- tax: data['tax'] || nil,
92
- total_with_tax: data['total_with_tax'],
93
- outlays: data['outlays'] || nil,
94
- payable: data['payable'],
95
- advance: data['advance'] || nil,
96
- due: data['due'] || nil
97
- )
98
- end
99
-
100
- # Returns a hash of GOBL data representing the current object
101
- #
102
- # @return [Hash] the array of GOBL data that represents the current object
103
- def to_gobl
104
- {
105
- 'sum' => attributes[:sum]&.to_gobl,
106
- 'discount' => attributes[:discount]&.to_gobl,
107
- 'charge' => attributes[:charge]&.to_gobl,
108
- 'tax_included' => attributes[:tax_included]&.to_gobl,
109
- 'total' => attributes[:total]&.to_gobl,
110
- 'taxes' => attributes[:taxes]&.to_gobl,
111
- 'tax' => attributes[:tax]&.to_gobl,
112
- 'total_with_tax' => attributes[:total_with_tax]&.to_gobl,
113
- 'outlays' => attributes[:outlays]&.to_gobl,
114
- 'payable' => attributes[:payable]&.to_gobl,
115
- 'advance' => attributes[:advance]&.to_gobl,
116
- 'due' => attributes[:due]&.to_gobl
117
- }.compact
118
- end
119
-
120
- # @!method self.new(attrs)
121
- #
122
- # Returns a {Totals} object from a given hash of attributes. Nested
123
- # attributes are supported: the constructor will instantiate the proper GOBL
124
- # objects when nested hashes or arrays are given as part of the `attrs`
125
- # parameter.
126
- #
127
- # The `new` method will only allow to create a new object if all attributes
128
- # marked as mandatory and not calculated in the JSON schema are provided.
129
- #
130
- # @param attrs [Hash] the hash of attributes
131
- #
132
- # @return [Totals] the object corresponding to the given input
78
+ property :due, GOBL::Num::Amount
133
79
  end
134
80
  end
135
81
  end