cambios a metodo de consulta de codelist
FossilOrigin-Name: f127cde5990855880e481d75cd3c8fe27de0bcb534ce29dee889a630fa8e9d9b
This commit is contained in:
parent
15d880885e
commit
d5a6a47f99
@ -91,13 +91,13 @@ class SendBillAsync(SOAPService):
|
|||||||
@dataclass
|
@dataclass
|
||||||
class SendTestSetAsyncResponse:
|
class SendTestSetAsyncResponse:
|
||||||
ZipKey: str
|
ZipKey: str
|
||||||
ErrorMessageList: List[str] = []
|
ErrorMessageList: List[str]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromdict(cls, data):
|
def fromdict(cls, data):
|
||||||
return cls(
|
return cls(
|
||||||
data['ZipKey'],
|
data['ZipKey'],
|
||||||
data['ErrorMessageList']
|
data['ErrorMessageList'] or []
|
||||||
)
|
)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -8,7 +8,7 @@ DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||||||
|
|
||||||
class CodeList:
|
class CodeList:
|
||||||
|
|
||||||
def __init__(self, filename, primary_column):
|
def __init__(self, filename, primary_column, name_column):
|
||||||
self.short_name = ''
|
self.short_name = ''
|
||||||
self.long_name = ''
|
self.long_name = ''
|
||||||
self.version = 1
|
self.version = 1
|
||||||
@ -16,6 +16,7 @@ class CodeList:
|
|||||||
self.canonical_version_uri = ''
|
self.canonical_version_uri = ''
|
||||||
self.location_uri = ''
|
self.location_uri = ''
|
||||||
|
|
||||||
|
self.name_column = name_column
|
||||||
self.rows = {}
|
self.rows = {}
|
||||||
self._load(filename, primary_column)
|
self._load(filename, primary_column)
|
||||||
|
|
||||||
@ -49,6 +50,12 @@ class CodeList:
|
|||||||
return self.rows[str(key)]
|
return self.rows[str(key)]
|
||||||
|
|
||||||
|
|
||||||
|
def by_name(self, name):
|
||||||
|
for k, v in self.rows.items():
|
||||||
|
if v[self.name_column] == name:
|
||||||
|
return v
|
||||||
|
raise KeyError
|
||||||
|
|
||||||
# nombres de variables igual a ./Identification/ShortName
|
# nombres de variables igual a ./Identification/ShortName
|
||||||
# TODO: garantizar unica carga en python
|
# TODO: garantizar unica carga en python
|
||||||
|
|
||||||
@ -59,7 +66,7 @@ __all__ = ['TipoOrganizacion',
|
|||||||
def path_for_codelist(name):
|
def path_for_codelist(name):
|
||||||
return os.path.join(DATA_DIR, name)
|
return os.path.join(DATA_DIR, name)
|
||||||
|
|
||||||
TipoOrganizacion = CodeList(path_for_codelist('TipoOrganizacion-2.1.gc'), 'name')
|
TipoOrganizacion = CodeList(path_for_codelist('TipoOrganizacion-2.1.gc'), 'code', 'name')
|
||||||
TipoResponsabilidad = CodeList(path_for_codelist('TipoResponsabilidad-2.1.gc'), 'name')
|
TipoResponsabilidad = CodeList(path_for_codelist('TipoResponsabilidad-2.1.gc'), 'code', 'name')
|
||||||
TipoAmbiente = CodeList(path_for_codelist('TipoAmbiente-2.1.gc'), 'name')
|
TipoAmbiente = CodeList(path_for_codelist('TipoAmbiente-2.1.gc'), 'code', 'name')
|
||||||
TipoDocumento = CodeList(path_for_codelist('TipoDocumento-2.1.gc'), 'name')
|
TipoDocumento = CodeList(path_for_codelist('TipoDocumento-2.1.gc'), 'code', 'name')
|
||||||
|
@ -41,8 +41,8 @@ class FeXML(FachoXML):
|
|||||||
|
|
||||||
|
|
||||||
class DianXMLExtensionCUFE(FachoXMLExtension):
|
class DianXMLExtensionCUFE(FachoXMLExtension):
|
||||||
AMBIENTE_PRUEBAS = 'Pruebas'
|
AMBIENTE_PRUEBAS = codelist.TipoAmbiente.by_name('Pruebas')['code']
|
||||||
AMBIENTE_PRODUCCION = 'Producción'
|
AMBIENTE_PRODUCCION = codelist.TipoAmbiente.by_name('Producción')['code']
|
||||||
|
|
||||||
def __init__(self, invoice, tipo_ambiente = AMBIENTE_PRUEBAS, clave_tecnica = ''):
|
def __init__(self, invoice, tipo_ambiente = AMBIENTE_PRUEBAS, clave_tecnica = ''):
|
||||||
self.tipo_ambiente = tipo_ambiente
|
self.tipo_ambiente = tipo_ambiente
|
||||||
@ -50,7 +50,7 @@ class DianXMLExtensionCUFE(FachoXMLExtension):
|
|||||||
self.invoice = invoice
|
self.invoice = invoice
|
||||||
|
|
||||||
def _tipo_ambiente(self):
|
def _tipo_ambiente(self):
|
||||||
return int(codelist.TipoAmbiente[self.tipo_ambiente]['code'])
|
return int(self.tipo_ambiente)
|
||||||
|
|
||||||
def build(self, fachoxml):
|
def build(self, fachoxml):
|
||||||
cufe = self._generate_cufe(self.invoice, fachoxml)
|
cufe = self._generate_cufe(self.invoice, fachoxml)
|
||||||
|
@ -18,7 +18,7 @@ class Item:
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class StandarItem(Item):
|
class StandardItem(Item):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -174,12 +174,15 @@ class DianResolucion0001Validator:
|
|||||||
try:
|
try:
|
||||||
codelist.TipoResponsabilidad[party.responsability_code]
|
codelist.TipoResponsabilidad[party.responsability_code]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.errors.append((model, 'responsability_code', 'not found'))
|
self.errors.append((model,
|
||||||
|
'responsability_code',
|
||||||
|
'not found %s' % (party.responsability_code)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
codelist.TipoOrganizacion[party.organization_code]
|
codelist.TipoOrganizacion[party.organization_code]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.errors.append((model, 'organization_code', 'not found'))
|
self.errors.append((model, 'organization_code' ,
|
||||||
|
'not found %s' % (party.organization_code)))
|
||||||
|
|
||||||
def validate(self, invoice):
|
def validate(self, invoice):
|
||||||
invoice.accept(self)
|
invoice.accept(self)
|
||||||
@ -211,7 +214,7 @@ class DIANInvoiceXML(fe.FeXML):
|
|||||||
|
|
||||||
invoice.calculate()
|
invoice.calculate()
|
||||||
|
|
||||||
fexml.set_element('/fe:Invoice/cbc:InvoiceTypeCode', codelist.TipoDocumento['Factura de Venta Nacional']['code'],
|
fexml.set_element('/fe:Invoice/cbc:InvoiceTypeCode', codelist.TipoDocumento.by_name('Factura de Venta Nacional')['code'],
|
||||||
listAgencyID='195',
|
listAgencyID='195',
|
||||||
listAgencyName='No matching global declaration available for the validation root',
|
listAgencyName='No matching global declaration available for the validation root',
|
||||||
listURI='http://www.dian.gov.co')
|
listURI='http://www.dian.gov.co')
|
||||||
|
@ -10,12 +10,12 @@ from facho.fe.data.dian import codelist
|
|||||||
|
|
||||||
def test_tiporesponsabilidad():
|
def test_tiporesponsabilidad():
|
||||||
assert codelist.TipoResponsabilidad.short_name == 'TipoResponsabilidad'
|
assert codelist.TipoResponsabilidad.short_name == 'TipoResponsabilidad'
|
||||||
assert codelist.TipoResponsabilidad['Autorretenedor']['name'] == 'Autorretenedor'
|
assert codelist.TipoResponsabilidad.by_name('Autorretenedor')['name'] == 'Autorretenedor'
|
||||||
|
|
||||||
def test_tipoorganizacion():
|
def test_tipoorganizacion():
|
||||||
assert codelist.TipoOrganizacion.short_name == 'TipoOrganizacion'
|
assert codelist.TipoOrganizacion.short_name == 'TipoOrganizacion'
|
||||||
assert codelist.TipoOrganizacion['Persona Natural']['name'] == 'Persona Natural'
|
assert codelist.TipoOrganizacion.by_name('Persona Natural')['name'] == 'Persona Natural'
|
||||||
|
|
||||||
def test_tipodocumento():
|
def test_tipodocumento():
|
||||||
assert codelist.TipoDocumento.short_name == 'TipoDocumento'
|
assert codelist.TipoDocumento.short_name == 'TipoDocumento'
|
||||||
assert codelist.TipoDocumento['Factura de Venta Nacional']['code'] == '01'
|
assert codelist.TipoDocumento.by_name('Factura de Venta Nacional')['code'] == '01'
|
||||||
|
@ -23,15 +23,15 @@ def simple_invoice_without_lines():
|
|||||||
inv.set_supplier(form.Party(
|
inv.set_supplier(form.Party(
|
||||||
name = 'facho-supplier',
|
name = 'facho-supplier',
|
||||||
ident = 123,
|
ident = 123,
|
||||||
responsability_code = 'No aplica',
|
responsability_code = 'ZZ',
|
||||||
organization_code = 'Persona Natural',
|
organization_code = '1',
|
||||||
address = form.Address(name='Test Building')
|
address = form.Address(name='Test Building')
|
||||||
))
|
))
|
||||||
inv.set_customer(form.Party(
|
inv.set_customer(form.Party(
|
||||||
name = 'facho-customer',
|
name = 'facho-customer',
|
||||||
ident = 321,
|
ident = 321,
|
||||||
responsability_code = 'No aplica',
|
responsability_code = 'ZZ',
|
||||||
organization_code = 'Persona Natural',
|
organization_code = '1',
|
||||||
address = form.Address(name='Test Building')
|
address = form.Address(name='Test Building')
|
||||||
))
|
))
|
||||||
return inv
|
return inv
|
||||||
@ -45,19 +45,19 @@ def simple_invoice():
|
|||||||
inv.set_supplier(form.Party(
|
inv.set_supplier(form.Party(
|
||||||
name = 'facho-supplier',
|
name = 'facho-supplier',
|
||||||
ident = 123,
|
ident = 123,
|
||||||
responsability_code = 'No aplica',
|
responsability_code = 'ZZ',
|
||||||
organization_code = 'Persona Natural'
|
organization_code = '1'
|
||||||
))
|
))
|
||||||
inv.set_customer(form.Party(
|
inv.set_customer(form.Party(
|
||||||
name = 'facho-customer',
|
name = 'facho-customer',
|
||||||
ident = 321,
|
ident = 321,
|
||||||
responsability_code = 'No aplica',
|
responsability_code = 'ZZ',
|
||||||
organization_code = 'Persona Natural'
|
organization_code = '1'
|
||||||
))
|
))
|
||||||
inv.add_invoice_line(form.InvoiceLine(
|
inv.add_invoice_line(form.InvoiceLine(
|
||||||
quantity = 1,
|
quantity = 1,
|
||||||
description = 'producto facho',
|
description = 'producto facho',
|
||||||
item = form.StandarItem('test', 9999),
|
item = form.StandardItem('test', 9999),
|
||||||
price_amount = 100.0,
|
price_amount = 100.0,
|
||||||
tax = form.TaxTotal(
|
tax = form.TaxTotal(
|
||||||
tax_amount = 0.0,
|
tax_amount = 0.0,
|
||||||
@ -159,7 +159,7 @@ def test_invoice_totals(simple_invoice_without_lines):
|
|||||||
simple_invoice.add_invoice_line(form.InvoiceLine(
|
simple_invoice.add_invoice_line(form.InvoiceLine(
|
||||||
quantity = 1,
|
quantity = 1,
|
||||||
description = 'producto',
|
description = 'producto',
|
||||||
item = form.StandarItem('test', 9999),
|
item = form.StandardItem('test', 9999),
|
||||||
price_amount = 1_500_000,
|
price_amount = 1_500_000,
|
||||||
tax = form.TaxTotal(
|
tax = form.TaxTotal(
|
||||||
subtotals = [
|
subtotals = [
|
||||||
@ -182,7 +182,7 @@ def test_invoice_cufe(simple_invoice_without_lines):
|
|||||||
simple_invoice.add_invoice_line(form.InvoiceLine(
|
simple_invoice.add_invoice_line(form.InvoiceLine(
|
||||||
quantity = 1,
|
quantity = 1,
|
||||||
description = 'producto',
|
description = 'producto',
|
||||||
item = form.StandarItem('test', 111),
|
item = form.StandardItem('test', 111),
|
||||||
price_amount = 1_500_000,
|
price_amount = 1_500_000,
|
||||||
tax = form.TaxTotal(
|
tax = form.TaxTotal(
|
||||||
subtotals = [
|
subtotals = [
|
||||||
|
Loading…
Reference in New Issue
Block a user