cfdi40 0.1.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf7ce0ac8de4ab678da94ef6a052c68ea8a403c0b9c349b252654d4bf9771cde
4
- data.tar.gz: bc02e70bc14b70576f178b3fed467970d36cc6f72693e9bc78415963cab435e4
3
+ metadata.gz: f610f343a775755d3ec5e603588f8693ac502c576c56a32bf6dda422a7eebebe
4
+ data.tar.gz: 0e72a90973ca6f28b42b0c793951400a0d5ae8532bbb7c2d750c917cbae41b38
5
5
  SHA512:
6
- metadata.gz: a2b13b7fccfdf28774032f0b7e9b95028d7b96c0d6803d1f04b547f26435a0532f7b43c1644ae1309fe4168409ba34543d3164b99995c62b4b70a1d32f4bfaef
7
- data.tar.gz: 37637f8e76f129a3582b963b3ef3e8206fb5a997d527feb6ec507b75f2f5983346fcdcef93d63684265d6846debde1539d04b7c836c50ca390a33934b1d2b688
6
+ metadata.gz: 1cfcc729870cb04928ad9534068843df9ea61a9a6f9b0e994500f0b94b16f01659427984a05e05cc991900055bd4ac5bf8456d2ddabe0ffd7570f8e229693042
7
+ data.tar.gz: cfd0ca0717d596c1347e42d6ff680c39c13c57c0cf83c5ad9005ca96c9efcc5f9e1bd55ed706a086b99657bba0ff244b5eba8abcfabe50980f1481651429a87d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cfdi40 (0.0.9)
4
+ cfdi40 (0.1.2)
5
5
  nokogiri (>= 1.10.10)
6
6
 
7
7
  GEM
@@ -152,6 +152,7 @@ module Cfdi40
152
152
  concepto = Concepto.new
153
153
  concepto.parent_node = @conceptos
154
154
  concepto.load_from_ng_node(ng_node)
155
+ concepto.precio_bruto = concepto.valor_unitario.to_f
155
156
  @conceptos.children_nodes << concepto
156
157
  concepto
157
158
  end
@@ -223,12 +224,6 @@ module Cfdi40
223
224
  impuestos_node.total_impuestos_trasladados
224
225
  end
225
226
 
226
- def total_iva_node
227
- return nil unless impuestos_node
228
-
229
- impuestos_node.traslado_iva
230
- end
231
-
232
227
  def calculate!
233
228
  @docxml = nil
234
229
  @subtotal = @conceptos.children_nodes.map(&:importe).map(&:to_f).sum
@@ -240,6 +235,19 @@ module Cfdi40
240
235
  @conceptos.children_nodes
241
236
  end
242
237
 
238
+ def total_iva_node
239
+ # TODO: Puede haber más de un nodo, cuando hay varias tasas de iva
240
+ return nil unless impuestos_node
241
+
242
+ impuestos_node.traslado_iva
243
+ end
244
+
245
+ def total_iva
246
+ return 0 unless traslados
247
+
248
+ traslados.traslados_iva.map(&:importe).map(&:to_f).sum.round(2)
249
+ end
250
+
243
251
  private
244
252
 
245
253
  def add_node_concepto_actividad_pago
@@ -324,11 +332,6 @@ module Cfdi40
324
332
  impuestos_node.traslados
325
333
  end
326
334
 
327
- # TODO: Eliminar
328
- def traslado_iva_node
329
- impuestos_node.traslado_iva
330
- end
331
-
332
335
  def load_private_key
333
336
  return unless defined?(@key_data)
334
337
 
@@ -82,6 +82,7 @@ module Cfdi40
82
82
 
83
83
  def load_traslado_iva(ng_node)
84
84
  traslado_iva_node.load_from_ng_node(ng_node)
85
+ calculate_from_gross_price
85
86
  end
86
87
 
87
88
  private
@@ -99,15 +100,15 @@ module Cfdi40
99
100
  calculate_taxes
100
101
  # May be can not be rounded with 2 decimals.
101
102
  # Example gross_price = 1.99512
102
- @precio_neto = (@importe_neto / cantidad).round(6)
103
+ @precio_neto = (@importe_neto / cantidad.to_f).round(6)
103
104
  update_xml_attributes
104
105
  end
105
106
 
106
107
  def calculate_taxes
107
- @base_ieps = (@precio_bruto * cantidad.to_f).round(2)
108
- @ieps = (@base_ieps * tasa_ieps.to_f).round(2)
109
- @base_iva = (@base_ieps + @ieps).round(2)
110
- @iva = (@base_iva * tasa_iva.to_f).round(2)
108
+ @base_ieps = (@precio_bruto * cantidad.to_f).round(6)
109
+ @ieps = (@base_ieps * tasa_ieps.to_f).round(4)
110
+ @base_iva = (@base_ieps + @ieps).round(6)
111
+ @iva = (@base_iva * tasa_iva.to_f).round(4)
111
112
  @importe_bruto = @base_ieps
112
113
  @importe_neto = (@base_iva + @iva).round(2)
113
114
  end
@@ -16,5 +16,9 @@ module Cfdi40
16
16
  def traslado_nodes
17
17
  children_nodes
18
18
  end
19
+
20
+ def traslados_iva
21
+ children_nodes.select { |node| node.impuesto == '002' }
22
+ end
19
23
  end
20
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cfdi40
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfdi40
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Israel Benítez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-06-11 00:00:00.000000000 Z
11
+ date: 2025-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri