cfdi40 0.2.0 → 0.3.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cfdi40/complemento.rb +4 -0
- data/lib/cfdi40/comprobante.rb +14 -0
- data/lib/cfdi40/concepto.rb +6 -4
- data/lib/cfdi40/impuestos.rb +2 -2
- data/lib/cfdi40/node.rb +12 -1
- data/lib/cfdi40/timbre.rb +12 -0
- data/lib/cfdi40/traslado.rb +2 -2
- data/lib/cfdi40/version.rb +1 -1
- data/lib/cfdi40/xml_loader.rb +9 -0
- data/lib/cfdi40.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3be0f21285d38b188da1f754be05c94c8e441397b99c0999fad9ded2f49aad1e
|
4
|
+
data.tar.gz: 182ddc911312bb0e40785baef05ec34e0a5d365b48e8aac6be50c1e89febcf5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0a03c705030d5cc17c8709a68b4e8054d170d93426c93e6162f3b728efbaa2d3771f389a0014a978edae29e8e615376090fb2c7a9b2c40ae48f704e865f97fd
|
7
|
+
data.tar.gz: 0e565d63b5e549bfff192979f34b2385fdf161923b0974a8f566b9bb023d61ede67ed94ad906f343686ff67d9113b55780f8aeeba92e9f1fe3bd24b10c7edaa6
|
data/Gemfile.lock
CHANGED
data/lib/cfdi40/complemento.rb
CHANGED
data/lib/cfdi40/comprobante.rb
CHANGED
@@ -264,6 +264,20 @@ module Cfdi40
|
|
264
264
|
traslados.traslados_iva.map(&:importe).map(&:to_f).sum.round(2)
|
265
265
|
end
|
266
266
|
|
267
|
+
def load_tfd(tfd_node)
|
268
|
+
timbre = Cfdi40::Timbre.new
|
269
|
+
timbre.load_from_ng_node(tfd_node)
|
270
|
+
timbre.parent_node = complemento
|
271
|
+
complemento.children_nodes << timbre
|
272
|
+
timbre
|
273
|
+
end
|
274
|
+
|
275
|
+
def timbre
|
276
|
+
return nil unless defined?(@complemento)
|
277
|
+
|
278
|
+
complemento.timbre
|
279
|
+
end
|
280
|
+
|
267
281
|
private
|
268
282
|
|
269
283
|
def add_node_concepto_actividad_pago
|
data/lib/cfdi40/concepto.rb
CHANGED
@@ -89,9 +89,11 @@ module Cfdi40
|
|
89
89
|
|
90
90
|
def calculate_from_net_price
|
91
91
|
set_defaults
|
92
|
-
@precio_neto = @precio_neto.round(
|
93
|
-
@precio_bruto = (@precio_neto / ((1 + tasa_iva.to_f) * (1 + tasa_ieps.to_f)))
|
92
|
+
@precio_neto = @precio_neto.round(6)
|
93
|
+
@precio_bruto = (@precio_neto / ((1 + tasa_iva.to_f) * (1 + tasa_ieps.to_f)))
|
94
94
|
calculate_taxes
|
95
|
+
|
96
|
+
@precio_bruto = (((@precio_neto * cantidad.to_f) - @iva - @ieps) / cantidad.to_f.round(6)).round(6)
|
95
97
|
update_xml_attributes
|
96
98
|
end
|
97
99
|
|
@@ -106,9 +108,9 @@ module Cfdi40
|
|
106
108
|
|
107
109
|
def calculate_taxes
|
108
110
|
@base_ieps = (@precio_bruto * cantidad.to_f).round(6)
|
109
|
-
@ieps = (@base_ieps * tasa_ieps.to_f).round(
|
111
|
+
@ieps = (@base_ieps * tasa_ieps.to_f).round(6)
|
110
112
|
@base_iva = (@base_ieps + @ieps).round(6)
|
111
|
-
@iva = (@base_iva * tasa_iva.to_f).round(
|
113
|
+
@iva = (@base_iva * tasa_iva.to_f).round(6)
|
112
114
|
@importe_bruto = @base_ieps
|
113
115
|
@importe_neto = (@base_iva + @iva).round(2)
|
114
116
|
end
|
data/lib/cfdi40/impuestos.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# /cfdi:Comprobante/cfdi:Impuestos
|
4
4
|
module Cfdi40
|
5
5
|
class Impuestos < Node
|
6
|
-
define_attribute :total_impuestos_retenidos, xml_attribute: "TotalImpuestosRetenidos", format: :
|
7
|
-
define_attribute :total_impuestos_trasladados, xml_attribute: "TotalImpuestosTrasladados", format: :
|
6
|
+
define_attribute :total_impuestos_retenidos, xml_attribute: "TotalImpuestosRetenidos", format: :t_ImporteMXN
|
7
|
+
define_attribute :total_impuestos_trasladados, xml_attribute: "TotalImpuestosTrasladados", format: :t_ImporteMXN
|
8
8
|
|
9
9
|
def traslados
|
10
10
|
return @traslados if defined?(@traslados)
|
data/lib/cfdi40/node.rb
CHANGED
@@ -187,7 +187,18 @@ module Cfdi40
|
|
187
187
|
self.class.attributes.each do |variable_name, attr_name|
|
188
188
|
next if ng_node.attributes[attr_name].nil?
|
189
189
|
|
190
|
-
|
190
|
+
case self.class.formats[variable_name]
|
191
|
+
when :t_FechaH, :t_FechaHora
|
192
|
+
begin
|
193
|
+
parsed_time = Time.strptime(ng_node.attributes[attr_name].value, "%Y-%m-%dT%H:%M:%S")
|
194
|
+
instance_variable_set("@#{variable_name}".to_sym, parsed_time)
|
195
|
+
rescue
|
196
|
+
puts "Warning: cannot parse '#{value}' as Time"
|
197
|
+
next
|
198
|
+
end
|
199
|
+
else
|
200
|
+
instance_variable_set("@#{variable_name}".to_sym, ng_node.attributes[attr_name].value)
|
201
|
+
end
|
191
202
|
end
|
192
203
|
end
|
193
204
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Cfdi40
|
3
|
+
class Timbre < Node
|
4
|
+
define_attribute :version, readonly: true, xml_attribute: "Version"
|
5
|
+
define_attribute :rfc_prov_certif, readonly: true, xml_attribute: "RfcProvCertif"
|
6
|
+
define_attribute :fecha_timbrado, readonly: true, xml_attribute: "FechaTimbrado", format: :t_FechaH
|
7
|
+
define_attribute :uuid, readonly: true, xml_attribute: "UUID"
|
8
|
+
define_attribute :sello_cfd, readonly: true, xml_attribute: "SelloCFD"
|
9
|
+
define_attribute :sello_sat, readonly: true, xml_attribute: "SelloSAT"
|
10
|
+
define_attribute :no_certificado_sat, readonly: true, xml_attribute: "NoCertificadoSAT"
|
11
|
+
end
|
12
|
+
end
|
data/lib/cfdi40/traslado.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
# /cfdi:Comprobante/cfdi:Impuestos/cfdi:Traslados/cfdi:Traslado
|
4
4
|
module Cfdi40
|
5
5
|
class Traslado < Node
|
6
|
-
define_attribute :base, xml_attribute: "Base", format: :
|
6
|
+
define_attribute :base, xml_attribute: "Base", format: :t_ImporteMXN
|
7
7
|
define_attribute :impuesto, xml_attribute: "Impuesto"
|
8
8
|
define_attribute :tipo_factor, xml_attribute: "TipoFactor", default: "Tasa"
|
9
9
|
define_attribute :tasa_o_cuota, xml_attribute: "TasaOCuota", format: :t_Importe
|
10
|
-
define_attribute :importe, xml_attribute: "Importe", format: :
|
10
|
+
define_attribute :importe, xml_attribute: "Importe", format: :t_ImporteMXN
|
11
11
|
end
|
12
12
|
end
|
data/lib/cfdi40/version.rb
CHANGED
data/lib/cfdi40/xml_loader.rb
CHANGED
@@ -17,6 +17,7 @@ module Cfdi40
|
|
17
17
|
load_receptor
|
18
18
|
load_conceptos
|
19
19
|
load_impuestos
|
20
|
+
load_tfd
|
20
21
|
|
21
22
|
@cfdi.lock if readonly?
|
22
23
|
@cfdi.loaded_xml = xml_string
|
@@ -62,5 +63,13 @@ module Cfdi40
|
|
62
63
|
|
63
64
|
@cfdi.load_impuestos(impuestos_node)
|
64
65
|
end
|
66
|
+
|
67
|
+
def load_tfd
|
68
|
+
tfd_namespace = { "tfd" => "http://www.sat.gob.mx/TimbreFiscalDigital" }
|
69
|
+
tfd_node = xml_doc.xpath("//tfd:TimbreFiscalDigital", tfd_namespace).first
|
70
|
+
return if tfd_node.nil?
|
71
|
+
|
72
|
+
@cfdi.load_tfd(tfd_node)
|
73
|
+
end
|
65
74
|
end
|
66
75
|
end
|
data/lib/cfdi40.rb
CHANGED
@@ -32,6 +32,7 @@ require_relative "cfdi40/impuestos_p"
|
|
32
32
|
require_relative "cfdi40/traslados_p"
|
33
33
|
require_relative "cfdi40/traslado_p"
|
34
34
|
require_relative "cfdi40/cp_totales"
|
35
|
+
require_relative "cfdi40/timbre"
|
35
36
|
require_relative "cfdi40/xml_loader"
|
36
37
|
|
37
38
|
# Leading module and entry point for all features and classes
|
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
|
+
version: 0.3.0
|
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-08-
|
11
|
+
date: 2025-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/cfdi40/sat_csd.rb
|
65
65
|
- lib/cfdi40/schema_validator.rb
|
66
66
|
- lib/cfdi40/signature_validator.rb
|
67
|
+
- lib/cfdi40/timbre.rb
|
67
68
|
- lib/cfdi40/traslado.rb
|
68
69
|
- lib/cfdi40/traslado_dr.rb
|
69
70
|
- lib/cfdi40/traslado_p.rb
|