cfdi40 0.3.2 → 0.4.1

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: 2b059ddd5e63b0d7cfb314d888c3adf99da0ee6e1d715555a586b94cdecb6213
4
- data.tar.gz: 5f6538b53add3cc98020d612644fa5a420ec629cbb0ab62c878e1b01293945a0
3
+ metadata.gz: 0640bebb04d18652cf33f6dbd3f21a1628bb0df9602f9c4644d89a52da9a8604
4
+ data.tar.gz: ca5d8c18c35dc547f7321089c6e932bea09a8304bc02d7604ee1b042de7440f0
5
5
  SHA512:
6
- metadata.gz: 4928ad092b02eb76e8262f68d00d265dc32686759956491199d5bd7357d6aa6390019eb7073fbabb354ef4a1c58fc761810bc7ef14ac54bd26e14d3e1672bb1a
7
- data.tar.gz: 512ec675667b5b1c768035d70c451c4c255b174ea91bf1dde8b0984298fa5dfff75e29648b6e7fba8b7c1dfc8253155d6edb276bca34d2a2137a8c17da23505f
6
+ metadata.gz: 6bdf05c00a3161967b2c053896a3d8575a2d9a0c519980fd3b22e28ba33751cc1a312f8d8944dc34a2183012e3f58468704657c904247691d2bb2ff123f3723d
7
+ data.tar.gz: 26e267b91dec8b0ebcd41cf7c9fc09951bcbda73610a97375b9536ef605e2c0e8c70d52e010257aefe6260a696f037f2365092c240bd71823f28d57b59c44c12
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cfdi40 (0.3.1)
4
+ cfdi40 (0.4.1)
5
5
  nokogiri (>= 1.10.10)
6
6
 
7
7
  GEM
data/README_es-MX.md CHANGED
@@ -77,9 +77,7 @@ Hasta ahora:
77
77
  cfdi.receptor.regimen_fiscal = '616'
78
78
  cfdi.receptor.uso_cfdi = 'CP01'
79
79
 
80
- # Agrega un concepto en pesos,
81
- # precio final al cliente (neto)
82
- # causa IVA con tasa de 16% (default)
80
+ # Agrega un pago en pesos
83
81
  cfdi.add_pago(
84
82
  monto: 200.17,
85
83
  uuid: 'e40229b3-5c4b-46fb-9ba8-707df828a5bc',
@@ -91,6 +89,10 @@ Hasta ahora:
91
89
  importe_saldo_anterior: 845.673
92
90
  )
93
91
 
92
+ # Elimina el n-ésimo pago
93
+ # 0 es el primer pago
94
+ cfdi.remove_pago(1)
95
+
94
96
  # Archivos CSD
95
97
  cfdi.cert_path = '/path_to/certificado.cer'
96
98
  cfdi.key_path = '/path_to/llave_privada.key'
@@ -8,6 +8,12 @@ module Cfdi40
8
8
  pagos.add_pago(attributes)
9
9
  end
10
10
 
11
+ def pago_nodes
12
+ return [] unless defined?(@pagos)
13
+
14
+ pagos.pago_nodes
15
+ end
16
+
11
17
  def pagos
12
18
  return @pagos if defined?(@pagos)
13
19
 
@@ -191,6 +191,13 @@ module Cfdi40
191
191
  complemento.add_pago(attributes)
192
192
  end
193
193
 
194
+ def remove_pago(index)
195
+ return unless defined?(@complemento)
196
+ return if complemento.pagos.pago_nodes.empty?
197
+
198
+ complemento.pagos.remove_pago(index.to_i)
199
+ end
200
+
194
201
  def to_s
195
202
  to_xml
196
203
  end
@@ -248,6 +255,12 @@ module Cfdi40
248
255
  @conceptos.children_nodes
249
256
  end
250
257
 
258
+ def pago_nodes
259
+ return [] unless defined?(@complemento)
260
+
261
+ complemento.pago_nodes
262
+ end
263
+
251
264
  def total_iva_node
252
265
  # TODO: Puede haber más de un nodo, cuando hay varias tasas de iva
253
266
  return nil unless impuestos_node
@@ -12,7 +12,7 @@ module Cfdi40
12
12
  define_attribute :cantidad, xml_attribute: "Cantidad", default: 1, format: :decimal
13
13
  define_attribute :clave_unidad, xml_attribute: "ClaveUnidad"
14
14
  define_attribute :unidad, xml_attribute: "Unidad"
15
- define_attribute :descripcion, xml_attribute: "Descripcion"
15
+ define_attribute :descripcion, xml_attribute: "Descripcion", no_writer: true
16
16
  define_attribute :valor_unitario, xml_attribute: "ValorUnitario", format: :t_Importe
17
17
  define_attribute :importe, xml_attribute: "Importe", format: :t_Importe
18
18
  define_attribute :descuento, xml_attribute: "Descuento", format: :t_Importe
data/lib/cfdi40/node.rb CHANGED
@@ -33,10 +33,11 @@ module Cfdi40
33
33
  @@element_names ||= {}
34
34
  end
35
35
 
36
- def self.define_attribute(accessor, xml_attribute:, default: nil, format: nil, readonly: false)
36
+ # +no_writer+ option implies that the writer methos must be defined in the child class.
37
+ def self.define_attribute(accessor, xml_attribute:, default: nil, format: nil, readonly: false, no_writer: nil)
37
38
  verify_class_variables
38
39
  define_reader(accessor, format)
39
- define_writer(accessor, readonly, format)
40
+ define_writer(accessor, readonly, format) unless no_writer
40
41
 
41
42
  @@attributes[name][accessor.to_sym] = xml_attribute
42
43
  @@default_values[name][accessor.to_sym] = default if default
@@ -163,6 +164,12 @@ module Cfdi40
163
164
  @children_nodes << child_node
164
165
  end
165
166
 
167
+ def delete_child(child_node)
168
+ raise Error, "child_node must be a Node object" unless child_node.is_a?(Node)
169
+
170
+ @children_nodes.delete(child_node)
171
+ end
172
+
166
173
  # Locks for readonly this node and children
167
174
  def lock
168
175
  @readonly = true
data/lib/cfdi40/pago.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # /cfdi:Comprobante/cfdi:Complemento/pago20:Pagos/pago20:Pago
4
4
  module Cfdi40
5
5
  class Pago < Node
6
- define_attribute :monto, xml_attribute: "Monto", format: :t_Importe
6
+ define_attribute :monto, xml_attribute: "Monto", format: :t_ImporteMXN
7
7
  define_attribute :fecha_pago, xml_attribute: "FechaPago", format: :t_FechaH
8
8
  define_attribute :forma_pago, xml_attribute: "FormaDePagoP"
9
9
  define_attribute :moneda, xml_attribute: "MonedaP", readonly: true, default: "MXN"
data/lib/cfdi40/pagos.rb CHANGED
@@ -27,6 +27,12 @@ module Cfdi40
27
27
  true
28
28
  end
29
29
 
30
+ def remove_pago(index)
31
+ @children_nodes.delete(pago_nodes[index])
32
+ update_totales
33
+ true
34
+ end
35
+
30
36
  def update_totales
31
37
  update_totales_traslado_iva16
32
38
  update_total_monto
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cfdi40
4
- VERSION = "0.3.2"
4
+ VERSION = "0.4.1"
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.3.2
4
+ version: 0.4.1
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-10-27 00:00:00.000000000 Z
11
+ date: 2025-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri