cfdi40 0.4.3 → 0.4.4

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: 463e9e9afbe82401d3664da4e110e8c3be599db170884715b0b2a43762aad5b8
4
- data.tar.gz: c688efebca0b62e00c85d0edc2d24be6d3b5add127aa8ee1f9217dd9234be17d
3
+ metadata.gz: c5d902e16b11421579d59b2cf22aac71d40602829d952e43825c38f448689b67
4
+ data.tar.gz: 5f1a7d20d12018956c459cce25ea08701778c87a5ac5b665da7760dff72699b4
5
5
  SHA512:
6
- metadata.gz: aac1fa7a86a1a8fcffe9b435b718f3ce665777da9a27f747e2a170d4d28b675b37e7e9656d2a522558926674dcaaafc08776448ad6652be5f3ab678d58d83d50
7
- data.tar.gz: abedeb3fad410bd0e338b91279ceec3652b4dbf182acd884da53c8fdeee88e1259e698e798b3c264d430ea315dcfd8d184d13a02965494658350794cd191ddba
6
+ metadata.gz: 77abcb157daa8154ec16bd2c1fc847715034f78905f44a7dd94a29c5274121d38d781bcf5ec504b7dbf0661ecd8964773260be691db742158d2eeef34b3e80fc
7
+ data.tar.gz: '0638c1cbaeb96408dac0f3822a8f198d32452d99fa6af66b8a28fc1fcd16ad95ee274221aa8b2069b40ffaf15bd23223cd0fbe0752553f63767b5ea21659e05a'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cfdi40 (0.4.3)
4
+ cfdi40 (0.4.4)
5
5
  nokogiri (>= 1.10.10)
6
6
 
7
7
  GEM
@@ -32,11 +32,11 @@ module Cfdi40
32
32
  @pagos = Cfdi40::Pagos.new
33
33
  @pagos.load_from_ng_node(pagos_node)
34
34
  @pagos.parent_node = self
35
+ totales_node = pagos_node.xpath("//pago20:Totales", Cfdi40::Pagos::NG_NAMESPACE).first
36
+ @pagos.load_totales(totales_node) unless totales_node.nil?
35
37
  pagos_node.xpath("//pago20:Pago", Cfdi40::Pagos::NG_NAMESPACE).each do |pago_node|
36
38
  @pagos.load_pago(pago_node)
37
39
  end
38
- totales_node = pagos_node.xpath("//pago20:Totales", Cfdi40::Pagos::NG_NAMESPACE).first
39
- @pagos.load_totales(totales_node) unless totales_node.nil?
40
40
  @children_nodes << @pagos
41
41
  @pagos
42
42
  end
@@ -32,7 +32,7 @@ module Cfdi40
32
32
  define_attribute :confirmacion, xml_attribute: "Confirmacion"
33
33
 
34
34
  attr_reader :emisor, :receptor, :conceptos, :private_key, :sat_csd, :errors, :cadena_original
35
- attr_writer :key_data, :key_pass
35
+ attr_writer :key_data, :key_pass, :namespace_pagos_on_root
36
36
  attr_accessor :loaded_xml
37
37
 
38
38
  def initialize
@@ -47,6 +47,7 @@ module Cfdi40
47
47
  @sat_csd = SatCsd.new
48
48
  @fecha ||= Time.now
49
49
  @children_nodes = [@emisor, @receptor, @conceptos]
50
+ @namespace_pagos_on_root = false
50
51
  set_defaults
51
52
  end
52
53
 
@@ -214,6 +215,8 @@ module Cfdi40
214
215
  return loaded_xml if !loaded_xml.nil? && signed?
215
216
 
216
217
  sign unless signed?
218
+ return xml_string_ns_pagos_on_root if @namespace_pagos_on_root && pago_nodes.count > 0
219
+
217
220
  docxml.to_xml
218
221
  end
219
222
 
@@ -300,6 +303,14 @@ module Cfdi40
300
303
  complemento.timbre
301
304
  end
302
305
 
306
+ # Some PACs require that the namespace pago20 be placed in root node
307
+ def add_namespace_pagos_to_root
308
+ self.class.define_namespace "pago20", "http://www.sat.gob.mx/Pagos20"
309
+ @schema_location += " http://www.sat.gob.mx/Pagos20 " \
310
+ "http://www.sat.gob.mx/sitio_internet/cfd/Pagos/Pagos20.xsd"
311
+ true
312
+ end
313
+
303
314
  private
304
315
 
305
316
  def add_node_concepto_actividad_pago
@@ -399,5 +410,16 @@ module Cfdi40
399
410
  @children_nodes << @complemento
400
411
  @complemento
401
412
  end
413
+
414
+ # Creates a new XML an change and puts the namespace pagos on root element.
415
+ def xml_string_ns_pagos_on_root
416
+ tmp_nkgdoc = Nokogiri::XML(docxml.to_xml)
417
+ tmp_nkgdoc.root["xmlns:pago20"] = "http://www.sat.gob.mx/Pagos20"
418
+ unless tmp_nkgdoc.root["xsi:schemaLocation"].include?("Pagos20")
419
+ tmp_nkgdoc.root["xsi:schemaLocation"] += " http://www.sat.gob.mx/Pagos20" \
420
+ " http://www.sat.gob.mx/sitio_internet/cfd/Pagos/Pagos20.xsd"
421
+ end
422
+ tmp_nkgdoc.to_xml
423
+ end
402
424
  end
403
425
  end
@@ -6,7 +6,7 @@ module Cfdi40
6
6
  define_attribute :serie, xml_attribute: "Serie"
7
7
  define_attribute :folio, xml_attribute: "Folio"
8
8
  define_attribute :moneda_dr, xml_attribute: "MonedaDR", default: "MXN"
9
- define_attribute :equivalencia_dr, xml_attribute: "EquivalenciaDR", default: "1", format: :decimal
9
+ define_attribute :equivalencia_dr, xml_attribute: "EquivalenciaDR", default: "1"
10
10
  define_attribute :num_parcialidad, xml_attribute: "NumParcialidad"
11
11
  define_attribute :imp_saldo_ant, xml_attribute: "ImpSaldoAnt", format: :t_ImporteMXN
12
12
  define_attribute :imp_pagado, xml_attribute: "ImpPagado", format: :t_ImporteMXN
@@ -9,5 +9,19 @@ module Cfdi40
9
9
  add_child_node @traslados_p
10
10
  @traslados_p
11
11
  end
12
+
13
+ def traslados_p_node
14
+ @children_nodes.select {|child| child.instance_of?(Cfdi40::TrasladosP) }.first
15
+ end
16
+
17
+ def load_traslados_p_node(ng_node)
18
+ @traslados_p = TrasladosP.new
19
+ @traslados_p.load_from_ng_node(ng_node)
20
+ add_child_node @traslados_p
21
+ ng_node.xpath("//pago20:TrasladoP", { "pago20" => "http://www.sat.gob.mx/Pagos20" }).each do |trsld_p_node|
22
+ @traslados_p.load_traslado_p(trsld_p_node)
23
+ end
24
+ @traslados_p
25
+ end
12
26
  end
13
27
  end
data/lib/cfdi40/pago.rb CHANGED
@@ -38,7 +38,7 @@ module Cfdi40
38
38
 
39
39
  @docto_relacionados =
40
40
  @children_nodes.select do |child|
41
- child if child.instance_of?(::Cfdi40::DoctoRelacionado)
41
+ child.instance_of?(::Cfdi40::DoctoRelacionado)
42
42
  end
43
43
  end
44
44
 
@@ -65,5 +65,18 @@ module Cfdi40
65
65
  dr.load_impuestos_dr(imp_dr_node) unless imp_dr_node.nil?
66
66
  dr
67
67
  end
68
+
69
+ def impuestos_p_node
70
+ @children_nodes.select { |child| child.instance_of?(Cfdi40::ImpuestosP) }.first
71
+ end
72
+
73
+ def load_impuestos_p(ng_node)
74
+ imp_p = ImpuestosP.new
75
+ imp_p.load_from_ng_node(ng_node)
76
+ add_child_node imp_p
77
+ trns_p_node = ng_node.xpath("//pago20:TrasladosP", { "pago20" => "http://www.sat.gob.mx/Pagos20" }).first
78
+ imp_p.load_traslados_p_node(trns_p_node)
79
+ imp_p
80
+ end
68
81
  end
69
82
  end
data/lib/cfdi40/pagos.rb CHANGED
@@ -103,11 +103,12 @@ module Cfdi40
103
103
  def load_pago(pago_node)
104
104
  pago = Pago.new
105
105
  pago.load_from_ng_node(pago_node)
106
- pago.parent_node = self
107
- @children_nodes << pago
106
+ add_child_node pago
108
107
  pago_node.xpath("//pago20:DoctoRelacionado", { "pago20" => "http://www.sat.gob.mx/Pagos20" }).each do |dr_node|
109
108
  pago.load_dr(dr_node)
110
109
  end
110
+ imp_p_node = pago_node.xpath("//pago20:ImpuestosP", { "pago20" => "http://www.sat.gob.mx/Pagos20" }).first
111
+ pago.load_impuestos_p(imp_p_node) if imp_p_node
111
112
  pago
112
113
  end
113
114
 
@@ -14,5 +14,16 @@ module Cfdi40
14
14
  add_child_node traslado_p
15
15
  end
16
16
  end
17
+
18
+ def traslado_p_nodes
19
+ @children_nodes.select { |child| child.instance_of?(Cfdi40::TrasladoP) }
20
+ end
21
+
22
+ def load_traslado_p(ng_node)
23
+ traslado_p = TrasladoP.new
24
+ traslado_p.load_from_ng_node(ng_node)
25
+ add_child_node traslado_p
26
+ traslado_p
27
+ end
17
28
  end
18
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cfdi40
4
- VERSION = "0.4.3"
4
+ VERSION = "0.4.4"
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.4.3
4
+ version: 0.4.4
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-12-05 00:00:00.000000000 Z
11
+ date: 2025-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri