@@ -140,21 +140,30 @@ def _convert_result(result): # pragma: no cover
140
140
'Estado' : 'status' ,
141
141
'Tipo de comprobante' : 'type' ,
142
142
u'Válido hasta' : 'valid_until' ,
143
+ u'Código de Seguridad' : 'security_code' ,
144
+ 'Rnc Emisor' : 'issuing_rnc' ,
145
+ 'Rnc Comprador' : 'buyer_rnc' ,
146
+ 'Monto Total' : 'total' ,
147
+ 'Total de ITBIS' : 'total_itbis' ,
148
+ 'Fecha Emisión' : 'issuing_date' ,
149
+ u'Fecha Emisión' : 'issuing_date' ,
150
+ u'Fecha de Firma' : 'signature_date' ,
151
+ 'e-NCF' : 'ncf' ,
143
152
}
144
153
return dict (
145
154
(translation .get (key , key ), value )
146
155
for key , value in result .items ())
147
156
148
157
149
- def check_dgii (rnc , ncf , timeout = 30 ): # pragma: no cover
158
+ def check_dgii (rnc , ncf , buyer_rnc = None , security_code = None , timeout = 30 ): # pragma: no cover
150
159
"""Validate the RNC, NCF combination on using the DGII online web service.
151
160
152
161
This uses the validation service run by the the Dirección General de
153
162
Impuestos Internos, the Dominican Republic tax department to check
154
163
whether the combination of RNC and NCF is valid. The timeout is in
155
164
seconds.
156
165
157
- Returns a dict with the following structure::
166
+ Returns a dict with the following structure for a NCF ::
158
167
159
168
{
160
169
'name': 'The registered name',
@@ -165,12 +174,29 @@ def check_dgii(rnc, ncf, timeout=30): # pragma: no cover
165
174
'validation_message': 'El NCF digitado es válido.',
166
175
}
167
176
177
+ For an ECNF::
178
+
179
+ {
180
+ 'status': 'Aceptado',
181
+ 'issuing_rnc': '1234567890123',
182
+ 'buyer_rnc': '123456789',
183
+ 'ncf': 'E300000000000',
184
+ 'security_code': '1+2kP3',
185
+ 'issuing_date': '2020-03-25',
186
+ 'signature_date': '2020-03-22',
187
+ 'total': '2203.50',
188
+ 'total_itbis': '305.10',
189
+ 'validation_message': 'Aceptado',
190
+ }
191
+
168
192
Will return None if the number is invalid or unknown."""
169
193
import lxml .html
170
194
import requests
171
195
from stdnum .do .rnc import compact as rnc_compact # noqa: I003
172
196
rnc = rnc_compact (rnc )
173
197
ncf = compact (ncf )
198
+ if buyer_rnc :
199
+ buyer_rnc = rnc_compact (buyer_rnc )
174
200
url = 'https://dgii.gov.do/app/WebApps/ConsultasWeb2/ConsultasWeb/consultas/ncf.aspx'
175
201
session = requests .Session ()
176
202
session .headers .update ({
@@ -188,13 +214,18 @@ def check_dgii(rnc, ncf, timeout=30): # pragma: no cover
188
214
'ctl00$cphMain$txtNCF' : ncf ,
189
215
'ctl00$cphMain$txtRNC' : rnc ,
190
216
}
217
+ if ncf [0 ] == 'E' :
218
+ data ['ctl00$cphMain$txtRncComprador' ] = buyer_rnc
219
+ data ['ctl00$cphMain$txtCodigoSeg' ] = security_code
191
220
# Do the actual request
192
221
document = lxml .html .fromstring (
193
222
session .post (url , data = data , timeout = timeout ).text )
194
- result = document .find ('.//div[@id="cphMain_pResultado"]' )
223
+ result_path = './/div[@id="cphMain_PResultadoFE"]' if ncf [0 ] == 'E' else './/div[@id="cphMain_pResultado"]'
224
+ result = document .find (result_path )
195
225
if result is not None :
226
+ lbl_path = './/*[@id="cphMain_lblEstadoFe"]' if ncf [0 ] == 'E' else './/*[@id="cphMain_lblInformacion"]'
196
227
data = {
197
- 'validation_message' : document .findtext ('.//*[@id="cphMain_lblInformacion"]' ).strip (),
228
+ 'validation_message' : document .findtext (lbl_path ).strip (),
198
229
}
199
230
data .update (zip (
200
231
[x .text .strip () for x in result .findall ('.//th' )],
0 commit comments