lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.16-11-g4c51860

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.16-11-g4c51860



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  4c51860388bd11fdd80102d683b928487adc511d (commit)
       via  48e65022e257a32417a521f5929d7c884811635a (commit)
       via  2b452b631dab3464747fcd353a5dfe07fb1396e6 (commit)
      from  eeaf6650c1e71e1e838933976f1e692b90760cec (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=4c51860388bd11fdd80102d683b928487adc511d

commit 4c51860388bd11fdd80102d683b928487adc511d
Author: FRANK ROBERTO CHAVEZ SOSA <1085268@est.intec.edu.do>
Date:   Thu Jun 10 10:22:41 2021 -0400

    Add new e-CF types to Dominican Republic NCF

diff --git a/stdnum/do/ncf.py b/stdnum/do/ncf.py
index cdecfc0..7920908 100644
--- a/stdnum/do/ncf.py
+++ b/stdnum/do/ncf.py
@@ -90,6 +90,8 @@ _ecf_document_types = (
     '43',  # minor expenses invoices (purchases)
     '44',  # invoices for special customers (tourists, free zones)
     '45',  # invoices for the government
+    '46',  # invoices for exports
+    '47',  # invoices for foreign payments
 )
 
 

https://arthurdejong.org/git/python-stdnum/commit/?id=48e65022e257a32417a521f5929d7c884811635a

commit 48e65022e257a32417a521f5929d7c884811635a
Author: Andres Rodriguez <androdriguez14@gmail.com>
Date:   Mon Jan 18 20:41:58 2021 -0400

    Fix parsing of empty fields in DGII checking

diff --git a/stdnum/do/ncf.py b/stdnum/do/ncf.py
index bc82a34..cdecfc0 100644
--- a/stdnum/do/ncf.py
+++ b/stdnum/do/ncf.py
@@ -228,6 +228,6 @@ def check_dgii(rnc, ncf, buyer_rnc=None, 
security_code=None, timeout=30):  # pra
             'validation_message': document.findtext(lbl_path).strip(),
         }
         data.update(zip(
-            [x.text.strip() for x in result.findall('.//th')],
-            [x.text.strip() for x in result.findall('.//td/span')]))
+            [x.text.strip() for x in result.findall('.//th') if x.text],
+            [x.text.strip() for x in result.findall('.//td/span') if x.text]))
         return _convert_result(data)

https://arthurdejong.org/git/python-stdnum/commit/?id=2b452b631dab3464747fcd353a5dfe07fb1396e6

commit 2b452b631dab3464747fcd353a5dfe07fb1396e6
Author: Cristopher Ortega <ortega.cpp@gmail.com>
Date:   Fri Dec 11 11:31:28 2020 -0400

    Add ENCF validation support for Dominican Republic NCF
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/248

diff --git a/stdnum/do/ncf.py b/stdnum/do/ncf.py
index c9a3a13..bc82a34 100644
--- a/stdnum/do/ncf.py
+++ b/stdnum/do/ncf.py
@@ -140,13 +140,22 @@ def _convert_result(result):  # pragma: no cover
         'Estado': 'status',
         'Tipo de comprobante': 'type',
         u'Válido hasta': 'valid_until',
+        u'Código de Seguridad': 'security_code',
+        'Rnc Emisor': 'issuing_rnc',
+        'Rnc Comprador': 'buyer_rnc',
+        'Monto Total': 'total',
+        'Total de ITBIS': 'total_itbis',
+        'Fecha Emisi&oacuten': 'issuing_date',
+        u'Fecha Emisión': 'issuing_date',
+        u'Fecha de Firma': 'signature_date',
+        'e-NCF': 'ncf',
     }
     return dict(
         (translation.get(key, key), value)
         for key, value in result.items())
 
 
-def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
+def check_dgii(rnc, ncf, buyer_rnc=None, security_code=None, timeout=30):  # 
pragma: no cover
     """Validate the RNC, NCF combination on using the DGII online web service.
 
     This uses the validation service run by the the Dirección General de
@@ -154,7 +163,7 @@ def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
     whether the combination of RNC and NCF is valid. The timeout is in
     seconds.
 
-    Returns a dict with the following structure::
+    Returns a dict with the following structure for a NCF::
 
         {
             'name': 'The registered name',
@@ -165,12 +174,29 @@ def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
             'validation_message': 'El NCF digitado es válido.',
         }
 
+    For an ECNF::
+
+        {
+            'status': 'Aceptado',
+            'issuing_rnc': '1234567890123',
+            'buyer_rnc': '123456789',
+            'ncf': 'E300000000000',
+            'security_code': '1+2kP3',
+            'issuing_date': '2020-03-25',
+            'signature_date': '2020-03-22',
+            'total': '2203.50',
+            'total_itbis': '305.10',
+            'validation_message': 'Aceptado',
+        }
+
     Will return None if the number is invalid or unknown."""
     import lxml.html
     import requests
     from stdnum.do.rnc import compact as rnc_compact  # noqa: I003
     rnc = rnc_compact(rnc)
     ncf = compact(ncf)
+    if buyer_rnc:
+        buyer_rnc = rnc_compact(buyer_rnc)
     url = 
'https://dgii.gov.do/app/WebApps/ConsultasWeb2/ConsultasWeb/consultas/ncf.aspx'
     session = requests.Session()
     session.headers.update({
@@ -188,13 +214,18 @@ def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
         'ctl00$cphMain$txtNCF': ncf,
         'ctl00$cphMain$txtRNC': rnc,
     }
+    if ncf[0] == 'E':
+        data['ctl00$cphMain$txtRncComprador'] = buyer_rnc
+        data['ctl00$cphMain$txtCodigoSeg'] = security_code
     # Do the actual request
     document = lxml.html.fromstring(
         session.post(url, data=data, timeout=timeout).text)
-    result = document.find('.//div[@id="cphMain_pResultado"]')
+    result_path = './/div[@id="cphMain_PResultadoFE"]' if ncf[0] == 'E' else 
'.//div[@id="cphMain_pResultado"]'
+    result = document.find(result_path)
     if result is not None:
+        lbl_path = './/*[@id="cphMain_lblEstadoFe"]' if ncf[0] == 'E' else 
'.//*[@id="cphMain_lblInformacion"]'
         data = {
-            'validation_message': 
document.findtext('.//*[@id="cphMain_lblInformacion"]').strip(),
+            'validation_message': document.findtext(lbl_path).strip(),
         }
         data.update(zip(
             [x.text.strip() for x in result.findall('.//th')],
diff --git a/tests/test_do_ncf.py b/tests/test_do_ncf.py
index 8a94bfa..dc58b2d 100644
--- a/tests/test_do_ncf.py
+++ b/tests/test_do_ncf.py
@@ -64,3 +64,16 @@ class TestDGII(unittest.TestCase):
         self.assertIn('validation_message', result.keys())
         self.assertEqual(result['rnc'], '130546312')
         self.assertEqual(result['ncf'], 'B0100000005')
+        # Test the ENCF
+        result = ncf.check_dgii('101010632', 'E310049533639',
+                                buyer_rnc='22400559690', 
security_code='hnI63Q')
+        self.assertTrue(result)
+        self.assertIn('status', result.keys())
+        self.assertEqual(result['issuing_rnc'], '101010632')
+        self.assertEqual(result['buyer_rnc'], '22400559690')
+        self.assertEqual(result['ncf'], 'E310049533639')
+        self.assertIn('issuing_date', result.keys())
+        self.assertIn('signature_date', result.keys())
+        self.assertIn('total', result.keys())
+        self.assertIn('total_itbis', result.keys())
+        self.assertIn('validation_message', result.keys())

-----------------------------------------------------------------------

Summary of changes:
 stdnum/do/ncf.py     | 45 +++++++++++++++++++++++++++++++++++++++------
 tests/test_do_ncf.py | 13 +++++++++++++
 2 files changed, 52 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
python-stdnum