gobl 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ext/hashme.rb +28 -0
- data/lib/gobl/bill/advances.rb +1 -77
- data/lib/gobl/bill/charge.rb +11 -65
- data/lib/gobl/bill/delivery.rb +5 -47
- data/lib/gobl/bill/discount.rb +11 -65
- data/lib/gobl/bill/exchange_rates.rb +1 -77
- data/lib/gobl/bill/invoice.rb +28 -104
- data/lib/gobl/bill/invoice_type.rb +3 -134
- data/lib/gobl/bill/line.rb +13 -65
- data/lib/gobl/bill/line_charge.rb +5 -47
- data/lib/gobl/bill/line_discount.rb +5 -47
- data/lib/gobl/bill/ordering.rb +2 -38
- data/lib/gobl/bill/outlay.rb +11 -59
- data/lib/gobl/bill/payment.rb +5 -47
- data/lib/gobl/bill/preceding.rb +12 -62
- data/lib/gobl/bill/scheme_keys.rb +1 -77
- data/lib/gobl/bill/tax.rb +4 -44
- data/lib/gobl/bill/totals.rb +17 -71
- data/lib/gobl/cal/date.rb +1 -90
- data/lib/gobl/cal/period.rb +5 -41
- data/lib/gobl/currency/code.rb +3 -134
- data/lib/gobl/currency/exchange_rate.rb +5 -41
- data/lib/gobl/document.rb +1 -58
- data/lib/gobl/dsig/digest.rb +5 -41
- data/lib/gobl/dsig/signature.rb +1 -90
- data/lib/gobl/enum.rb +81 -0
- data/lib/gobl/envelope.rb +9 -48
- data/lib/gobl/header.rb +10 -56
- data/lib/gobl/i18n/string.rb +1 -58
- data/lib/gobl/l10n/code.rb +1 -90
- data/lib/gobl/l10n/country_code.rb +3 -134
- data/lib/gobl/map.rb +62 -0
- data/lib/gobl/note/message.rb +5 -44
- data/lib/gobl/num/amount.rb +6 -35
- data/lib/gobl/object.rb +21 -0
- data/lib/gobl/operations.rb +3 -3
- data/lib/gobl/org/address.rb +18 -80
- data/lib/gobl/org/code.rb +1 -90
- data/lib/gobl/org/coordinates.rb +5 -47
- data/lib/gobl/org/email.rb +6 -47
- data/lib/gobl/org/inbox.rb +8 -50
- data/lib/gobl/org/item.rb +13 -65
- data/lib/gobl/org/item_code.rb +4 -41
- data/lib/gobl/org/key.rb +1 -90
- data/lib/gobl/org/meta.rb +1 -58
- data/lib/gobl/org/name.rb +12 -62
- data/lib/gobl/org/note.rb +6 -47
- data/lib/gobl/org/note_key.rb +3 -134
- data/lib/gobl/org/party.rb +14 -71
- data/lib/gobl/org/person.rb +9 -56
- data/lib/gobl/org/registration.rb +9 -59
- data/lib/gobl/org/source_key.rb +3 -134
- data/lib/gobl/org/tax_identity.rb +8 -53
- data/lib/gobl/org/telephone.rb +5 -44
- data/lib/gobl/org/unit.rb +1 -136
- data/lib/gobl/pay/advance.rb +11 -59
- data/lib/gobl/pay/card.rb +5 -41
- data/lib/gobl/pay/credit_transfer.rb +6 -50
- data/lib/gobl/pay/direct_debit.rb +4 -44
- data/lib/gobl/pay/due_date.rb +8 -50
- data/lib/gobl/pay/instructions.rb +11 -62
- data/lib/gobl/pay/method_key.rb +3 -134
- data/lib/gobl/pay/online.rb +4 -41
- data/lib/gobl/pay/term_key.rb +3 -134
- data/lib/gobl/pay/terms.rb +6 -47
- data/lib/gobl/stamp.rb +5 -41
- data/lib/gobl/struct.rb +15 -15
- data/lib/gobl/tax/category.rb +9 -50
- data/lib/gobl/tax/category_total.rb +11 -53
- data/lib/gobl/tax/combo.rb +6 -47
- data/lib/gobl/tax/localities.rb +1 -77
- data/lib/gobl/tax/locality.rb +6 -44
- data/lib/gobl/tax/rate.rb +8 -47
- data/lib/gobl/tax/rate_total.rb +9 -50
- data/lib/gobl/tax/rate_total_surcharge.rb +5 -41
- data/lib/gobl/tax/rate_value.rb +6 -47
- data/lib/gobl/tax/region.rb +12 -56
- data/lib/gobl/tax/scheme.rb +8 -50
- data/lib/gobl/tax/schemes.rb +1 -77
- data/lib/gobl/tax/set.rb +1 -77
- data/lib/gobl/tax/total.rb +4 -41
- data/lib/gobl/uuid/uuid.rb +1 -90
- data/lib/gobl/value.rb +58 -0
- data/lib/gobl/version.rb +1 -1
- data/lib/gobl.rb +3 -1
- data/lib/gobl_extensions/document_helper.rb +3 -3
- data/lib/gobl_extensions/envelope_helper.rb +5 -0
- data/lib/gobl_extensions/i18n/value_keys_helper.rb +3 -3
- data/lib/gobl_extensions/tax/region_helper.rb +3 -9
- metadata +11 -36
- data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +0 -30
- data/lib/gobl/types.rb +0 -17
@@ -9,79 +9,37 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# CategoryTotal groups together all rates inside a given category.
|
12
|
-
class CategoryTotal < GOBL::
|
12
|
+
class CategoryTotal < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL CategoryTotal structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/tax/total#/$defs/CategoryTotal'
|
15
15
|
|
16
16
|
# @!attribute [r] code
|
17
17
|
# @return [GOBL::Org::Code]
|
18
|
-
|
18
|
+
property :code, GOBL::Org::Code
|
19
|
+
validates :code, presence: true
|
19
20
|
|
20
21
|
# @!attribute [r] retained
|
21
22
|
# @return [Boolean]
|
22
|
-
|
23
|
+
property :retained, Boolean
|
23
24
|
|
24
25
|
# @!attribute [r] rates
|
25
26
|
# @return [Array<RateTotal>]
|
26
|
-
|
27
|
+
property :rates, [RateTotal]
|
28
|
+
validates :rates, presence: true
|
27
29
|
|
28
30
|
# @!attribute [r] base
|
29
31
|
# @return [GOBL::Num::Amount]
|
30
|
-
|
32
|
+
property :base, GOBL::Num::Amount
|
33
|
+
validates :base, presence: true
|
31
34
|
|
32
35
|
# @!attribute [r] amount
|
33
36
|
# @return [GOBL::Num::Amount]
|
34
|
-
|
37
|
+
property :amount, GOBL::Num::Amount
|
38
|
+
validates :amount, presence: true
|
35
39
|
|
36
40
|
# @!attribute [r] surcharge
|
37
41
|
# @return [GOBL::Num::Amount]
|
38
|
-
|
39
|
-
|
40
|
-
# Creates a new object from a hash of GOBL data
|
41
|
-
#
|
42
|
-
# @param data [Hash] a hash of GOBL data
|
43
|
-
#
|
44
|
-
# @return [CategoryTotal] the object created from the given data
|
45
|
-
def self.from_gobl!(data)
|
46
|
-
data = GOBL::Types::Hash[data]
|
47
|
-
|
48
|
-
new(
|
49
|
-
code: GOBL::Org::Code.from_gobl!(data['code']),
|
50
|
-
retained: data['retained'],
|
51
|
-
rates: data['rates']&.map { |item| RateTotal.from_gobl!(item) },
|
52
|
-
base: data['base'],
|
53
|
-
amount: data['amount'],
|
54
|
-
surcharge: data['surcharge'] || nil
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns a hash of GOBL data representing the current object
|
59
|
-
#
|
60
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
61
|
-
def to_gobl
|
62
|
-
{
|
63
|
-
'code' => attributes[:code]&.to_gobl,
|
64
|
-
'retained' => attributes[:retained],
|
65
|
-
'rates' => attributes[:rates]&.map { |item| item&.to_gobl },
|
66
|
-
'base' => attributes[:base]&.to_gobl,
|
67
|
-
'amount' => attributes[:amount]&.to_gobl,
|
68
|
-
'surcharge' => attributes[:surcharge]&.to_gobl
|
69
|
-
}.compact
|
70
|
-
end
|
71
|
-
|
72
|
-
# @!method self.new(attrs)
|
73
|
-
#
|
74
|
-
# Returns a {CategoryTotal} object from a given hash of attributes. Nested
|
75
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
76
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
77
|
-
# parameter.
|
78
|
-
#
|
79
|
-
# The `new` method will only allow to create a new object if all attributes
|
80
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
81
|
-
#
|
82
|
-
# @param attrs [Hash] the hash of attributes
|
83
|
-
#
|
84
|
-
# @return [CategoryTotal] the object corresponding to the given input
|
42
|
+
property :surcharge, GOBL::Num::Amount
|
85
43
|
end
|
86
44
|
end
|
87
45
|
end
|
data/lib/gobl/tax/combo.rb
CHANGED
@@ -9,71 +9,30 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# Combo represents the tax combination of a category code and rate key.
|
12
|
-
class Combo < GOBL::
|
12
|
+
class Combo < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Combo structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/tax/set#/$defs/Combo'
|
15
15
|
|
16
16
|
# @!attribute [r] cat
|
17
17
|
# Tax category code from those available inside a region.
|
18
18
|
# @return [GOBL::Org::Code]
|
19
|
-
|
19
|
+
property :cat, GOBL::Org::Code
|
20
|
+
validates :cat, presence: true
|
20
21
|
|
21
22
|
# @!attribute [r] rate
|
22
23
|
# Rate within a category to apply.
|
23
24
|
# @return [GOBL::Org::Key]
|
24
|
-
|
25
|
+
property :rate, GOBL::Org::Key
|
25
26
|
|
26
27
|
# @!attribute [r] percent
|
27
28
|
# Percent defines the percentage set manually or determined from the rate key (calculated if rate present).
|
28
29
|
# @return [GOBL::Num::Percentage]
|
29
|
-
|
30
|
+
property :percent, GOBL::Num::Percentage
|
30
31
|
|
31
32
|
# @!attribute [r] surcharge
|
32
33
|
# Some countries require an additional surcharge (calculated if rate present).
|
33
34
|
# @return [GOBL::Num::Percentage]
|
34
|
-
|
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 [Combo] the object created from the given data
|
41
|
-
def self.from_gobl!(data)
|
42
|
-
data = GOBL::Types::Hash[data]
|
43
|
-
|
44
|
-
new(
|
45
|
-
cat: GOBL::Org::Code.from_gobl!(data['cat']),
|
46
|
-
rate: data['rate'] ? GOBL::Org::Key.from_gobl!(data['rate']) : nil,
|
47
|
-
percent: data['percent'] || nil,
|
48
|
-
surcharge: data['surcharge'] || 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
|
-
'cat' => attributes[:cat]&.to_gobl,
|
58
|
-
'rate' => attributes[:rate]&.to_gobl,
|
59
|
-
'percent' => attributes[:percent]&.to_gobl,
|
60
|
-
'surcharge' => attributes[:surcharge]&.to_gobl
|
61
|
-
}.compact
|
62
|
-
end
|
63
|
-
|
64
|
-
# @!method self.new(attrs)
|
65
|
-
#
|
66
|
-
# Returns a {Combo} 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 [Combo] the object corresponding to the given input
|
35
|
+
property :surcharge, GOBL::Num::Percentage
|
77
36
|
end
|
78
37
|
end
|
79
38
|
end
|
data/lib/gobl/tax/localities.rb
CHANGED
@@ -9,82 +9,6 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# Localities stores an array of locality objects used to describe areas sub-divisions inside a region.
|
12
|
-
|
13
|
-
extend Forwardable
|
14
|
-
include Enumerable
|
15
|
-
|
16
|
-
# The Schema ID of the GOBL Localities structure
|
17
|
-
SCHEMA_ID = 'https://gobl.org/draft-0/tax/region#/$defs/Localities'
|
18
|
-
|
19
|
-
attribute :_ary, GOBL::Types::Array.of(Locality)
|
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 [Locality] 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<Locality>] 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<Locality>] 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 [Localities] the object created from the given data
|
61
|
-
def self.from_gobl!(data)
|
62
|
-
new(_ary: data&.map { |item| Locality.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 {Localities} object from a given array of structs. The array may
|
73
|
-
# contain {Locality} objects or hashes. If hashes are provided, the constructor
|
74
|
-
# will call `Locality#new` to generate the objects that will be part of the
|
75
|
-
# returned {Localities} object
|
76
|
-
#
|
77
|
-
# @param object [Array<Locality, Hash>] the array containing the structs
|
78
|
-
#
|
79
|
-
# @return [Localities] 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
|
+
Localities = [Locality] # rubocop:disable Naming/ConstantName, Style/MutableConstant
|
89
13
|
end
|
90
14
|
end
|
data/lib/gobl/tax/locality.rb
CHANGED
@@ -9,64 +9,26 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# Locality represents an area inside a region, like a province or a state, which shares the basic definitions of the region, but may vary in some validation rules.
|
12
|
-
class Locality < GOBL::
|
12
|
+
class Locality < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Locality structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/tax/region#/$defs/Locality'
|
15
15
|
|
16
16
|
# @!attribute [r] code
|
17
17
|
# Code
|
18
18
|
# @return [GOBL::L10n::Code]
|
19
|
-
|
19
|
+
property :code, GOBL::L10n::Code
|
20
|
+
validates :code, presence: true
|
20
21
|
|
21
22
|
# @!attribute [r] name
|
22
23
|
# Name of the locality with local and hopefully international translations.
|
23
24
|
# @return [GOBL::I18n::String]
|
24
|
-
|
25
|
+
property :name, GOBL::I18n::String
|
26
|
+
validates :name, presence: true
|
25
27
|
|
26
28
|
# @!attribute [r] meta
|
27
29
|
# Any additional information
|
28
30
|
# @return [GOBL::Org::Meta]
|
29
|
-
|
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 [Locality] the object created from the given data
|
36
|
-
def self.from_gobl!(data)
|
37
|
-
data = GOBL::Types::Hash[data]
|
38
|
-
|
39
|
-
new(
|
40
|
-
code: GOBL::L10n::Code.from_gobl!(data['code']),
|
41
|
-
name: GOBL::I18n::String.from_gobl!(data['name']),
|
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
|
-
'code' => attributes[:code]&.to_gobl,
|
52
|
-
'name' => attributes[:name]&.to_gobl,
|
53
|
-
'meta' => attributes[:meta]&.to_gobl
|
54
|
-
}.compact
|
55
|
-
end
|
56
|
-
|
57
|
-
# @!method self.new(attrs)
|
58
|
-
#
|
59
|
-
# Returns a {Locality} 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 [Locality] the object corresponding to the given input
|
31
|
+
property :meta, GOBL::Org::Meta
|
70
32
|
end
|
71
33
|
end
|
72
34
|
end
|
data/lib/gobl/tax/rate.rb
CHANGED
@@ -9,69 +9,30 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# Rate defines a single rate inside a category
|
12
|
-
class Rate < GOBL::
|
12
|
+
class Rate < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Rate structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/tax/region#/$defs/Rate'
|
15
15
|
|
16
16
|
# @!attribute [r] key
|
17
17
|
# Key identifies this rate within the system
|
18
18
|
# @return [GOBL::Org::Key]
|
19
|
-
|
19
|
+
property :key, GOBL::Org::Key
|
20
|
+
validates :key, presence: true
|
20
21
|
|
21
22
|
# @!attribute [r] name
|
22
23
|
# @return [GOBL::I18n::String]
|
23
|
-
|
24
|
+
property :name, GOBL::I18n::String
|
25
|
+
validates :name, presence: true
|
24
26
|
|
25
27
|
# @!attribute [r] desc
|
26
28
|
# @return [GOBL::I18n::String]
|
27
|
-
|
29
|
+
property :desc, GOBL::I18n::String
|
28
30
|
|
29
31
|
# @!attribute [r] values
|
30
32
|
# Values contains a list of Value objects that contain the current and historical percentage values for the rate; order is important, newer values should come before older values.
|
31
33
|
# @return [Array<RateValue>]
|
32
|
-
|
33
|
-
|
34
|
-
# Creates a new object from a hash of GOBL data
|
35
|
-
#
|
36
|
-
# @param data [Hash] a hash of GOBL data
|
37
|
-
#
|
38
|
-
# @return [Rate] the object created from the given data
|
39
|
-
def self.from_gobl!(data)
|
40
|
-
data = GOBL::Types::Hash[data]
|
41
|
-
|
42
|
-
new(
|
43
|
-
key: GOBL::Org::Key.from_gobl!(data['key']),
|
44
|
-
name: GOBL::I18n::String.from_gobl!(data['name']),
|
45
|
-
desc: data['desc'] ? GOBL::I18n::String.from_gobl!(data['desc']) : nil,
|
46
|
-
values: data['values']&.map { |item| RateValue.from_gobl!(item) }
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Returns a hash of GOBL data representing the current object
|
51
|
-
#
|
52
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
53
|
-
def to_gobl
|
54
|
-
{
|
55
|
-
'key' => attributes[:key]&.to_gobl,
|
56
|
-
'name' => attributes[:name]&.to_gobl,
|
57
|
-
'desc' => attributes[:desc]&.to_gobl,
|
58
|
-
'values' => attributes[:values]&.map { |item| item&.to_gobl }
|
59
|
-
}.compact
|
60
|
-
end
|
61
|
-
|
62
|
-
# @!method self.new(attrs)
|
63
|
-
#
|
64
|
-
# Returns a {Rate} object from a given hash of attributes. Nested
|
65
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
66
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
67
|
-
# parameter.
|
68
|
-
#
|
69
|
-
# The `new` method will only allow to create a new object if all attributes
|
70
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
71
|
-
#
|
72
|
-
# @param attrs [Hash] the hash of attributes
|
73
|
-
#
|
74
|
-
# @return [Rate] the object corresponding to the given input
|
34
|
+
property :values, [RateValue]
|
35
|
+
validates :values, presence: true
|
75
36
|
end
|
76
37
|
end
|
77
38
|
end
|
data/lib/gobl/tax/rate_total.rb
CHANGED
@@ -9,74 +9,33 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# RateTotal contains a sum of all the tax rates in the document with a matching category and rate.
|
12
|
-
class RateTotal < GOBL::
|
12
|
+
class RateTotal < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL RateTotal structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/tax/total#/$defs/RateTotal'
|
15
15
|
|
16
16
|
# @!attribute [r] key
|
17
17
|
# @return [GOBL::Org::Key]
|
18
|
-
|
18
|
+
property :key, GOBL::Org::Key
|
19
19
|
|
20
20
|
# @!attribute [r] base
|
21
21
|
# @return [GOBL::Num::Amount]
|
22
|
-
|
22
|
+
property :base, GOBL::Num::Amount
|
23
|
+
validates :base, presence: true
|
23
24
|
|
24
25
|
# @!attribute [r] percent
|
25
26
|
# @return [GOBL::Num::Percentage]
|
26
|
-
|
27
|
+
property :percent, GOBL::Num::Percentage
|
28
|
+
validates :percent, presence: true
|
27
29
|
|
28
30
|
# @!attribute [r] amount
|
29
31
|
# Total amount of rate, excluding surcharges
|
30
32
|
# @return [GOBL::Num::Amount]
|
31
|
-
|
33
|
+
property :amount, GOBL::Num::Amount
|
34
|
+
validates :amount, presence: true
|
32
35
|
|
33
36
|
# @!attribute [r] surcharge
|
34
37
|
# @return [RateTotalSurcharge]
|
35
|
-
|
36
|
-
|
37
|
-
# Creates a new object from a hash of GOBL data
|
38
|
-
#
|
39
|
-
# @param data [Hash] a hash of GOBL data
|
40
|
-
#
|
41
|
-
# @return [RateTotal] the object created from the given data
|
42
|
-
def self.from_gobl!(data)
|
43
|
-
data = GOBL::Types::Hash[data]
|
44
|
-
|
45
|
-
new(
|
46
|
-
key: data['key'] ? GOBL::Org::Key.from_gobl!(data['key']) : nil,
|
47
|
-
base: data['base'],
|
48
|
-
percent: data['percent'],
|
49
|
-
amount: data['amount'],
|
50
|
-
surcharge: data['surcharge'] ? RateTotalSurcharge.from_gobl!(data['surcharge']) : nil
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Returns a hash of GOBL data representing the current object
|
55
|
-
#
|
56
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
57
|
-
def to_gobl
|
58
|
-
{
|
59
|
-
'key' => attributes[:key]&.to_gobl,
|
60
|
-
'base' => attributes[:base]&.to_gobl,
|
61
|
-
'percent' => attributes[:percent]&.to_gobl,
|
62
|
-
'amount' => attributes[:amount]&.to_gobl,
|
63
|
-
'surcharge' => attributes[:surcharge]&.to_gobl
|
64
|
-
}.compact
|
65
|
-
end
|
66
|
-
|
67
|
-
# @!method self.new(attrs)
|
68
|
-
#
|
69
|
-
# Returns a {RateTotal} object from a given hash of attributes. Nested
|
70
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
71
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
72
|
-
# parameter.
|
73
|
-
#
|
74
|
-
# The `new` method will only allow to create a new object if all attributes
|
75
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
76
|
-
#
|
77
|
-
# @param attrs [Hash] the hash of attributes
|
78
|
-
#
|
79
|
-
# @return [RateTotal] the object corresponding to the given input
|
38
|
+
property :surcharge, RateTotalSurcharge
|
80
39
|
end
|
81
40
|
end
|
82
41
|
end
|
@@ -9,55 +9,19 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# RateTotalSurcharge reflects the sum surcharges inside the rate.
|
12
|
-
class RateTotalSurcharge < GOBL::
|
12
|
+
class RateTotalSurcharge < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL RateTotalSurcharge structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/tax/total#/$defs/RateTotalSurcharge'
|
15
15
|
|
16
16
|
# @!attribute [r] percent
|
17
17
|
# @return [GOBL::Num::Percentage]
|
18
|
-
|
18
|
+
property :percent, GOBL::Num::Percentage
|
19
|
+
validates :percent, presence: true
|
19
20
|
|
20
21
|
# @!attribute [r] amount
|
21
22
|
# @return [GOBL::Num::Amount]
|
22
|
-
|
23
|
-
|
24
|
-
# Creates a new object from a hash of GOBL data
|
25
|
-
#
|
26
|
-
# @param data [Hash] a hash of GOBL data
|
27
|
-
#
|
28
|
-
# @return [RateTotalSurcharge] the object created from the given data
|
29
|
-
def self.from_gobl!(data)
|
30
|
-
data = GOBL::Types::Hash[data]
|
31
|
-
|
32
|
-
new(
|
33
|
-
percent: data['percent'],
|
34
|
-
amount: data['amount']
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Returns a hash of GOBL data representing the current object
|
39
|
-
#
|
40
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
41
|
-
def to_gobl
|
42
|
-
{
|
43
|
-
'percent' => attributes[:percent]&.to_gobl,
|
44
|
-
'amount' => attributes[:amount]&.to_gobl
|
45
|
-
}.compact
|
46
|
-
end
|
47
|
-
|
48
|
-
# @!method self.new(attrs)
|
49
|
-
#
|
50
|
-
# Returns a {RateTotalSurcharge} object from a given hash of attributes. Nested
|
51
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
52
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
53
|
-
# parameter.
|
54
|
-
#
|
55
|
-
# The `new` method will only allow to create a new object if all attributes
|
56
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
57
|
-
#
|
58
|
-
# @param attrs [Hash] the hash of attributes
|
59
|
-
#
|
60
|
-
# @return [RateTotalSurcharge] the object corresponding to the given input
|
23
|
+
property :amount, GOBL::Num::Amount
|
24
|
+
validates :amount, presence: true
|
61
25
|
end
|
62
26
|
end
|
63
27
|
end
|
data/lib/gobl/tax/rate_value.rb
CHANGED
@@ -9,71 +9,30 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Tax
|
11
11
|
# RateValue contains a percentage rate or fixed amount for a given date range.
|
12
|
-
class RateValue < GOBL::
|
12
|
+
class RateValue < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL RateValue structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/tax/region#/$defs/RateValue'
|
15
15
|
|
16
16
|
# @!attribute [r] since
|
17
17
|
# Date from which this value should be applied.
|
18
18
|
# @return [GOBL::Cal::Date]
|
19
|
-
|
19
|
+
property :since, GOBL::Cal::Date
|
20
20
|
|
21
21
|
# @!attribute [r] percent
|
22
22
|
# Percent rate that should be applied
|
23
23
|
# @return [GOBL::Num::Percentage]
|
24
|
-
|
24
|
+
property :percent, GOBL::Num::Percentage
|
25
|
+
validates :percent, presence: true
|
25
26
|
|
26
27
|
# @!attribute [r] surcharge
|
27
28
|
# An additional surcharge to apply.
|
28
29
|
# @return [GOBL::Num::Percentage]
|
29
|
-
|
30
|
+
property :surcharge, GOBL::Num::Percentage
|
30
31
|
|
31
32
|
# @!attribute [r] disabled
|
32
33
|
# When true, this value should no longer be used.
|
33
34
|
# @return [Boolean]
|
34
|
-
|
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 [RateValue] the object created from the given data
|
41
|
-
def self.from_gobl!(data)
|
42
|
-
data = GOBL::Types::Hash[data]
|
43
|
-
|
44
|
-
new(
|
45
|
-
since: data['since'] ? GOBL::Cal::Date.from_gobl!(data['since']) : nil,
|
46
|
-
percent: data['percent'],
|
47
|
-
surcharge: data['surcharge'] || nil,
|
48
|
-
disabled: data['disabled']
|
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
|
-
'since' => attributes[:since]&.to_gobl,
|
58
|
-
'percent' => attributes[:percent]&.to_gobl,
|
59
|
-
'surcharge' => attributes[:surcharge]&.to_gobl,
|
60
|
-
'disabled' => attributes[:disabled]
|
61
|
-
}.compact
|
62
|
-
end
|
63
|
-
|
64
|
-
# @!method self.new(attrs)
|
65
|
-
#
|
66
|
-
# Returns a {RateValue} 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 [RateValue] the object corresponding to the given input
|
35
|
+
property :disabled, Boolean
|
77
36
|
end
|
78
37
|
end
|
79
38
|
end
|