From 510ebdd1e5d9f96ccac682d9af035dab56844218 Mon Sep 17 00:00:00 2001 From: El Mau Date: Sun, 21 Jan 2024 23:20:27 -0600 Subject: [PATCH] Stamp CE in version 2.0 --- source/app/controllers/cfdi_xml.py | 92 ++++++++++++------------- source/app/controllers/util.py | 5 +- source/app/models/main.py | 2 - source/static/js/controller/invoices.js | 42 +++++++++++ 4 files changed, 90 insertions(+), 51 deletions(-) diff --git a/source/app/controllers/cfdi_xml.py b/source/app/controllers/cfdi_xml.py index c0671a5..ee3d961 100644 --- a/source/app/controllers/cfdi_xml.py +++ b/source/app/controllers/cfdi_xml.py @@ -169,7 +169,9 @@ class CFDI(object): if 'nomina' in datos: self._nomina(datos['nomina']) - return self._to_pretty_xml(ET.tostring(self._cfdi, encoding='utf-8')) + xml = self._to_pretty_xml(ET.tostring(self._cfdi, encoding='utf-8')) + + return xml def add_sello(self, sello, cert_txt): self._cfdi.attrib['Sello'] = sello @@ -518,6 +520,47 @@ class CFDI(object): return + def _complemento_comercio_exterior(self, datos): + prefix = SAT['comercioe']['prefix'] + + emisor = datos.pop('emisor') + propietarios = datos.pop('propietarios', {}) + receptor = datos.pop('receptor') + destinatario = datos.pop('destinatario', {}) + mercancias = datos.pop('mercancias') + + attr = {'Version': SAT['comercioe']['version']} + attr.update(datos) + ce = ET.SubElement( + self._complemento, f'{prefix}:ComercioExterior', attr) + + attributes = {} + if 'Curp' in emisor: + attributes = {'Curp': emisor.pop('Curp')} + node = ET.SubElement(ce, '{}:Emisor'.format(prefix), attributes) + ET.SubElement(node, '{}:Domicilio'.format(prefix), emisor) + + attributes = {} + if 'NumRegIdTrib' in receptor: + attributes = {'NumRegIdTrib': receptor.pop('NumRegIdTrib')} + node = ET.SubElement(ce, '{}:Receptor'.format(prefix), attributes) + ET.SubElement(node, '{}:Domicilio'.format(prefix), receptor) + + node = ET.SubElement(ce, '{}:Mercancias'.format(prefix)) + fields = ('Marca', 'Modelo', 'SubModelo', 'NumeroSerie') + for row in mercancias: + detalle = {} + for f in fields: + if f in row and row[f]: + detalle[f] = row[f] + row.pop(f) + concepto = ET.SubElement(node, '{}:Mercancia'.format(prefix), row) + if detalle: + ET.SubElement( + concepto, '{}:DescripcionesEspecificas'.format(prefix), detalle) + + return + def _complementos(self, datos): if not datos: return @@ -642,52 +685,7 @@ class CFDI(object): ET.SubElement(node_leyend, '{}:Leyenda'.format(pre), leyend) if self._comercio_exterior: - prefix = SAT['comercioe']['prefix'] datos = datos.pop('comercioe') + self._complemento_comercio_exterior(datos) - emisor = datos.pop('emisor') - propietarios = datos.pop('propietarios', {}) - receptor = datos.pop('receptor') - destinatario = datos.pop('destinatario', {}) - mercancias = datos.pop('mercancias') - - attr = {'Version': SAT['comercioe']['version']} - attr.update(datos) - ce = ET.SubElement( - self._complemento, f'{prefix}:ComercioExterior', attr) - - attributes = {} - if 'Curp' in emisor: - attributes = {'Curp': emisor.pop('Curp')} - node = ET.SubElement(ce, '{}:Emisor'.format(prefix), attributes) - ET.SubElement(node, '{}:Domicilio'.format(prefix), emisor) - - # ~ if propietario: - # ~ ET.SubElement(ce, '{}:Propietario'.format(prefix), propietario) - - attributes = {} - if 'NumRegIdTrib' in receptor: - attributes = {'NumRegIdTrib': receptor.pop('NumRegIdTrib')} - node = ET.SubElement(ce, '{}:Receptor'.format(prefix), attributes) - ET.SubElement(node, '{}:Domicilio'.format(prefix), receptor) - - # ~ attributes = {} - # ~ if 'NumRegIdTrib' in destinatario: - # ~ attributes = {'NumRegIdTrib': destinatario.pop('NumRegIdTrib')} - # ~ if 'Nombre' in destinatario: - # ~ attributes.update({'Nombre': destinatario.pop('Nombre')}) - # ~ node = ET.SubElement(ce, '{}:Destinatario'.format(prefix), attributes) - # ~ ET.SubElement(node, '{}:Domicilio'.format(prefix), destinatario) - - node = ET.SubElement(ce, '{}:Mercancias'.format(prefix)) - fields = ('Marca', 'Modelo', 'SubModelo', 'NumeroSerie') - for row in mercancias: - detalle = {} - for f in fields: - if f in row: - detalle[f] = row.pop(f) - concepto = ET.SubElement(node, '{}:Mercancia'.format(prefix), row) - if detalle: - ET.SubElement( - concepto, '{}:DescripcionesEspecificas'.format(prefix), detalle) return diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index ad06eb7..50d5405 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -1576,11 +1576,12 @@ class LIBO(object): return data def _current_region_to_tuple(self, cursor): + data = [] cursor.collapseToCurrentRegion() rows = cursor.getDataArray()[1:] - if len(rows) == 2: - return [] + if len(rows) == 1: + return data keys = rows[0] data = [dict(zip(keys, values)) for values in rows[1:]] diff --git a/source/app/models/main.py b/source/app/models/main.py index 3f2070f..ed75c0f 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -5623,8 +5623,6 @@ class Facturas(BaseModel): if not valores: return - # ~ values = utils.loads(valores) - data = { 'factura': invoice, 'nombre': 'comercioe', diff --git a/source/static/js/controller/invoices.js b/source/static/js/controller/invoices.js index 94a6a2c..74aca5f 100644 --- a/source/static/js/controller/invoices.js +++ b/source/static/js/controller/invoices.js @@ -247,6 +247,7 @@ function default_config(){ $$('tv_invoice').getTabbar().hideOption('Comercio Exterior') }else{ $$('tv_invoice').getTabbar().showOption('Comercio Exterior') + _set_default_comercio_exterior() } cfg_invoice['leyendasfiscales'] = values.cfdi_leyendasfiscales cfg_invoice['edu'] = values.cfdi_edu @@ -2961,7 +2962,48 @@ function up_invoice_json_on_after_file_add(obj){ } +function _set_default_comercio_exterior(){ + const controls = { + lst_ce_exportacion: '02', + lst_ce_motivo_traslado: '', + lst_ce_clave_pedimento: 'A1', + lst_ce_certificado_origen: '0', + txt_ce_numero_certificado: '', + txt_ce_numero_exportador: '', + lst_ce_incoterm: 'CFR', + txt_ce_observaciones: '', + txt_ce_tipo_cambio_usd: '', + txt_ce_total_usd: '', + }; + + Object.keys(controls).forEach(key => { + $$(key).setValue(controls[key]) + }); + + var grid = $$('grid_ce_emisor') + grid.clearAll() + grid.add({id: 0}) + + var grid = $$('grid_ce_receptor') + grid.clearAll() + grid.add({id: 0}) + + var grid = $$('grid_ce_destinatario') + grid.clearAll() + grid.add({id: 0}) + + var grid = $$('grid_ce_propietarios') + grid.clearAll() + + var grid = $$('grid_ce_mercancias') + grid.clearAll() +} + + function _set_from_json_comercioe(data, json){ + + _set_default_comercio_exterior() + try{ if(json){ values = JSON.parse(data)