cfdi40 0.4.1 → 0.4.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: 0640bebb04d18652cf33f6dbd3f21a1628bb0df9602f9c4644d89a52da9a8604
4
- data.tar.gz: ca5d8c18c35dc547f7321089c6e932bea09a8304bc02d7604ee1b042de7440f0
3
+ metadata.gz: 6fb15d8d4d0e081acf97f51f3b7d42709a3c0f0e2dc11772a7104cad40b9ca42
4
+ data.tar.gz: 7c01a9c38907d5728070828a220f3c7d4168b76658f4e5f44efcef428870b7df
5
5
  SHA512:
6
- metadata.gz: 6bdf05c00a3161967b2c053896a3d8575a2d9a0c519980fd3b22e28ba33751cc1a312f8d8944dc34a2183012e3f58468704657c904247691d2bb2ff123f3723d
7
- data.tar.gz: 26e267b91dec8b0ebcd41cf7c9fc09951bcbda73610a97375b9536ef605e2c0e8c70d52e010257aefe6260a696f037f2365092c240bd71823f28d57b59c44c12
6
+ metadata.gz: 53d81cf68988fdaf98557009fb7b90dd24e996d6e313c5cf432ea49c7fe6f3d3cec6cb8129300508ffab6b7c0f42a081c144f0df2e0643482182074061702af7
7
+ data.tar.gz: 88f608a836522680e4540744ae111957f98db192b4dcbc28f3d271fbfe9be6a1b0b30f996ba2ca49bd8dbcc732a81bfdefe42ba6a3bee3bb2729b77b29b8f891
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cfdi40 (0.4.1)
4
+ cfdi40 (0.4.2)
5
5
  nokogiri (>= 1.10.10)
6
6
 
7
7
  GEM
@@ -8,6 +8,11 @@ module Cfdi40
8
8
  pagos.add_pago(attributes)
9
9
  end
10
10
 
11
+ def add_splitted_pago(attributes = {})
12
+ pagos.totales_node
13
+ pagos.add_splitted_pago(attributes)
14
+ end
15
+
11
16
  def pago_nodes
12
17
  return [] unless defined?(@pagos)
13
18
 
@@ -198,6 +198,14 @@ module Cfdi40
198
198
  complemento.pagos.remove_pago(index.to_i)
199
199
  end
200
200
 
201
+ # See test_adding_pago_with_n_docto_relacionados in file test/test_cfdi40_rep.rb
202
+ def add_splitted_pago(attributes = {})
203
+ raise Error, "CFDi debe ser tipo 'P'" unless tipo_de_comprobante == "P"
204
+
205
+ add_node_concepto_actividad_pago
206
+ complemento.add_splitted_pago(attributes)
207
+ end
208
+
201
209
  def to_s
202
210
  to_xml
203
211
  end
data/lib/cfdi40/pago.rb CHANGED
@@ -14,15 +14,15 @@ module Cfdi40
14
14
  # Generate docto_relacionado node
15
15
  # Data for dcto_relacionado node is obtained from de accessors
16
16
  # uuid, serie, folio
17
- def add_docto_relacionado
17
+ def add_docto_relacionado(attributes = {})
18
18
  docto_relacionado = DoctoRelacionado.new
19
19
  docto_relacionado.parent_node = self
20
- docto_relacionado.id_documento = uuid
21
- docto_relacionado.serie = serie
22
- docto_relacionado.folio = folio
23
- docto_relacionado.num_parcialidad = num_parcialidad
24
- docto_relacionado.imp_saldo_ant = importe_saldo_anterior.round(2)
25
- docto_relacionado.imp_pagado = monto
20
+ docto_relacionado.id_documento = attributes[:uuid]
21
+ docto_relacionado.serie = attributes[:serie]
22
+ docto_relacionado.folio = attributes[:folio]
23
+ docto_relacionado.num_parcialidad = attributes[:num_parcialidad]
24
+ docto_relacionado.imp_saldo_ant = attributes[:importe_saldo_anterior].round(2)
25
+ docto_relacionado.imp_pagado = attributes[:imp_pagado]
26
26
  docto_relacionado.calculate!
27
27
  @children_nodes << docto_relacionado
28
28
  end
data/lib/cfdi40/pagos.rb CHANGED
@@ -13,18 +13,41 @@ module Cfdi40
13
13
  def add_pago(attributes = {})
14
14
  pago = Pago.new
15
15
  pago.parent_node = self
16
+ attributes_doc_rel = { imp_pagado: attributes[:monto] }
17
+ doc_rel_keys = [:uuid, :serie, :folio, :num_parcialidad, :importe_saldo_anterior, :objeto_impuestos]
18
+ attributes.each do |key, value|
19
+ if doc_rel_keys.include?(key)
20
+ attributes_doc_rel[key] = value
21
+ else
22
+ method_name = "#{key}=".to_sym
23
+ raise Error, ":#{key} no se puede asignar al nodo Pago" unless pago.respond_to?(method_name)
24
+
25
+ pago.public_send(method_name, value)
26
+ end
27
+ end
28
+ pago.monto = pago.monto.round(2)
29
+ pago.add_docto_relacionado(attributes_doc_rel)
30
+ pago.add_impuestos_p
31
+ @children_nodes << pago
32
+ update_totales
33
+ true
34
+ end
35
+
36
+ def add_splitted_pago(attributes = {})
37
+ pago = Pago.new
38
+ pago.parent_node = self
39
+ docs = attributes.delete(:docs)
16
40
  attributes.each do |key, value|
17
41
  method_name = "#{key}=".to_sym
18
42
  raise Error, ":#{key} no se puede asignar al nodo Pago" unless pago.respond_to?(method_name)
19
43
 
20
44
  pago.public_send(method_name, value)
21
45
  end
22
- pago.monto = pago.monto.round(2)
23
- pago.add_docto_relacionado
46
+ docs.each { |doc_attributes| pago.add_docto_relacionado(doc_attributes) }
47
+ pago.monto = docs.map { |doc_attributes| doc_attributes[:imp_pagado].to_f }.sum.round(2)
24
48
  pago.add_impuestos_p
25
49
  @children_nodes << pago
26
50
  update_totales
27
- true
28
51
  end
29
52
 
30
53
  def remove_pago(index)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cfdi40
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.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.4.1
4
+ version: 0.4.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-12-03 00:00:00.000000000 Z
11
+ date: 2025-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri