afipws 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +102 -0
- data/.travis.yml +1 -0
- data/Gemfile.lock +22 -4
- data/LICENSE.txt +22 -0
- data/README.md +11 -5
- data/afipws.gemspec +1 -0
- data/lib/afipws.rb +2 -0
- data/lib/afipws/client.rb +4 -17
- data/lib/afipws/core_ext/hash.rb +2 -2
- data/lib/afipws/excepciones.rb +1 -1
- data/lib/afipws/type_conversions.rb +19 -16
- data/lib/afipws/version.rb +1 -1
- data/lib/afipws/ws_base.rb +12 -0
- data/lib/afipws/ws_constancia_inscripcion.rb +33 -0
- data/lib/afipws/wsaa.rb +9 -13
- data/lib/afipws/{wsfev1.wsdl → wsdl/wsfev1.wsdl} +1371 -1371
- data/lib/afipws/wsfe.rb +57 -38
- data/spec/afipws/core_ext/hash_spec.rb +6 -6
- data/spec/afipws/type_conversions_spec.rb +11 -12
- data/spec/afipws/ws_constancia_inscripcion_spec.rb +65 -0
- data/spec/afipws/wsaa_spec.rb +66 -58
- data/spec/afipws/wsfe_spec.rb +272 -259
- data/spec/fixtures/constancia_inscripcion_dummy/success.xml +11 -0
- data/spec/fixtures/constancia_inscripcion_get_persona/failure.xml +35 -0
- data/spec/fixtures/constancia_inscripcion_get_persona/success.xml +53 -0
- data/spec/fixtures/ws_constancia_inscripcion.wsdl +230 -0
- metadata +31 -5
- data/.autotest +0 -2
- data/autotest/discover.rb +0 -1
data/spec/afipws/wsfe_spec.rb
CHANGED
@@ -1,312 +1,325 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
savon.expects(:fe_param_get_tipos_cbte).with(message: auth).returns(fixture('fe_param_get_tipos_cbte/success'))
|
15
|
-
ws.tipos_comprobantes.should == [
|
16
|
-
{ id: 1, desc: "Factura A", fch_desde: Date.new(2010,9,17), fch_hasta: nil },
|
17
|
-
{ id: 2, desc: "Nota de Débito A", fch_desde: Date.new(2010,9,18), fch_hasta: Date.new(2011,9,18) }]
|
18
|
-
end
|
19
|
-
|
20
|
-
it "tipos_documentos" do
|
21
|
-
savon.expects(:fe_param_get_tipos_doc).with(message: auth).returns(fixture('fe_param_get_tipos_doc/success'))
|
22
|
-
ws.tipos_documentos.should == [{ id: 80, desc: "CUIT", fch_desde: Date.new(2008,7,25), fch_hasta: nil }]
|
23
|
-
end
|
3
|
+
module Afipws
|
4
|
+
describe WSFE do
|
5
|
+
let(:ta) { {token: 't', sign: 's'} }
|
6
|
+
let(:ws) { WSFE.new(cuit: '1').tap { |ws| ws.wsaa.stubs auth: ta } }
|
7
|
+
let(:auth) { {auth: ta.merge(cuit: '1')} }
|
8
|
+
|
9
|
+
context 'métodos de negocio' do
|
10
|
+
it 'dummy' do
|
11
|
+
savon.expects(:fe_dummy).returns(fixture('fe_dummy/success'))
|
12
|
+
ws.dummy.should == { app_server: 'OK', db_server: 'OK', auth_server: 'OK' }
|
13
|
+
end
|
24
14
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
it 'tipos_comprobantes' do
|
16
|
+
savon.expects(:fe_param_get_tipos_cbte).with(message: auth).returns(fixture('fe_param_get_tipos_cbte/success'))
|
17
|
+
ws.tipos_comprobantes.should == [
|
18
|
+
{ id: 1, desc: 'Factura A', fch_desde: Date.new(2010, 9, 17), fch_hasta: nil },
|
19
|
+
{ id: 2, desc: 'Nota de Débito A', fch_desde: Date.new(2010, 9, 18), fch_hasta: Date.new(2011, 9, 18) }
|
20
|
+
]
|
21
|
+
end
|
31
22
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
it 'tipos_documentos' do
|
24
|
+
savon.expects(:fe_param_get_tipos_doc).with(message: auth).returns(fixture('fe_param_get_tipos_doc/success'))
|
25
|
+
ws.tipos_documentos.should == [{ id: 80, desc: 'CUIT', fch_desde: Date.new(2008, 7, 25), fch_hasta: nil }]
|
26
|
+
end
|
36
27
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
it 'tipos_monedas' do
|
29
|
+
savon.expects(:fe_param_get_tipos_monedas).with(message: auth).returns(fixture('fe_param_get_tipos_monedas/success'))
|
30
|
+
ws.tipos_monedas.should == [
|
31
|
+
{ id: 'PES', desc: 'Pesos Argentinos', fch_desde: Date.new(2009, 4, 3), fch_hasta: nil },
|
32
|
+
{ id: '002', desc: 'Dólar Libre EEUU', fch_desde: Date.new(2009, 4, 16), fch_hasta: nil }
|
33
|
+
]
|
34
|
+
end
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
{ nro: 2, emision_tipo: "CAEA", bloqueado: true, fch_baja: Date.new(2011,1,31) }]
|
47
|
-
end
|
36
|
+
it 'tipos_iva' do
|
37
|
+
savon.expects(:fe_param_get_tipos_iva).with(message: auth).returns(fixture('fe_param_get_tipos_iva/success'))
|
38
|
+
ws.tipos_iva.should == [{ id: 5, desc: '21%', fch_desde: Date.new(2009, 2, 20), fch_hasta: nil }]
|
39
|
+
end
|
48
40
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
ws.cotizacion('DOL').should == 3.976
|
41
|
+
it 'tipos_tributos' do
|
42
|
+
savon.expects(:fe_param_get_tipos_tributos).with(message: auth).returns(fixture('fe_param_get_tipos_tributos/success'))
|
43
|
+
ws.tipos_tributos.should == [{ id: 2, desc: 'Impuestos provinciales', fch_desde: Date.new(2010, 9, 17), fch_hasta: nil }]
|
53
44
|
end
|
54
45
|
|
55
|
-
it
|
56
|
-
savon.expects(:
|
57
|
-
|
46
|
+
it 'puntos_venta' do
|
47
|
+
savon.expects(:fe_param_get_ptos_venta).with(message: auth).returns(fixture('fe_param_get_ptos_venta/success'))
|
48
|
+
ws.puntos_venta.should == [
|
49
|
+
{ nro: 1, emision_tipo: 'CAE', bloqueado: false, fch_baja: nil },
|
50
|
+
{ nro: 2, emision_tipo: 'CAEA', bloqueado: true, fch_baja: Date.new(2011, 1, 31) }
|
51
|
+
]
|
58
52
|
end
|
59
|
-
end
|
60
53
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
context 'cotizacion' do
|
55
|
+
it 'cuando la moneda solicitada existe' do
|
56
|
+
savon.expects(:fe_param_get_cotizacion).with(message: auth.merge(mon_id: 'DOL')).returns(fixture('fe_param_get_cotizacion/dolar'))
|
57
|
+
ws.cotizacion('DOL').should == 3.976
|
58
|
+
end
|
65
59
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
'//FeCAEReq/FeCabReq/CantReg' => 1,
|
71
|
-
'//FeCAEReq/FeCabReq/PtoVta' => 2,
|
72
|
-
'//FeCAEReq/FeCabReq/CbteTipo' => 1,
|
73
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/DocTipo' => 80,
|
74
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/DocNro' => 30521189203,
|
75
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/CbteFch' => 20110113,
|
76
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/ImpTotal' => 1270.48,
|
77
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/ImpIVA' => 220.5,
|
78
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[1]/Id' => 5,
|
79
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[1]/Importe' => 220.5,
|
80
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/Id' => 0,
|
81
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/BaseImp' => 150,
|
82
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/Alic' => 5.2,
|
83
|
-
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/Importe' => 7.8
|
84
|
-
)).returns(fixture('fecae_solicitar/autorizacion_1_cbte'))
|
85
|
-
rta = ws.autorizar_comprobantes(cbte_tipo: 1, pto_vta: 2, comprobantes: [{cbte_nro: 1, concepto: 1,
|
86
|
-
doc_nro: 30521189203, doc_tipo: 80, cbte_fch: Date.new(2011,01,13),
|
87
|
-
imp_total: 1270.48, imp_neto: 1049.98, imp_iva: 220.50, mon_id: 'PES', mon_cotiz: 1,
|
88
|
-
iva: { alic_iva: [{ id: 5, base_imp: 1049.98, importe: 220.50 }]},
|
89
|
-
tributos: { tributo: [{ id: 0, base_imp: 150, alic: 5.2, importe: 7.8 }] }
|
90
|
-
}])
|
91
|
-
rta[0].should have_entries cae: '61023008595705', cae_fch_vto: Date.new(2011,01,23), cbte_nro: 1,
|
92
|
-
resultado: 'A', observaciones: []
|
93
|
-
rta.size.should == 1
|
60
|
+
it 'cuando la moneda no existe' do
|
61
|
+
savon.expects(:fe_param_get_cotizacion).with(message: auth.merge(mon_id: 'PES')).returns(fixture('fe_param_get_cotizacion/inexistente'))
|
62
|
+
-> { ws.cotizacion('PES') }.should raise_error WSError, /602: Sin Resultados/
|
63
|
+
end
|
94
64
|
end
|
95
65
|
|
96
|
-
it
|
97
|
-
savon.expects(:
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
66
|
+
it 'cant_max_registros_x_lote' do
|
67
|
+
savon.expects(:fe_comp_tot_x_request).with(message: auth).returns(fixture('fe_comp_tot_x_request/success'))
|
68
|
+
ws.cant_max_registros_x_lote.should == 250
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'autorizar_comprobante' do
|
72
|
+
it 'debería devolver un hash con el CAE y su fecha de vencimiento' do
|
73
|
+
savon.expects(:fecae_solicitar).with(message: has_path(
|
74
|
+
'//Auth/Token' => 't',
|
75
|
+
'//FeCAEReq/FeCabReq/CantReg' => 1,
|
76
|
+
'//FeCAEReq/FeCabReq/PtoVta' => 2,
|
77
|
+
'//FeCAEReq/FeCabReq/CbteTipo' => 1,
|
78
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/DocTipo' => 80,
|
79
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/DocNro' => 30_521_189_203,
|
80
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/CbteFch' => 20_110_113,
|
81
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/ImpTotal' => 1270.48,
|
82
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/ImpIVA' => 220.5,
|
83
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[1]/Id' => 5,
|
84
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[1]/Importe' => 220.5,
|
85
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/Id' => 0,
|
86
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/BaseImp' => 150,
|
87
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/Alic' => 5.2,
|
88
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Tributos/Tributo[1]/Importe' => 7.8
|
89
|
+
)).returns(fixture('fecae_solicitar/autorizacion_1_cbte'))
|
90
|
+
rta = ws.autorizar_comprobantes(cbte_tipo: 1, pto_vta: 2, comprobantes: [
|
91
|
+
{
|
92
|
+
cbte_nro: 1, concepto: 1, doc_nro: 30_521_189_203, doc_tipo: 80, cbte_fch: Date.new(2011, 0o1, 13),
|
93
|
+
imp_total: 1270.48, imp_neto: 1049.98, imp_iva: 220.50, mon_id: 'PES', mon_cotiz: 1,
|
94
|
+
iva: { alic_iva: [{ id: 5, base_imp: 1049.98, importe: 220.50 }]},
|
95
|
+
tributos: { tributo: [{ id: 0, base_imp: 150, alic: 5.2, importe: 7.8 }] }
|
96
|
+
}
|
97
|
+
])
|
98
|
+
rta[0].should have_entries cae: '61023008595705', cae_fch_vto: Date.new(2011, 0o1, 23), cbte_nro: 1,
|
99
|
+
resultado: 'A', observaciones: []
|
100
|
+
rta.size.should == 1
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'con varias alicuotas iva' do
|
104
|
+
savon.expects(:fecae_solicitar).with(message: has_path(
|
105
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[1]/Id' => 5,
|
106
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[1]/Importe' => 21,
|
107
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[2]/Id' => 4,
|
108
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/Iva/AlicIva[2]/Importe' => 5.25
|
109
|
+
)).returns(fixture('fecae_solicitar/autorizacion_1_cbte'))
|
110
|
+
ws.autorizar_comprobantes(cbte_tipo: 1, pto_vta: 2, comprobantes: [{iva: {alic_iva: [
|
104
111
|
{ id: 5, base_imp: 100, importe: 21 },
|
105
112
|
{ id: 4, base_imp: 50, importe: 5.25 }
|
106
|
-
|
107
|
-
|
113
|
+
]}}])
|
114
|
+
end
|
108
115
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
it 'con varios comprobantes aprobados' do
|
117
|
+
savon.expects(:fecae_solicitar).with(message: has_path(
|
118
|
+
'//FeCAEReq/FeCabReq/CantReg' => 2,
|
119
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/CbteDesde' => 5,
|
120
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[1]/CbteHasta' => 5,
|
121
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[2]/CbteDesde' => 6,
|
122
|
+
'//FeCAEReq/FeDetReq/FECAEDetRequest[2]/CbteHasta' => 6
|
123
|
+
)).returns(fixture('fecae_solicitar/autorizacion_2_cbtes'))
|
124
|
+
rta = ws.autorizar_comprobantes(cbte_tipo: 1, pto_vta: 2, comprobantes: [{ cbte_nro: 5 }, { cbte_nro: 6 }])
|
125
|
+
rta[0].should have_entries cbte_nro: 5, cae: '61033008894096'
|
126
|
+
rta[1].should have_entries cbte_nro: 6, cae: '61033008894101'
|
127
|
+
end
|
121
128
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
129
|
+
it 'con 2 observaciones' do
|
130
|
+
savon.expects(:fecae_solicitar).with(message: :any).returns(fixture('fecae_solicitar/dos_observaciones'))
|
131
|
+
rta = ws.autorizar_comprobantes comprobantes: []
|
132
|
+
rta[0].should have_entries cbte_nro: 3, cae: nil, resultado: 'R', observaciones: [
|
133
|
+
{code: 10_048, msg: 'Msg 1'}, {code: 10_018, msg: 'Msg 2'}
|
134
|
+
]
|
135
|
+
end
|
128
136
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
137
|
+
it 'con 1 observación' do
|
138
|
+
savon.expects(:fecae_solicitar).with(message: :any).returns(fixture('fecae_solicitar/una_observacion'))
|
139
|
+
rta = ws.autorizar_comprobantes comprobantes: []
|
140
|
+
rta[0].should have_entries observaciones: [{code: 10_048, msg: 'Msg 1'}]
|
141
|
+
end
|
133
142
|
end
|
134
|
-
end
|
135
143
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
144
|
+
context 'solicitar_caea' do
|
145
|
+
it 'debería mandar automáticamente el período y orden' do
|
146
|
+
Date.stubs today: Date.new(2011, 1, 27)
|
147
|
+
savon.expects(:fecaea_solicitar).with(message: has_path('//Periodo' => '201102', '//Orden' => 1)).returns(fixture('fecaea_solicitar/success'))
|
148
|
+
ws.solicitar_caea.should have_entries caea: '21043476341977', fch_tope_inf: Date.new(2011, 0o3, 17),
|
149
|
+
fch_vig_desde: Date.new(2011, 0o2, 0o1), fch_vig_hasta: Date.new(2011, 0o2, 15)
|
150
|
+
end
|
143
151
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
152
|
+
context 'periodo_para_solicitud_caea' do
|
153
|
+
it 'cuando estoy en la primer quincena' do
|
154
|
+
Date.stubs today: Date.new(2011, 1, 12)
|
155
|
+
ws.periodo_para_solicitud_caea.should == { periodo: '201101', orden: 2 }
|
156
|
+
Date.stubs today: Date.new(2011, 1, 15)
|
157
|
+
ws.periodo_para_solicitud_caea.should == { periodo: '201101', orden: 2 }
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'cuando estoy en la segunda quincena' do
|
161
|
+
Date.stubs today: Date.new(2011, 1, 16)
|
162
|
+
ws.periodo_para_solicitud_caea.should == { periodo: '201102', orden: 1 }
|
163
|
+
Date.stubs today: Date.new(2011, 1, 31)
|
164
|
+
ws.periodo_para_solicitud_caea.should == { periodo: '201102', orden: 1 }
|
165
|
+
end
|
150
166
|
end
|
151
167
|
|
152
|
-
it
|
153
|
-
Date.stubs today: Date.new(2011,1,
|
154
|
-
|
155
|
-
|
156
|
-
|
168
|
+
it 'cuando el caea ya fue otorgado debería consultarlo y devolverlo' do
|
169
|
+
Date.stubs today: Date.new(2011, 1, 27)
|
170
|
+
savon.expects(:fecaea_solicitar)
|
171
|
+
.with(message: has_path('//Periodo' => '201102', '//Orden' => 1))
|
172
|
+
.returns(fixture('fecaea_solicitar/caea_ya_otorgado'))
|
173
|
+
savon.expects(:fecaea_consultar)
|
174
|
+
.with(message: has_path('//Periodo' => '201102', '//Orden' => 1))
|
175
|
+
.returns(fixture('fecaea_consultar/success'))
|
176
|
+
ws.solicitar_caea.should have_entries caea: '21043476341977', fch_vig_desde: Date.new(2011, 0o2, 0o1)
|
157
177
|
end
|
158
|
-
end
|
159
178
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
ws.solicitar_caea.should have_entries caea: '21043476341977', fch_vig_desde: Date.new(2011,02,01)
|
179
|
+
it 'cuando hay otro error debería burbujearlo' do
|
180
|
+
savon.expects(:fecaea_solicitar).with(message: :any).returns(fixture('fecaea_solicitar/error_distinto'))
|
181
|
+
-> { ws.solicitar_caea }.should raise_error WSError, /15007/
|
182
|
+
end
|
165
183
|
end
|
166
184
|
|
167
|
-
it
|
168
|
-
savon.expects(:
|
169
|
-
|
185
|
+
it 'informar_comprobantes_caea' do
|
186
|
+
savon.expects(:fecaea_reg_informativo).with(message: has_path(
|
187
|
+
'//Auth/Token' => 't',
|
188
|
+
'//FeCAEARegInfReq/FeCabReq/CantReg' => 2,
|
189
|
+
'//FeCAEARegInfReq/FeCabReq/PtoVta' => 3,
|
190
|
+
'//FeCAEARegInfReq/FeCabReq/CbteTipo' => 1,
|
191
|
+
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[1]/CbteDesde' => 1,
|
192
|
+
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[1]/CbteHasta' => 1,
|
193
|
+
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[1]/CAEA' => '21043476341977',
|
194
|
+
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[2]/CbteDesde' => 2,
|
195
|
+
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[2]/CbteHasta' => 2,
|
196
|
+
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[2]/CAEA' => '21043476341977'
|
197
|
+
)).returns(fixture('fecaea_reg_informativo/informe_rtdo_parcial'))
|
198
|
+
rta = ws.informar_comprobantes_caea(cbte_tipo: 1, pto_vta: 3, comprobantes: [
|
199
|
+
{ cbte_nro: 1, caea: '21043476341977' }, { cbte_nro: 2, caea: '21043476341977' }
|
200
|
+
])
|
201
|
+
rta[0].should have_entries cbte_nro: 1, caea: '21043476341977', resultado: 'A', observaciones: []
|
202
|
+
rta[1].should have_entries cbte_nro: 2, caea: '21043476341977', resultado: 'R', observaciones: [{code: 724, msg: 'Msg'}]
|
170
203
|
end
|
171
|
-
end
|
172
|
-
|
173
|
-
it "informar_comprobantes_caea" do
|
174
|
-
savon.expects(:fecaea_reg_informativo).with(message: has_path(
|
175
|
-
'//Auth/Token' => 't',
|
176
|
-
'//FeCAEARegInfReq/FeCabReq/CantReg' => 2,
|
177
|
-
'//FeCAEARegInfReq/FeCabReq/PtoVta' => 3,
|
178
|
-
'//FeCAEARegInfReq/FeCabReq/CbteTipo' => 1,
|
179
|
-
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[1]/CbteDesde' => 1,
|
180
|
-
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[1]/CbteHasta' => 1,
|
181
|
-
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[1]/CAEA' => '21043476341977',
|
182
|
-
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[2]/CbteDesde' => 2,
|
183
|
-
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[2]/CbteHasta' => 2,
|
184
|
-
'//FeCAEARegInfReq/FeDetReq/FECAEADetRequest[2]/CAEA' => '21043476341977',
|
185
|
-
)).returns(fixture 'fecaea_reg_informativo/informe_rtdo_parcial')
|
186
|
-
rta = ws.informar_comprobantes_caea(cbte_tipo: 1, pto_vta: 3, comprobantes: [
|
187
|
-
{ cbte_nro: 1, caea: '21043476341977' }, { cbte_nro: 2, caea: '21043476341977' },
|
188
|
-
])
|
189
|
-
rta[0].should have_entries cbte_nro: 1, caea: '21043476341977', resultado: 'A', observaciones: []
|
190
|
-
rta[1].should have_entries cbte_nro: 2, caea: '21043476341977', resultado: 'R', observaciones: [{code: 724, msg: 'Msg'}]
|
191
|
-
end
|
192
204
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
205
|
+
it 'informar_caea_sin_movimientos' do
|
206
|
+
savon.expects(:fecaea_sin_movimiento_informar).with(message: has_path(
|
207
|
+
'//Auth/Token' => 't',
|
208
|
+
'//PtoVta' => 4,
|
209
|
+
'//CAEA' => '21043476341977'
|
210
|
+
)).returns(fixture('fecaea_sin_movimiento_informar/success'))
|
211
|
+
rta = ws.informar_caea_sin_movimientos('21043476341977', 4)
|
212
|
+
rta.should have_entries caea: '21043476341977', resultado: 'A'
|
213
|
+
end
|
202
214
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
215
|
+
context 'consultar_caea' do
|
216
|
+
it 'consultar_caea' do
|
217
|
+
savon.expects(:fecaea_consultar).with(message: has_path('//Periodo' => '201101', '//Orden' => 1)).returns(fixture('fecaea_consultar/success'))
|
218
|
+
ws.consultar_caea(Date.new(2011, 1, 1)).should have_entries caea: '21043476341977', fch_tope_inf: Date.new(2011, 0o3, 17)
|
219
|
+
end
|
207
220
|
end
|
208
|
-
end
|
209
221
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
222
|
+
it 'ultimo_comprobante_autorizado' do
|
223
|
+
savon.expects(:fe_comp_ultimo_autorizado).with(message: has_path('//PtoVta' => 1, '//CbteTipo' => 1)).returns(fixture('fe_comp_ultimo_autorizado/success'))
|
224
|
+
ws.ultimo_comprobante_autorizado(pto_vta: 1, cbte_tipo: 1).should == 20
|
225
|
+
end
|
214
226
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
227
|
+
it 'consultar_comprobante' do
|
228
|
+
savon.expects(:fe_comp_consultar).with(message: has_path(
|
229
|
+
'//Auth/Token' => 't', '//FeCompConsReq/PtoVta' => 1, '//FeCompConsReq/CbteTipo' => 2, '//FeCompConsReq/CbteNro' => 3
|
230
|
+
)).returns(fixture('fe_comp_consultar/success'))
|
231
|
+
rta = ws.consultar_comprobante(pto_vta: 1, cbte_tipo: 2, cbte_nro: 3)
|
232
|
+
rta[:cod_autorizacion].should == '61023008595705'
|
233
|
+
rta[:emision_tipo].should == 'CAE'
|
234
|
+
end
|
222
235
|
end
|
223
|
-
end
|
224
236
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
237
|
+
context 'autenticacion' do
|
238
|
+
before { FileUtils.rm_rf Dir.glob('tmp/*ta.dump') }
|
239
|
+
|
240
|
+
it 'debería autenticarse usando el WSAA' do
|
241
|
+
wsfe = WSFE.new cuit: '1', cert: 'cert', key: 'key'
|
242
|
+
wsfe.wsaa.cert.should == 'cert'
|
243
|
+
wsfe.wsaa.key.should == 'key'
|
244
|
+
wsfe.wsaa.service.should == 'wsfe'
|
245
|
+
wsfe.wsaa.expects(:login).returns(token: 't', sign: 's')
|
246
|
+
savon.expects(:fe_param_get_tipos_cbte).with(message: has_path(
|
247
|
+
'//Auth/Token' => 't', '//Auth/Sign' => 's', '//Auth/Cuit' => '1'
|
248
|
+
)).returns(fixture('fe_param_get_tipos_cbte/success'))
|
249
|
+
wsfe.tipos_comprobantes
|
250
|
+
end
|
238
251
|
end
|
239
|
-
end
|
240
252
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
253
|
+
context 'entorno' do
|
254
|
+
it 'debería usar las url para development cuando el env es development' do
|
255
|
+
Client.expects(:new).with(wsdl: 'https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl')
|
256
|
+
Client.expects(:new).with(wsdl: 'https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL', convert_request_keys_to: :camelcase)
|
257
|
+
wsfe = WSFE.new env: :development
|
258
|
+
wsfe.env.should == :development
|
259
|
+
end
|
248
260
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
261
|
+
it 'debería usar las url para production cuando el env es production' do
|
262
|
+
Client.expects(:new).with(wsdl: 'https://wsaa.afip.gov.ar/ws/services/LoginCms?wsdl')
|
263
|
+
Client.expects(:new).with(has_entries(wsdl: File.expand_path(__dir__ + '/../../') + '/lib/afipws/wsdl/wsfev1.wsdl'))
|
264
|
+
wsfe = WSFE.new env: 'production'
|
265
|
+
wsfe.env.should == :production
|
266
|
+
end
|
254
267
|
end
|
255
|
-
end
|
256
268
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
269
|
+
context 'manejo de errores' do
|
270
|
+
it 'cuando hay un error' do
|
271
|
+
savon.expects(:fe_param_get_tipos_cbte).with(message: :any).returns(fixture('fe_param_get_tipos_cbte/failure_1_error'))
|
272
|
+
-> { ws.tipos_comprobantes }.should raise_error { |e|
|
273
|
+
e.should be_a WSError
|
274
|
+
e.errors.should == [{ code: '600', msg: 'No se corresponden token con firma' }]
|
275
|
+
e.message.should == '600: No se corresponden token con firma'
|
276
|
+
}
|
277
|
+
end
|
266
278
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
279
|
+
it 'cuando hay varios errores' do
|
280
|
+
savon.expects(:fe_param_get_tipos_cbte).with(message: :any).returns(fixture('fe_param_get_tipos_cbte/failure_2_errors'))
|
281
|
+
-> { ws.tipos_comprobantes }.should raise_error { |e|
|
282
|
+
e.should be_a WSError
|
283
|
+
e.errors.should == [{ code: '600', msg: 'No se corresponden token con firma' }, { code: '601', msg: 'CUIT representada no incluida en token' }]
|
284
|
+
e.message.should == '600: No se corresponden token con firma; 601: CUIT representada no incluida en token'
|
285
|
+
}
|
286
|
+
end
|
274
287
|
end
|
275
|
-
end
|
276
288
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
289
|
+
context 'cálculo de fechas y períodos' do
|
290
|
+
it 'periodo_para_consulta_caea' do
|
291
|
+
ws.periodo_para_consulta_caea(Date.new(2011, 1, 1)).should == { periodo: '201101', orden: 1 }
|
292
|
+
ws.periodo_para_consulta_caea(Date.new(2011, 1, 15)).should == { periodo: '201101', orden: 1 }
|
293
|
+
ws.periodo_para_consulta_caea(Date.new(2011, 1, 16)).should == { periodo: '201101', orden: 2 }
|
294
|
+
ws.periodo_para_consulta_caea(Date.new(2011, 1, 31)).should == { periodo: '201101', orden: 2 }
|
295
|
+
ws.periodo_para_consulta_caea(Date.new(2011, 2, 2)).should == { periodo: '201102', orden: 1 }
|
296
|
+
end
|
285
297
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
298
|
+
it 'fecha_inicio_quincena_siguiente' do
|
299
|
+
fecha_inicio_quincena_siguiente(Date.new(2010, 1, 1)).should == Date.new(2010, 1, 16)
|
300
|
+
fecha_inicio_quincena_siguiente(Date.new(2010, 1, 10)).should == Date.new(2010, 1, 16)
|
301
|
+
fecha_inicio_quincena_siguiente(Date.new(2010, 1, 15)).should == Date.new(2010, 1, 16)
|
290
302
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
303
|
+
fecha_inicio_quincena_siguiente(Date.new(2010, 1, 16)).should == Date.new(2010, 2, 1)
|
304
|
+
fecha_inicio_quincena_siguiente(Date.new(2010, 1, 20)).should == Date.new(2010, 2, 1)
|
305
|
+
fecha_inicio_quincena_siguiente(Date.new(2010, 1, 31)).should == Date.new(2010, 2, 1)
|
306
|
+
fecha_inicio_quincena_siguiente(Date.new(2010, 12, 31)).should == Date.new(2011, 1, 1)
|
307
|
+
end
|
296
308
|
|
297
|
-
|
298
|
-
|
299
|
-
|
309
|
+
def fecha_inicio_quincena_siguiente fecha
|
310
|
+
Date.stubs(today: fecha)
|
311
|
+
subject.fecha_inicio_quincena_siguiente
|
312
|
+
end
|
300
313
|
end
|
301
|
-
end
|
302
314
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
315
|
+
context 'comprobante_to_request' do
|
316
|
+
def c2r comprobante
|
317
|
+
subject.comprobante_to_request comprobante
|
318
|
+
end
|
307
319
|
|
308
|
-
|
309
|
-
|
320
|
+
it 'no debería enviar tag tributos si el impTrib es 0' do
|
321
|
+
c2r(imp_trib: 0.0, tributos: { tributo: [] }).should_not have_key :tributos
|
322
|
+
end
|
310
323
|
end
|
311
324
|
end
|
312
325
|
end
|