se mueven archivos .gc a directorio facho/fe/data/dian/codelist/
FossilOrigin-Name: dbd0c91c222b504d32a8728084a024ccd2b7f5204819a68bf26318d3e38e378c
This commit is contained in:
parent
6aebada2d6
commit
cb73e7c930
@ -1,3 +1,6 @@
|
||||
# facho
|
||||
|
||||
libreria facturacion electronica colombia
|
||||
libreria facturacion electronica colombia
|
||||
|
||||
## COMENTARIOS
|
||||
* http://facturasyrespuestas.com/2342/error-al-enviar-set-de-pruebas-usando-sendtestsetasync
|
||||
|
@ -1,61 +1 @@
|
||||
import os.path
|
||||
|
||||
from lxml import etree
|
||||
|
||||
|
||||
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class CodeList:
|
||||
|
||||
def __init__(self, filename, primary_column):
|
||||
self.short_name = ''
|
||||
self.long_name = ''
|
||||
self.version = 1
|
||||
self.canonical_uri = ''
|
||||
self.canonical_version_uri = ''
|
||||
self.location_uri = ''
|
||||
|
||||
self.rows = {}
|
||||
self._load(filename, primary_column)
|
||||
|
||||
def _load(self, filename, primary_column):
|
||||
tree = etree.parse(filename)
|
||||
|
||||
#obtener identificadores...
|
||||
self.short_name = tree.find('./Identification/ShortName').text
|
||||
self.long_name = tree.find('./Identification/LongName').text
|
||||
self.version = tree.find('./Identification/Version').text
|
||||
self.canonical_uri = tree.find('./Identification/CanonicalUri').text
|
||||
self.canonical_version_uri = tree.find('./Identification/CanonicalVersionUri').text
|
||||
self.location_uri = tree.find('./Identification/LocationUri').text
|
||||
|
||||
#obtener registros...
|
||||
for row in tree.findall('./SimpleCodeList/Row'):
|
||||
new_row = self.xmlrow_to_dict(row)
|
||||
primary_key = new_row[primary_column]
|
||||
self.rows[primary_key] = new_row.copy()
|
||||
|
||||
def xmlrow_to_dict(self, xmlrow):
|
||||
row = {}
|
||||
|
||||
#construir registro...
|
||||
for value in xmlrow.getchildren():
|
||||
row[value.attrib['ColumnRef']] = value.getchildren()[0].text
|
||||
|
||||
return row
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.rows[str(key)]
|
||||
|
||||
|
||||
# nombres de variables igual a ./Identification/ShortName
|
||||
# TODO: garantizar unica carga en python
|
||||
|
||||
__all__ = ['TipoOrganizacion',
|
||||
'TipoResponsabilidad',
|
||||
'TipoAmbiente']
|
||||
|
||||
TipoOrganizacion = CodeList(os.path.join(DATA_DIR, 'TipoOrganizacion-2.1.gc'), 'name')
|
||||
TipoResponsabilidad = CodeList(os.path.join(DATA_DIR, 'TipoResponsabilidad-2.1.gc'), 'name')
|
||||
TipoAmbiente = CodeList(os.path.join(DATA_DIR, 'TipoAmbiente-2.1.gc'), 'name')
|
||||
from .codelist import CodeList
|
||||
|
61
facho/fe/data/dian/codelist/__init__.py
Normal file
61
facho/fe/data/dian/codelist/__init__.py
Normal file
@ -0,0 +1,61 @@
|
||||
import os.path
|
||||
|
||||
from lxml import etree
|
||||
|
||||
|
||||
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class CodeList:
|
||||
|
||||
def __init__(self, filename, primary_column):
|
||||
self.short_name = ''
|
||||
self.long_name = ''
|
||||
self.version = 1
|
||||
self.canonical_uri = ''
|
||||
self.canonical_version_uri = ''
|
||||
self.location_uri = ''
|
||||
|
||||
self.rows = {}
|
||||
self._load(filename, primary_column)
|
||||
|
||||
def _load(self, filename, primary_column):
|
||||
tree = etree.parse(filename)
|
||||
|
||||
#obtener identificadores...
|
||||
self.short_name = tree.find('./Identification/ShortName').text
|
||||
self.long_name = tree.find('./Identification/LongName').text
|
||||
self.version = tree.find('./Identification/Version').text
|
||||
self.canonical_uri = tree.find('./Identification/CanonicalUri').text
|
||||
self.canonical_version_uri = tree.find('./Identification/CanonicalVersionUri').text
|
||||
self.location_uri = tree.find('./Identification/LocationUri').text
|
||||
|
||||
#obtener registros...
|
||||
for row in tree.findall('./SimpleCodeList/Row'):
|
||||
new_row = self.xmlrow_to_dict(row)
|
||||
primary_key = new_row[primary_column]
|
||||
self.rows[primary_key] = new_row.copy()
|
||||
|
||||
def xmlrow_to_dict(self, xmlrow):
|
||||
row = {}
|
||||
|
||||
#construir registro...
|
||||
for value in xmlrow.getchildren():
|
||||
row[value.attrib['ColumnRef']] = value.getchildren()[0].text
|
||||
|
||||
return row
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.rows[str(key)]
|
||||
|
||||
|
||||
# nombres de variables igual a ./Identification/ShortName
|
||||
# TODO: garantizar unica carga en python
|
||||
|
||||
__all__ = ['TipoOrganizacion',
|
||||
'TipoResponsabilidad',
|
||||
'TipoAmbiente']
|
||||
|
||||
TipoOrganizacion = CodeList(os.path.join(DATA_DIR, 'TipoOrganizacion-2.1.gc'), 'name')
|
||||
TipoResponsabilidad = CodeList(os.path.join(DATA_DIR, 'TipoResponsabilidad-2.1.gc'), 'name')
|
||||
TipoAmbiente = CodeList(os.path.join(DATA_DIR, 'TipoAmbiente-2.1.gc'), 'name')
|
@ -10,7 +10,7 @@ import zipfile
|
||||
import warnings
|
||||
import hashlib
|
||||
from contextlib import contextmanager
|
||||
from .data import dian
|
||||
from .data.dian import codelist
|
||||
|
||||
NAMESPACES = {
|
||||
'fe': 'http://www.dian.gov.co/contratos/facturaelectronica/v1',
|
||||
@ -50,7 +50,7 @@ class DianXMLExtensionCUFE(FachoXMLExtension):
|
||||
self.invoice = invoice
|
||||
|
||||
def _tipo_ambiente(self):
|
||||
return int(dian.TipoAmbiente[self.tipo_ambiente]['code'])
|
||||
return int(codelist.TipoAmbiente[self.tipo_ambiente]['code'])
|
||||
|
||||
def build(self, fachoxml):
|
||||
cufe = self._generate_cufe(self.invoice, fachoxml)
|
||||
|
@ -7,7 +7,7 @@ import copy
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
|
||||
from .data import dian
|
||||
from .data.dian import codelist
|
||||
from . import fe
|
||||
|
||||
@dataclass
|
||||
@ -146,12 +146,12 @@ class DianResolucion0001Validator:
|
||||
|
||||
def _validate_party(self, party):
|
||||
try:
|
||||
dian.TipoResponsabilidad[party.responsability_code]
|
||||
codelist.TipoResponsabilidad[party.responsability_code]
|
||||
except KeyError:
|
||||
self.errors.append(('responsability_code', 'not found'))
|
||||
|
||||
try:
|
||||
dian.TipoOrganizacion[party.organization_code]
|
||||
codelist.TipoOrganizacion[party.organization_code]
|
||||
except KeyError:
|
||||
self.errors.append(('organization_code', 'not found'))
|
||||
|
||||
|
@ -6,11 +6,11 @@
|
||||
"""Tests for `facho` package."""
|
||||
|
||||
import pytest
|
||||
import facho.fe.data.dian as dian
|
||||
from facho.fe.data.dian import codelist
|
||||
|
||||
def test_dian():
|
||||
assert dian.TipoResponsabilidad.short_name == 'TipoResponsabilidad'
|
||||
assert dian.TipoResponsabilidad['Autorretenedor']['name'] == 'Autorretenedor'
|
||||
assert codelist.TipoResponsabilidad.short_name == 'TipoResponsabilidad'
|
||||
assert codelist.TipoResponsabilidad['Autorretenedor']['name'] == 'Autorretenedor'
|
||||
|
||||
assert dian.TipoOrganizacion.short_name == 'TipoOrganizacion'
|
||||
assert dian.TipoOrganizacion['Persona Natural']['name'] == 'Persona Natural'
|
||||
assert codelist.TipoOrganizacion.short_name == 'TipoOrganizacion'
|
||||
assert codelist.TipoOrganizacion['Persona Natural']['name'] == 'Persona Natural'
|
||||
|
Loading…
Reference in New Issue
Block a user