cambios a metodo de consulta de codelist
FossilOrigin-Name: f127cde5990855880e481d75cd3c8fe27de0bcb534ce29dee889a630fa8e9d9b
This commit is contained in:
		| @@ -91,13 +91,13 @@ class SendBillAsync(SOAPService): | ||||
| @dataclass | ||||
| class SendTestSetAsyncResponse: | ||||
|     ZipKey: str | ||||
|     ErrorMessageList: List[str] = [] | ||||
|     ErrorMessageList: List[str] | ||||
|      | ||||
|     @classmethod | ||||
|     def fromdict(cls, data): | ||||
|         return cls( | ||||
|             data['ZipKey'], | ||||
|             data['ErrorMessageList'] | ||||
|             data['ErrorMessageList'] or [] | ||||
|         ) | ||||
|      | ||||
| @dataclass | ||||
|   | ||||
| @@ -8,14 +8,15 @@ DATA_DIR = os.path.dirname(os.path.abspath(__file__)) | ||||
|  | ||||
| class CodeList: | ||||
|  | ||||
|     def __init__(self, filename, primary_column): | ||||
|     def __init__(self, filename, primary_column, name_column): | ||||
|         self.short_name = '' | ||||
|         self.long_name = '' | ||||
|         self.version = 1 | ||||
|         self.canonical_uri = '' | ||||
|         self.canonical_version_uri = '' | ||||
|         self.location_uri = '' | ||||
|          | ||||
|  | ||||
|         self.name_column = name_column | ||||
|         self.rows = {} | ||||
|         self._load(filename, primary_column) | ||||
|  | ||||
| @@ -49,6 +50,12 @@ class CodeList: | ||||
|         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 | ||||
| # TODO: garantizar unica carga en python | ||||
|  | ||||
| @@ -59,7 +66,7 @@ __all__ = ['TipoOrganizacion', | ||||
| def path_for_codelist(name): | ||||
|     return os.path.join(DATA_DIR, name) | ||||
|  | ||||
| TipoOrganizacion = CodeList(path_for_codelist('TipoOrganizacion-2.1.gc'), 'name') | ||||
| TipoResponsabilidad = CodeList(path_for_codelist('TipoResponsabilidad-2.1.gc'), 'name') | ||||
| TipoAmbiente = CodeList(path_for_codelist('TipoAmbiente-2.1.gc'), 'name') | ||||
| TipoDocumento = CodeList(path_for_codelist('TipoDocumento-2.1.gc'), 'name') | ||||
| TipoOrganizacion = CodeList(path_for_codelist('TipoOrganizacion-2.1.gc'), 'code', 'name') | ||||
| TipoResponsabilidad = CodeList(path_for_codelist('TipoResponsabilidad-2.1.gc'), 'code', 'name') | ||||
| TipoAmbiente = CodeList(path_for_codelist('TipoAmbiente-2.1.gc'), 'code', 'name') | ||||
| TipoDocumento = CodeList(path_for_codelist('TipoDocumento-2.1.gc'), 'code', 'name') | ||||
|   | ||||
| @@ -41,8 +41,8 @@ class FeXML(FachoXML): | ||||
|  | ||||
|  | ||||
| class DianXMLExtensionCUFE(FachoXMLExtension): | ||||
|     AMBIENTE_PRUEBAS = 'Pruebas' | ||||
|     AMBIENTE_PRODUCCION = 'Producción' | ||||
|     AMBIENTE_PRUEBAS = codelist.TipoAmbiente.by_name('Pruebas')['code'] | ||||
|     AMBIENTE_PRODUCCION = codelist.TipoAmbiente.by_name('Producción')['code'] | ||||
|      | ||||
|     def __init__(self, invoice, tipo_ambiente = AMBIENTE_PRUEBAS, clave_tecnica = ''): | ||||
|         self.tipo_ambiente = tipo_ambiente | ||||
| @@ -50,7 +50,7 @@ class DianXMLExtensionCUFE(FachoXMLExtension): | ||||
|         self.invoice = invoice | ||||
|  | ||||
|     def _tipo_ambiente(self): | ||||
|         return int(codelist.TipoAmbiente[self.tipo_ambiente]['code']) | ||||
|         return int(self.tipo_ambiente) | ||||
|  | ||||
|     def build(self, fachoxml): | ||||
|         cufe = self._generate_cufe(self.invoice, fachoxml) | ||||
|   | ||||
| @@ -18,7 +18,7 @@ class Item: | ||||
|  | ||||
|      | ||||
| @dataclass | ||||
| class StandarItem(Item): | ||||
| class StandardItem(Item): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| @@ -174,12 +174,15 @@ class DianResolucion0001Validator: | ||||
|         try: | ||||
|             codelist.TipoResponsabilidad[party.responsability_code] | ||||
|         except KeyError: | ||||
|             self.errors.append((model, 'responsability_code', 'not found')) | ||||
|             self.errors.append((model, | ||||
|                                 'responsability_code', | ||||
|                                 'not found %s' % (party.responsability_code))) | ||||
|  | ||||
|         try: | ||||
|             codelist.TipoOrganizacion[party.organization_code] | ||||
|         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): | ||||
|         invoice.accept(self) | ||||
| @@ -211,7 +214,7 @@ class DIANInvoiceXML(fe.FeXML): | ||||
|  | ||||
|         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', | ||||
|                           listAgencyName='No matching global declaration available for the validation root', | ||||
|                           listURI='http://www.dian.gov.co') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user