xrechnung 0.1.3 → 0.2.0

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: 44b1e46debbb386e29b8d5acf9fff32ce97a374b613ca3359a9f694ea55d58e9
4
- data.tar.gz: 0f81126b1f1fa3d921736970c21f63c130e9d6655913e3fb306f3ccf1d5892b2
3
+ metadata.gz: 4f041dd061b2cbafddf1f119d5dd735030f5090385ae705e4a078fba9308e3c4
4
+ data.tar.gz: bdb51353f944c7560ef64f6f908f45eed508212d357d3e28bd95ba4c8a0b24d7
5
5
  SHA512:
6
- metadata.gz: d03ff9707832f949b7fb51d33b73af0c5d9ef9ce8d07719fb1222aeb907477bf260eb408b5a24ba736d195a845461c744bd706a62a93154e258888a7e8f36d9a
7
- data.tar.gz: b1ae9c060ac8651af67bac032c028e1a48281f6710b0ca53c1f9ab8ba934bfa566a63b405c12f3d80754379cabda493727604aaf2966e4e5e2fca09d6e8f8976
6
+ metadata.gz: 01ecec735fd1d6df67c83ff14a722b48d8fae9191d27f200b12efeb9d810045c54cf8534a0dee6d41d9935a24edf25589b4b872c9c37d14bf11b0b12263bfef9
7
+ data.tar.gz: 682358abc94767c051821749ef42d7bb92f8e687bd6d47b4085dda99e95f5fe52ee4edf8fd99029a2bc37426afd4699ab397eb55c5adeca24a3d56cc5918db7d
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on: [push, fork]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ name: Ruby ${{ matrix.ruby }}
9
+ strategy:
10
+ matrix:
11
+ ruby: ['2.7', '3.0', '3.2']
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true
21
+
22
+ - name: Run rspec
23
+ run: bundle exec rake spec
@@ -7,7 +7,7 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
 
9
9
  steps:
10
- - uses: actions/checkout@v2
10
+ - uses: actions/checkout@v4
11
11
 
12
12
  - uses: actions/setup-java@v2
13
13
  with:
@@ -25,7 +25,7 @@ jobs:
25
25
  - name: Run validator
26
26
  run: bundle exec rake validator:run
27
27
 
28
- - uses: actions/upload-artifact@v2
28
+ - uses: actions/upload-artifact@v4
29
29
  if: failure()
30
30
  with:
31
31
  name: validation-results
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xrechnung (0.1.3)
4
+ xrechnung (0.2.0)
5
5
  builder (~> 3.2)
6
6
 
7
7
  GEM
@@ -9,51 +9,60 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  builder (3.2.4)
12
- diff-lcs (1.4.4)
13
- httparty (0.18.1)
14
- mime-types (~> 3.0)
12
+ diff-lcs (1.5.1)
13
+ httparty (0.21.0)
14
+ mini_mime (>= 1.0.0)
15
15
  multi_xml (>= 0.5.2)
16
- mime-types (3.3.1)
17
- mime-types-data (~> 3.2015)
18
- mime-types-data (3.2021.0225)
16
+ json (2.7.1)
17
+ language_server-protocol (3.17.0.3)
18
+ mini_mime (1.1.5)
19
19
  multi_xml (0.6.0)
20
- parallel (1.20.1)
21
- parser (3.0.1.0)
20
+ parallel (1.24.0)
21
+ parser (3.3.0.5)
22
22
  ast (~> 2.4.1)
23
- rainbow (3.0.0)
24
- rake (13.0.3)
25
- regexp_parser (2.1.1)
26
- rexml (3.2.5)
27
- rspec (3.10.0)
28
- rspec-core (~> 3.10.0)
29
- rspec-expectations (~> 3.10.0)
30
- rspec-mocks (~> 3.10.0)
31
- rspec-core (3.10.1)
32
- rspec-support (~> 3.10.0)
33
- rspec-expectations (3.10.1)
23
+ racc
24
+ racc (1.7.3)
25
+ rainbow (3.1.1)
26
+ rake (13.1.0)
27
+ regexp_parser (2.9.0)
28
+ rexml (3.2.6)
29
+ rspec (3.13.0)
30
+ rspec-core (~> 3.13.0)
31
+ rspec-expectations (~> 3.13.0)
32
+ rspec-mocks (~> 3.13.0)
33
+ rspec-core (3.13.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-expectations (3.13.0)
34
36
  diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.10.0)
36
- rspec-mocks (3.10.2)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-mocks (3.13.0)
37
39
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.10.0)
39
- rspec-support (3.10.2)
40
- rubocop (1.13.0)
40
+ rspec-support (~> 3.13.0)
41
+ rspec-support (3.13.1)
42
+ rubocop (1.62.1)
43
+ json (~> 2.3)
44
+ language_server-protocol (>= 3.17.0)
41
45
  parallel (~> 1.10)
42
- parser (>= 3.0.0.0)
46
+ parser (>= 3.3.0.2)
43
47
  rainbow (>= 2.2.2, < 4.0)
44
48
  regexp_parser (>= 1.8, < 3.0)
45
- rexml
46
- rubocop-ast (>= 1.2.0, < 2.0)
49
+ rexml (>= 3.2.5, < 4.0)
50
+ rubocop-ast (>= 1.31.1, < 2.0)
47
51
  ruby-progressbar (~> 1.7)
48
- unicode-display_width (>= 1.4.0, < 3.0)
49
- rubocop-ast (1.4.1)
50
- parser (>= 2.7.1.5)
51
- rubocop-rspec (2.2.0)
52
- rubocop (~> 1.0)
53
- rubocop-ast (>= 1.1.0)
54
- ruby-progressbar (1.11.0)
55
- rubyzip (2.3.0)
56
- unicode-display_width (2.0.0)
52
+ unicode-display_width (>= 2.4.0, < 3.0)
53
+ rubocop-ast (1.31.2)
54
+ parser (>= 3.3.0.4)
55
+ rubocop-capybara (2.20.0)
56
+ rubocop (~> 1.41)
57
+ rubocop-factory_bot (2.25.1)
58
+ rubocop (~> 1.41)
59
+ rubocop-rspec (2.27.1)
60
+ rubocop (~> 1.40)
61
+ rubocop-capybara (~> 2.17)
62
+ rubocop-factory_bot (~> 2.22)
63
+ ruby-progressbar (1.13.0)
64
+ rubyzip (2.3.2)
65
+ unicode-display_width (2.5.0)
57
66
 
58
67
  PLATFORMS
59
68
  ruby
@@ -67,4 +76,4 @@ DEPENDENCIES
67
76
  xrechnung!
68
77
 
69
78
  BUNDLED WITH
70
- 2.2.15
79
+ 2.4.19
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ namespace :validator do
14
14
  },
15
15
  scenarios: {
16
16
  filename: "validator/scenarios.xml",
17
- release_url: "https://github.com/itplr-kosit/validator-configuration-xrechnung/releases/download/release-2020-12-31/validator-configuration-xrechnung_2.0.1_2020-12-31.zip",
17
+ release_url: "https://github.com/itplr-kosit/validator-configuration-xrechnung/releases/download/release-2023-05-12/validator-configuration-xrechnung_2.3.1_2023-05-12.zip",
18
18
  }
19
19
  }
20
20
 
@@ -1,3 +1,5 @@
1
+ require "xrechnung/invoice_period"
2
+
1
3
  module Xrechnung
2
4
  class InvoiceLine
3
5
  include MemberContainer
@@ -14,6 +16,10 @@ module Xrechnung
14
16
  # @return [Xrechnung::Currency]
15
17
  member :line_extension_amount, type: Xrechnung::Currency
16
18
 
19
+ # @!attribute invoice_period
20
+ # @return [Xrechnung::InvoicePeriod]
21
+ member :invoice_period, type: Xrechnung::InvoicePeriod, optional: true
22
+
17
23
  # @!attribute item
18
24
  # @return [Xrechnung::Item]
19
25
  member :item, type: Xrechnung::Item
@@ -33,6 +39,10 @@ module Xrechnung
33
39
  xml.cbc :ID, id
34
40
  xml.cbc :InvoicedQuantity, invoiced_quantity.amount_to_s, unitCode: invoiced_quantity.unit_code
35
41
  xml.cbc :LineExtensionAmount, *line_extension_amount.xml_args
42
+
43
+ unless self.class.members[:invoice_period].optional && invoice_period.nil?
44
+ invoice_period&.to_xml(xml)
45
+ end
36
46
  item&.to_xml(xml)
37
47
  price&.to_xml(xml)
38
48
  end
@@ -0,0 +1,20 @@
1
+ module Xrechnung
2
+ class InvoicePeriod
3
+ include MemberContainer
4
+
5
+ # @!attribute start_date
6
+ # @return [Date]
7
+ member :start_date, type: Date
8
+
9
+ # @!attribute end_date
10
+ # @return [Date]
11
+ member :end_date, type: Date
12
+
13
+ def to_xml(xml)
14
+ xml.cac :InvoicePeriod do
15
+ xml.cbc :StartDate, start_date
16
+ xml.cbc :EndDate, end_date
17
+ end
18
+ end
19
+ end
20
+ end
@@ -40,10 +40,10 @@ module Xrechnung
40
40
 
41
41
  # noinspection RubyResolve
42
42
  def to_xml(xml)
43
- members.each do |member, _options|
44
- next if self[member].nil?
43
+ self.class.members.each_key do |name|
44
+ next if self[name].nil?
45
45
 
46
- xml.cbc :"#{member.to_s.split("_").map(&:capitalize).join}", *self[member].xml_args
46
+ xml.cbc :"#{name.to_s.split("_").map(&:capitalize).join}", *self[name].xml_args
47
47
  end
48
48
  xml.target!
49
49
  end
@@ -6,8 +6,9 @@ module Xrechnung
6
6
  end
7
7
 
8
8
  def initialize(**kwargs)
9
- self.class.after_initialize.each do |block|
10
- instance_eval(&block)
9
+ # initialize default values
10
+ self.class.members.each do |name, member|
11
+ self[name] = member.default.dup unless member.default.nil?
11
12
  end
12
13
 
13
14
  kwargs.each do |k, v|
@@ -15,54 +16,44 @@ module Xrechnung
15
16
  end
16
17
  end
17
18
 
18
- def members
19
- self.class.instance_variable_get :@members
20
- end
21
-
22
19
  def [](key)
23
20
  send(key)
24
21
  end
25
22
 
26
23
  def []=(key, value)
27
- send(members[key].fetch(:setter_name), value)
24
+ send("#{key}=", value)
28
25
  end
29
26
 
27
+ Member = Struct.new(:type, :default, :optional, :transform_value, keyword_init: true)
28
+
30
29
  module ClassMethods
30
+ def members
31
+ @members
32
+ end
33
+
31
34
  # @param [String] member_name
32
35
  # @param [Array<Class>, Class] type
33
36
  # @param [Object] default
34
37
  # @param [TrueClass, FalseClass] optional When true, omits tag rather than rendering an empty tag on nil
35
38
  # @param [Proc] transform_value A Proc which is called with the input value to perform type conversion.
36
- def member(member_name, type: nil, default: nil, optional: false, transform_value: nil)
39
+ def member(member_name, **kwargs)
37
40
  attr_reader member_name
38
- setter_name = :"#{member_name}="
39
- @members[member_name] = { optional: optional, setter_name: setter_name }
41
+ kwargs[:default].freeze
40
42
 
41
- if default
42
- after_initialize do
43
- send(setter_name, default)
44
- end
45
- end
43
+ setter_name = :"#{member_name}="
44
+ member = Member.new(**kwargs)
45
+ @members[member_name] = member
46
46
 
47
47
  define_method setter_name do |in_value|
48
- in_value = transform_value.call(in_value) if transform_value
48
+ in_value = member.transform_value.call(in_value) if member.transform_value
49
49
 
50
- if type && !in_value.nil? && Array(type).none? { |t| in_value.is_a?(t) }
51
- raise ArgumentError, "expected #{type} for :#{member_name}, got: #{in_value.class}"
50
+ if member.type && !in_value.nil? && Array(member.type).none? { |t| in_value.is_a?(t) }
51
+ raise ArgumentError, "expected #{member.type} for :#{member_name}, got: #{in_value.class}"
52
52
  end
53
53
 
54
54
  instance_variable_set :"@#{member_name}", in_value
55
55
  end
56
56
  end
57
-
58
- def after_initialize(&block)
59
- @after_initialize_blocks ||= []
60
- if block
61
- @after_initialize_blocks << block
62
- else
63
- @after_initialize_blocks
64
- end
65
- end
66
57
  end
67
58
  end
68
59
  end
@@ -1,3 +1,3 @@
1
1
  module Xrechnung
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/xrechnung.rb CHANGED
@@ -21,6 +21,7 @@ require "xrechnung/allowance_charge"
21
21
  require "xrechnung/price"
22
22
  require "xrechnung/invoice_line"
23
23
  require "xrechnung/invoice_document_reference"
24
+ require "xrechnung/invoice_period"
24
25
  require "builder"
25
26
 
26
27
  module Xrechnung
@@ -168,6 +169,10 @@ module Xrechnung
168
169
  # @return [Xrechnung::InvoiceDocumentReference]
169
170
  member :billing_reference, type: Xrechnung::InvoiceDocumentReference, optional: true
170
171
 
172
+ # @!attribute invoice_period
173
+ # @return [Xrechnung::InvoicePeriod]
174
+ member :invoice_period, type: Xrechnung::InvoicePeriod, optional: true
175
+
171
176
  # Contract reference BT-12
172
177
  #
173
178
  # Eine eindeutige Bezeichnung des Vertrages (z. B. Vertragsnummer).
@@ -250,7 +255,7 @@ module Xrechnung
250
255
  "xmlns:cbc" => "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2",
251
256
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
252
257
  "xsi:schemaLocation" => "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd" do
253
- xml.cbc :CustomizationID, "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0"
258
+ xml.cbc :CustomizationID, "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.3"
254
259
  xml.cbc :ID, id
255
260
  xml.cbc :IssueDate, issue_date
256
261
  xml.cbc :DueDate, due_date
@@ -260,19 +265,23 @@ module Xrechnung
260
265
  xml.cbc :Note, note
261
266
  end
262
267
 
263
- xml.cbc :TaxPointDate, tax_point_date
268
+ xml.cbc :TaxPointDate, tax_point_date unless tax_point_date.nil?
264
269
  xml.cbc :DocumentCurrencyCode, document_currency_code
265
270
  xml.cbc :TaxCurrencyCode, tax_currency_code
266
271
  xml.cbc :BuyerReference, buyer_reference
267
272
 
273
+ unless self.class.members[:invoice_period].optional && invoice_period.nil?
274
+ invoice_period&.to_xml(xml)
275
+ end
276
+
268
277
  xml.cac :OrderReference do
269
278
  xml.cbc :ID, purchase_order_reference
270
- unless members[:sales_order_reference][:optional] && sales_order_reference.nil?
279
+ unless self.class.members[:sales_order_reference].optional && sales_order_reference.nil?
271
280
  xml.cbc :SalesOrderID, sales_order_reference
272
281
  end
273
282
  end
274
283
 
275
- unless members[:billing_reference][:optional] && billing_reference.nil?
284
+ unless self.class.members[:billing_reference].optional && billing_reference.nil?
276
285
  xml.cac :BillingReference do
277
286
  billing_reference&.to_xml(xml)
278
287
  end
@@ -294,7 +303,7 @@ module Xrechnung
294
303
  accounting_customer_party&.to_xml(xml)
295
304
  end
296
305
 
297
- unless members[:tax_representative_party][:optional] && tax_representative_party.nil?
306
+ unless self.class.members[:tax_representative_party].optional && tax_representative_party.nil?
298
307
  xml.cac :TaxRepresentativeParty do
299
308
  tax_representative_party&.to_xml(xml)
300
309
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrechnung
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Kornberger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2024-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -52,13 +52,14 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
- description:
55
+ description:
56
56
  email:
57
57
  - jk+github@digineo.de
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/workflows/rspec.yml"
62
63
  - ".github/workflows/validate-fixtures.yml"
63
64
  - ".gitignore"
64
65
  - ".rspec"
@@ -78,6 +79,7 @@ files:
78
79
  - lib/xrechnung/id.rb
79
80
  - lib/xrechnung/invoice_document_reference.rb
80
81
  - lib/xrechnung/invoice_line.rb
82
+ - lib/xrechnung/invoice_period.rb
81
83
  - lib/xrechnung/item.rb
82
84
  - lib/xrechnung/legal_monetary_total.rb
83
85
  - lib/xrechnung/member_container.rb
@@ -101,7 +103,7 @@ licenses:
101
103
  metadata:
102
104
  homepage_uri: https://github.com/digineo/xrechnung
103
105
  source_code_uri: https://github.com/digineo/xrechnung
104
- post_install_message:
106
+ post_install_message:
105
107
  rdoc_options: []
106
108
  require_paths:
107
109
  - lib
@@ -117,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  version: '0'
118
120
  requirements: []
119
121
  rubygems_version: 3.1.6
120
- signing_key:
122
+ signing_key:
121
123
  specification_version: 4
122
124
  summary: Library to create invoices in the XRechnung format.
123
125
  test_files: []