gobl 0.1.2

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 (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
data/data/tax/FR.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "https://gobl.org/draft-0/tax/region",
3
+ "name": {
4
+ "en": "France",
5
+ "fr": "La France"
6
+ },
7
+ "country": "FR",
8
+ "currency": "EUR",
9
+ "categories": [
10
+ {
11
+ "code": "VAT",
12
+ "name": {
13
+ "en": "VAT",
14
+ "fr": "TVA"
15
+ },
16
+ "desc": {
17
+ "en": "Value Added Tax",
18
+ "fr": "Taxe sur la Valeur Ajoutée"
19
+ },
20
+ "rates": [
21
+ {
22
+ "key": "zero",
23
+ "name": {
24
+ "en": "Zero Rate"
25
+ },
26
+ "values": [
27
+ {
28
+ "percent": "0.0%"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "key": "standard",
34
+ "name": {
35
+ "en": "Standard Rate"
36
+ },
37
+ "values": [
38
+ {
39
+ "since": "2011-01-04",
40
+ "percent": "20.0%"
41
+ }
42
+ ]
43
+ }
44
+ ]
45
+ }
46
+ ]
47
+ }
data/data/tax/GB.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "$schema": "https://gobl.org/draft-0/tax/region",
3
+ "name": {
4
+ "en": "United Kingdom"
5
+ },
6
+ "country": "GB",
7
+ "currency": "GBP",
8
+ "categories": [
9
+ {
10
+ "code": "VAT",
11
+ "name": {
12
+ "en": "VAT"
13
+ },
14
+ "desc": {
15
+ "en": "Value Added Tax"
16
+ },
17
+ "rates": [
18
+ {
19
+ "key": "zero",
20
+ "name": {
21
+ "en": "Zero Rate"
22
+ },
23
+ "values": [
24
+ {
25
+ "percent": "0.0%"
26
+ }
27
+ ]
28
+ },
29
+ {
30
+ "key": "standard",
31
+ "name": {
32
+ "en": "Standard Rate"
33
+ },
34
+ "values": [
35
+ {
36
+ "since": "2011-01-04",
37
+ "percent": "20.0%"
38
+ }
39
+ ]
40
+ },
41
+ {
42
+ "key": "reduced",
43
+ "name": {
44
+ "en": "Reduced Rate"
45
+ },
46
+ "values": [
47
+ {
48
+ "since": "2011-01-04",
49
+ "percent": "5.0%"
50
+ }
51
+ ]
52
+ }
53
+ ]
54
+ }
55
+ ]
56
+ }
data/data/tax/NL.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "$schema": "https://gobl.org/draft-0/tax/region",
3
+ "name": {
4
+ "en": "The Netherlands",
5
+ "nl": "Nederland"
6
+ },
7
+ "country": "NL",
8
+ "currency": "EUR",
9
+ "categories": [
10
+ {
11
+ "code": "VAT",
12
+ "name": {
13
+ "en": "VAT",
14
+ "nl": "BTW"
15
+ },
16
+ "desc": {
17
+ "en": "Value Added Tax",
18
+ "nl": "Belasting Toegevoegde Waarde"
19
+ },
20
+ "rates": [
21
+ {
22
+ "key": "zero",
23
+ "name": {
24
+ "en": "Zero Rate",
25
+ "nl": "0%-tarief"
26
+ },
27
+ "values": [
28
+ {
29
+ "percent": "0.0%"
30
+ }
31
+ ]
32
+ },
33
+ {
34
+ "key": "standard",
35
+ "name": {
36
+ "en": "Standard Rate",
37
+ "nl": "Standaardtarief"
38
+ },
39
+ "values": [
40
+ {
41
+ "percent": "21.0%"
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "key": "reduced",
47
+ "name": {
48
+ "en": "Reduced Rate",
49
+ "nl": "Gereduceerd Tarief"
50
+ },
51
+ "values": [
52
+ {
53
+ "percent": "9.0%"
54
+ }
55
+ ]
56
+ }
57
+ ]
58
+ }
59
+ ]
60
+ }
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/gobl/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'gobl'
7
+ spec.version = GOBL::VERSION
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.summary = 'Minimalist ruby version of the GOBL library'
10
+ spec.homepage = 'https://github.com/invopop/gobl.ruby'
11
+ spec.license = 'Apache-2.0'
12
+ spec.authors = ['David Lilue', 'Sam Lown', 'Juanjo Molinero']
13
+
14
+ spec.required_ruby_version = '>= 2.7'
15
+ spec.required_rubygems_version = '>= 3.1.4'
16
+
17
+ spec.files = Dir['lib/**/*', 'data/tax/**/*'] + [__FILE__]
18
+ spec.require_path = 'lib'
19
+
20
+ spec.metadata = {
21
+ 'rubygems_mfa_required' => 'true'
22
+ }
23
+
24
+ spec.add_dependency('activesupport', '~> 6.1')
25
+ spec.add_dependency('dry-files', '~> 0.1.0')
26
+ spec.add_dependency('dry-struct', '~> 1.4.0')
27
+ spec.add_dependency('dry-types', '~> 1.5.1')
28
+ spec.add_dependency('json', '~> 2.6.1')
29
+ spec.add_dependency('zeitwerk', '~> 2.5.1')
30
+ end
data/lib/extensions.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Extensions are all defined here so they are auto-loaded by Zeitwerk.
4
+ #
5
+ # Both the instance and class method modules need to be included/extended explicitly here
6
+ # to get YARD parsing them properly.
7
+
8
+ GOBL::I18n::String.include GOBLExtensions::I18n::ValueKeysHelper
9
+ GOBL::Document.include GOBLExtensions::DocumentHelper
10
+ GOBL::Document.extend GOBLExtensions::DocumentHelper::ClassMethods
11
+ GOBL::Envelope.include GOBLExtensions::EnvelopeHelper
12
+ GOBL::Tax::Region.extend GOBLExtensions::Tax::RegionHelper::ClassMethods
@@ -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
+ # Advances contains an array of advance objects.
12
+ class Advances < GOBL::Struct
13
+ extend Forwardable
14
+ include Enumerable
15
+
16
+ # The Schema ID of the GOBL Advances structure
17
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Advances'
18
+
19
+ attribute :_ary, GOBL::Types::Array.of(GOBL::Pay::Advance)
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::Pay::Advance] 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::Pay::Advance>] 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::Pay::Advance>] 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 [Advances] the object created from the given data
61
+ def self.from_gobl!(data)
62
+ new(_ary: data&.map { |item| GOBL::Pay::Advance.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 {Advances} object from a given array of structs. The array may
73
+ # contain {GOBL::Pay::Advance} objects or hashes. If hashes are provided, the constructor
74
+ # will call `GOBL::Pay::Advance#new` to generate the objects that will be part of the
75
+ # returned {Advances} object
76
+ #
77
+ # @param object [Array<GOBL::Pay::Advance, Hash>] the array containing the structs
78
+ #
79
+ # @return [Advances] 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,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
+ # Charge represents a surchange applied to the complete document independent from the individual lines.
12
+ class Charge < GOBL::Struct
13
+ # The Schema ID of the GOBL Charge structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Charge'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique identifying for the discount entry
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] i
22
+ # Line number inside the list of discounts (calculated).
23
+ # @return [Integer]
24
+ attribute? :i, GOBL::Types::Int.optional
25
+
26
+ # @!attribute [r] ref
27
+ # Code to used to refer to the this charge
28
+ # @return [String]
29
+ attribute? :ref, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] base
32
+ # Base represents the value used as a base for percent calculations. If not already provided, we'll take the invoices sum before discounts.
33
+ # @return [GOBL::Num::Amount]
34
+ attribute? :base, GOBL::Types.Constructor(GOBL::Num::Amount).optional
35
+
36
+ # @!attribute [r] percent
37
+ # Percentage to apply to the invoice's Sum
38
+ # @return [GOBL::Num::Percentage]
39
+ attribute? :percent, GOBL::Types.Constructor(GOBL::Num::Percentage).optional
40
+
41
+ # @!attribute [r] amount
42
+ # Amount to apply (calculated if percent present)
43
+ # @return [GOBL::Num::Amount]
44
+ attribute? :amount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
45
+
46
+ # @!attribute [r] taxes
47
+ # List of taxes to apply to the charge
48
+ # @return [GOBL::Tax::Set]
49
+ attribute? :taxes, GOBL::Tax::Set.optional
50
+
51
+ # @!attribute [r] code
52
+ # Code for why was this charge applied?
53
+ # @return [String]
54
+ attribute? :code, GOBL::Types::String.optional
55
+
56
+ # @!attribute [r] reason
57
+ # Text description as to why the charge was applied
58
+ # @return [String]
59
+ attribute? :reason, GOBL::Types::String.optional
60
+
61
+ # @!attribute [r] meta
62
+ # Additional semi-structured information.
63
+ # @return [GOBL::Org::Meta]
64
+ attribute? :meta, GOBL::Org::Meta.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 [Charge] 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
+ ref: data['ref'],
78
+ base: data['base'] || nil,
79
+ percent: data['percent'] || nil,
80
+ amount: data['amount'] || nil,
81
+ taxes: data['taxes'] ? GOBL::Tax::Set.from_gobl!(data['taxes']) : nil,
82
+ code: data['code'],
83
+ reason: data['reason'],
84
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
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
+ 'ref' => attributes[:ref],
96
+ 'base' => attributes[:base]&.to_gobl,
97
+ 'percent' => attributes[:percent]&.to_gobl,
98
+ 'amount' => attributes[:amount]&.to_gobl,
99
+ 'taxes' => attributes[:taxes]&.to_gobl,
100
+ 'code' => attributes[:code],
101
+ 'reason' => attributes[:reason],
102
+ 'meta' => attributes[:meta]&.to_gobl
103
+ }.compact
104
+ end
105
+
106
+ # @!method self.new(attrs)
107
+ #
108
+ # Returns a {Charge} 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 [Charge] 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
+ # Delivery covers the details of the destination for the products described in the invoice body.
12
+ class Delivery < GOBL::Struct
13
+ # The Schema ID of the GOBL Delivery structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Delivery'
15
+
16
+ # @!attribute [r] receiver
17
+ # The party who will receive delivery of the goods defined in the invoice and is not responsible for taxes.
18
+ # @return [GOBL::Org::Party]
19
+ attribute? :receiver, GOBL::Org::Party.optional
20
+
21
+ # @!attribute [r] date
22
+ # When the goods should be expected
23
+ # @return [GOBL::Cal::Date]
24
+ attribute? :date, GOBL::Cal::Date.optional
25
+
26
+ # @!attribute [r] start_date
27
+ # Start of a n invoicing or delivery period
28
+ # @return [GOBL::Cal::Date]
29
+ attribute? :start_date, GOBL::Cal::Date.optional
30
+
31
+ # @!attribute [r] end_date
32
+ # End of a n invoicing or delivery period
33
+ # @return [GOBL::Cal::Date]
34
+ attribute? :end_date, GOBL::Cal::Date.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 [Delivery] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ receiver: data['receiver'] ? GOBL::Org::Party.from_gobl!(data['receiver']) : nil,
46
+ date: data['date'] ? GOBL::Cal::Date.from_gobl!(data['date']) : nil,
47
+ start_date: data['start_date'] ? GOBL::Cal::Date.from_gobl!(data['start_date']) : nil,
48
+ end_date: data['end_date'] ? GOBL::Cal::Date.from_gobl!(data['end_date']) : 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
+ 'receiver' => attributes[:receiver]&.to_gobl,
58
+ 'date' => attributes[:date]&.to_gobl,
59
+ 'start_date' => attributes[:start_date]&.to_gobl,
60
+ 'end_date' => attributes[:end_date]&.to_gobl
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {Delivery} 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 [Delivery] the object corresponding to the given input
77
+ end
78
+ end
79
+ 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
+ # Discount represents an allowance applied to the complete document independent from the individual lines.
12
+ class Discount < GOBL::Struct
13
+ # The Schema ID of the GOBL Discount structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Discount'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique identifying for the discount entry
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] i
22
+ # Line number inside the list of discounts (calculated)
23
+ # @return [Integer]
24
+ attribute? :i, GOBL::Types::Int.optional
25
+
26
+ # @!attribute [r] ref
27
+ # Reference or ID for this Discount
28
+ # @return [String]
29
+ attribute? :ref, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] base
32
+ # Base represents the value used as a base for percent calculations. If not already provided, we'll take the invoices sum.
33
+ # @return [GOBL::Num::Amount]
34
+ attribute? :base, GOBL::Types.Constructor(GOBL::Num::Amount).optional
35
+
36
+ # @!attribute [r] percent
37
+ # Percentage to apply to the invoice's Sum.
38
+ # @return [GOBL::Num::Percentage]
39
+ attribute? :percent, GOBL::Types.Constructor(GOBL::Num::Percentage).optional
40
+
41
+ # @!attribute [r] amount
42
+ # Amount to apply (calculated if percent present).
43
+ # @return [GOBL::Num::Amount]
44
+ attribute? :amount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
45
+
46
+ # @!attribute [r] taxes
47
+ # List of taxes to apply to the discount
48
+ # @return [GOBL::Tax::Set]
49
+ attribute? :taxes, GOBL::Tax::Set.optional
50
+
51
+ # @!attribute [r] code
52
+ # Code for the reason this discount applied
53
+ # @return [String]
54
+ attribute? :code, GOBL::Types::String.optional
55
+
56
+ # @!attribute [r] reason
57
+ # Text description as to why the discount was applied
58
+ # @return [String]
59
+ attribute? :reason, GOBL::Types::String.optional
60
+
61
+ # @!attribute [r] meta
62
+ # Additional semi-structured information.
63
+ # @return [GOBL::Org::Meta]
64
+ attribute? :meta, GOBL::Org::Meta.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 [Discount] 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
+ ref: data['ref'],
78
+ base: data['base'] || nil,
79
+ percent: data['percent'] || nil,
80
+ amount: data['amount'] || nil,
81
+ taxes: data['taxes'] ? GOBL::Tax::Set.from_gobl!(data['taxes']) : nil,
82
+ code: data['code'],
83
+ reason: data['reason'],
84
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
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
+ 'ref' => attributes[:ref],
96
+ 'base' => attributes[:base]&.to_gobl,
97
+ 'percent' => attributes[:percent]&.to_gobl,
98
+ 'amount' => attributes[:amount]&.to_gobl,
99
+ 'taxes' => attributes[:taxes]&.to_gobl,
100
+ 'code' => attributes[:code],
101
+ 'reason' => attributes[:reason],
102
+ 'meta' => attributes[:meta]&.to_gobl
103
+ }.compact
104
+ end
105
+
106
+ # @!method self.new(attrs)
107
+ #
108
+ # Returns a {Discount} 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 [Discount] the object corresponding to the given input
119
+ end
120
+ end
121
+ end