gobl 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfea0d56efe6b8768eeb6bb8f0b24ba06f3cb0a92d20bd1b4a82d26eb8ad9339
4
- data.tar.gz: 134bd9649596f3abda61cfde20ce93792ff934c824daaf88fe49b10799c2d8bf
3
+ metadata.gz: 780ae6767cacd14ffee20e56cf54fe7717b4f4ce76fe298709910fc04c53bb3b
4
+ data.tar.gz: 3af8d8bbb1f70068115f36f6e264e609133e0791b213a4785be9cc2db7a5e046
5
5
  SHA512:
6
- metadata.gz: a7e6c54e26240d2b44af093e5e9582b82c3dc8997e100752997f0b56cb3d132c0d3b5ccfd441306ae97aae8bac91b2545d13f9cee2a5fe36a985599990a3822e
7
- data.tar.gz: 99a36744e2b6485bad7810377eecd01a01694381f29a58e785f68fda4b0d9aa2ddd363448292fdb7b8476c0737b3af349db62098ec66a1f98aadffedfb424721
6
+ metadata.gz: 7b37e007b00340a53df6bb721085f792038bc1168cc794741df707befb793abf6f2f1cc3b9b883505cf40b7ad10b32fcbedd0a818d529e5904b1e91ffd6445a6
7
+ data.tar.gz: 80263b62bce2dd2e1fae02d2af6141facd8264c68da2ee4ee5f2d9bd4371fee959d42d5f436d4ed12d05c91d391186a6b55906f7602f06b84e51aa3e9f29b21a
data/data/regimes/pt.json CHANGED
@@ -128,6 +128,75 @@
128
128
  }
129
129
  ],
130
130
  "currency": "EUR",
131
+ "tags": [
132
+ {
133
+ "key": "invoice-receipt",
134
+ "name": {
135
+ "en": "Invoice-receipt",
136
+ "pt": "Fatura-recibo"
137
+ }
138
+ },
139
+ {
140
+ "key": "simplified",
141
+ "name": {
142
+ "en": "Simplified invoice",
143
+ "pt": "Fatura simplificada"
144
+ }
145
+ }
146
+ ],
147
+ "scenarios": [
148
+ {
149
+ "schema": "bill/invoice",
150
+ "list": [
151
+ {
152
+ "type": [
153
+ "standard"
154
+ ],
155
+ "meta": {
156
+ "at-invoice-type": "FT"
157
+ }
158
+ },
159
+ {
160
+ "type": [
161
+ "standard"
162
+ ],
163
+ "tags": [
164
+ "simplified"
165
+ ],
166
+ "meta": {
167
+ "at-invoice-type": "FS"
168
+ }
169
+ },
170
+ {
171
+ "type": [
172
+ "standard"
173
+ ],
174
+ "tags": [
175
+ "invoice-receipt"
176
+ ],
177
+ "meta": {
178
+ "at-invoice-type": "FR"
179
+ }
180
+ },
181
+ {
182
+ "type": [
183
+ "debit-note"
184
+ ],
185
+ "meta": {
186
+ "at-invoice-type": "ND"
187
+ }
188
+ },
189
+ {
190
+ "type": [
191
+ "credit-note"
192
+ ],
193
+ "meta": {
194
+ "at-invoice-type": "NC"
195
+ }
196
+ }
197
+ ]
198
+ }
199
+ ],
131
200
  "preceding": {
132
201
  "types": [
133
202
  "credit-note"
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBL
4
+ module Extensions
5
+ module Bill
6
+ # Additional methods for the generated {GOBL::Bill::Invoice} class
7
+ module InvoiceHelper
8
+ # Returns the applicable regime based on the supplier’s tax ID
9
+ def regime
10
+ regime_country && GOBL::Tax::Regime.fetch(regime_country)
11
+ end
12
+
13
+ # Returns the invoice’s scenario summary which aggregates the data of
14
+ # the matching regime’s scenarios
15
+ def scenario_summary
16
+ ScenarioSummary.new(matching_scenarios)
17
+ end
18
+
19
+ private
20
+
21
+ def regime_country
22
+ supplier&.tax_id&.country
23
+ end
24
+
25
+ def matching_scenarios
26
+ return [] unless scenario_set
27
+
28
+ scenario_set.list.select do |scenario|
29
+ matches_scenario?(scenario)
30
+ end
31
+ end
32
+
33
+ def matches_scenario?(scenario)
34
+ matches_scenario_tags?(scenario) && matches_scenario_type?(scenario)
35
+ end
36
+
37
+ def matches_scenario_type?(scenario)
38
+ scenario.type.blank? || scenario.type.include?(type)
39
+ end
40
+
41
+ def matches_scenario_tags?(scenario)
42
+ scenario_tags = scenario.tags || []
43
+ tax_tags = tax&.tags || []
44
+
45
+ (scenario_tags - tax_tags).empty?
46
+ end
47
+
48
+ def scenario_set
49
+ regime&.scenarios&.find do |scenario_set|
50
+ self.class::SCHEMA_ID.include?(scenario_set.schema)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBL
4
+ module Extensions
5
+ module Bill
6
+ # Aggregates the data of collection of scenarios
7
+ class ScenarioSummary
8
+ def initialize(scenarios)
9
+ @scenarios = scenarios
10
+ end
11
+
12
+ # Returns the aggregated metadata of the scenarios
13
+ def meta
14
+ scenarios.inject({}) do |meta, scenario|
15
+ meta.merge(scenario.meta.to_h)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :scenarios
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/gobl/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GOBL
4
- VERSION = '0.14.0'
4
+ VERSION = '0.14.1'
5
5
  end
data/lib/gobl.rb CHANGED
@@ -50,3 +50,4 @@ GOBL::Document.include GOBL::Extensions::DocumentHelper
50
50
  GOBL::Document.extend GOBL::Extensions::DocumentHelper::ClassMethods
51
51
  GOBL::Envelope.include GOBL::Extensions::EnvelopeHelper
52
52
  GOBL::Tax::Regime.extend GOBL::Extensions::Tax::RegimeHelper::ClassMethods
53
+ GOBL::Bill::Invoice.include GOBL::Extensions::Bill::InvoiceHelper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gobl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luismi Cavalle
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-05-20 00:00:00.000000000 Z
14
+ date: 2023-05-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -146,6 +146,8 @@ files:
146
146
  - lib/gobl.rb
147
147
  - lib/gobl/config.rb
148
148
  - lib/gobl/enum.rb
149
+ - lib/gobl/extensions/bill/invoice_helper.rb
150
+ - lib/gobl/extensions/bill/scenario_summary.rb
149
151
  - lib/gobl/extensions/document_helper.rb
150
152
  - lib/gobl/extensions/envelope_helper.rb
151
153
  - lib/gobl/extensions/i18n/value_keys_helper.rb