Skip to content

Commit

Permalink
Add support to fm_informacion_cfdi for cfdi 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
lesm committed Nov 2, 2017
1 parent 4c9007c commit fe1fd55
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fm_timbrado_cfdi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "fm_timbrado_cfdi/fm_respuesta3_3"
require "fm_timbrado_cfdi/fm_timbre3_3"
require "fm_timbrado_cfdi/fm_informacion_cfdi"
require "fm_timbrado_cfdi/fm_informacion_cfdi3_3"
require "fm_timbrado_cfdi/fm_cfdi"
require 'nokogiri'
require 'base64'
Expand Down
30 changes: 30 additions & 0 deletions lib/fm_timbrado_cfdi/fm_informacion_cfdi3_3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- encoding : utf-8 -*-
require 'nokogiri'
require 'fm_timbrado_cfdi/fm_cfdi_parser'

module FmTimbradoCfdi
class FmInformacionCfdi3_3 < FmCfdiParser
attr_reader :total, :subtotal, :descuento

private
def atributos
[ 'total',
'subtotal',
'descuento',
]
end

def obtener_total(xml,ns)
xml.xpath("//cfdi:Comprobante",ns).attribute('Total').value rescue nil
end

def obtener_subtotal(xml,ns)
xml.xpath("//cfdi:Comprobante",ns).attribute('SubTotal').value rescue nil
end

def obtener_descuento(xml,ns)
xml.xpath("//cfdi:Comprobante",ns).attribute('Descuento').value rescue nil
end

end
end
17 changes: 17 additions & 0 deletions spec/fm_timbrado_cfdi/fm_informacion_cfdi3_3_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# encoding: utf-8
require 'spec_helper'

describe FmTimbradoCfdi::FmInformacionCfdi do
context "debe crear un objeto válido" do
let(:plantilla){File.open('spec/fixtures/layout_example3_3.txt').read}
let(:layout){ plantilla.gsub('--fecha-comprobante--', 'asignarFecha' )}
let(:respuesta){ FmTimbradoCfdi.timbrar3_3 'ESI920427886', layout }
let(:informacion) { FmTimbradoCfdi::FmInformacionCfdi3_3.new(respuesta.xml)}
it { expect(informacion.total).to_not be_nil }
it { expect(informacion.total).to eq "1943.00" }
it { expect(informacion.subtotal).to_not be_nil }
it { expect(informacion.subtotal).to eq "1850.00" }
it { expect(informacion.descuento).to_not be_nil }
it { expect(informacion.descuento).to eq "175.00" }
end
end

0 comments on commit fe1fd55

Please sign in to comment.