Import from json
This commit is contained in:
parent
1efa280920
commit
c1ce206835
|
@ -644,11 +644,12 @@ class CFDI(object):
|
||||||
if self._comercio_exterior:
|
if self._comercio_exterior:
|
||||||
prefix = SAT['comercioe']['prefix']
|
prefix = SAT['comercioe']['prefix']
|
||||||
datos = datos.pop('comercioe')
|
datos = datos.pop('comercioe')
|
||||||
|
|
||||||
emisor = datos.pop('emisor')
|
emisor = datos.pop('emisor')
|
||||||
# ~ propietario = datos.pop('propietario')
|
propietarios = datos.pop('propietarios', {})
|
||||||
receptor = datos.pop('receptor')
|
receptor = datos.pop('receptor')
|
||||||
# ~ destinatario = datos.pop('destinatario')
|
destinatario = datos.pop('destinatario', {})
|
||||||
conceptos = datos.pop('mercancias')
|
mercancias = datos.pop('mercancias')
|
||||||
|
|
||||||
attr = {'Version': SAT['comercioe']['version']}
|
attr = {'Version': SAT['comercioe']['version']}
|
||||||
attr.update(datos)
|
attr.update(datos)
|
||||||
|
@ -680,7 +681,7 @@ class CFDI(object):
|
||||||
|
|
||||||
node = ET.SubElement(ce, '{}:Mercancias'.format(prefix))
|
node = ET.SubElement(ce, '{}:Mercancias'.format(prefix))
|
||||||
fields = ('Marca', 'Modelo', 'SubModelo', 'NumeroSerie')
|
fields = ('Marca', 'Modelo', 'SubModelo', 'NumeroSerie')
|
||||||
for row in conceptos:
|
for row in mercancias:
|
||||||
detalle = {}
|
detalle = {}
|
||||||
for f in fields:
|
for f in fields:
|
||||||
if f in row:
|
if f in row:
|
||||||
|
|
|
@ -104,6 +104,7 @@ var invoices_controllers = {
|
||||||
$$('cmd_carta_import_json').attachEvent('onItemClick', cmd_carta_import_json_click)
|
$$('cmd_carta_import_json').attachEvent('onItemClick', cmd_carta_import_json_click)
|
||||||
|
|
||||||
$$('cmd_import_json_comercioe').attachEvent('onItemClick', cmd_import_json_comercioe_click)
|
$$('cmd_import_json_comercioe').attachEvent('onItemClick', cmd_import_json_comercioe_click)
|
||||||
|
$$('cmd_ce_import_ods').attachEvent('onItemClick', cmd_ce_import_ods_click)
|
||||||
$$('cmd_ce_tipo_cambio').attachEvent('onItemClick', cmd_ce_tipo_cambio_click)
|
$$('cmd_ce_tipo_cambio').attachEvent('onItemClick', cmd_ce_tipo_cambio_click)
|
||||||
$$('cmd_ce_add_propietario').attachEvent('onItemClick', cmd_ce_add_propietario_click)
|
$$('cmd_ce_add_propietario').attachEvent('onItemClick', cmd_ce_add_propietario_click)
|
||||||
$$('cmd_ce_add_mercancia').attachEvent('onItemClick', cmd_ce_add_mercancia_click)
|
$$('cmd_ce_add_mercancia').attachEvent('onItemClick', cmd_ce_add_mercancia_click)
|
||||||
|
@ -581,6 +582,12 @@ function validate_invoice(values){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~ validate comercio exterior
|
||||||
|
var usar_comercioe = $$('chk_cfdi_usar_comercioe').getValue()
|
||||||
|
if(usar_comercioe){
|
||||||
|
var values = _get_values_comercio_exterior()
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,11 +926,6 @@ function cmd_timbrar_click(id, e, node){
|
||||||
|
|
||||||
if($$('chk_cfdi_usar_comercioe').getValue()){
|
if($$('chk_cfdi_usar_comercioe').getValue()){
|
||||||
msg += 'Estas usando el complemento:<BR>Comercio Exterior<BR><BR>'
|
msg += 'Estas usando el complemento:<BR>Comercio Exterior<BR><BR>'
|
||||||
//~ if(values_comercioe === null){
|
|
||||||
//~ msg = 'El complemento de Comercio Exterior esta vacío'
|
|
||||||
//~ msg_error(msg)
|
|
||||||
//~ return
|
|
||||||
//~ }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tipo_comprobante == 'T'){
|
if(tipo_comprobante == 'T'){
|
||||||
|
@ -3070,7 +3072,7 @@ function cmd_win_global_close_click(){
|
||||||
|
|
||||||
|
|
||||||
function cmd_ce_tipo_cambio_click(){
|
function cmd_ce_tipo_cambio_click(){
|
||||||
window.open('https://www.banxico.org.mx/tipcamb/llenarTiposCambioAction.do?idioma=sp', '_blank')
|
window.open('https://www.banxico.org.mx/tipcamb/tipCamMIAction.do?idioma=sp', '_blank')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3100,3 +3102,142 @@ function grid_ce_mercancias_click(id, e, node){
|
||||||
}
|
}
|
||||||
this.remove(id.row)
|
this.remove(id.row)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function _get_values_comercio_exterior(){
|
||||||
|
var form = $$('form_comercio_exterior')
|
||||||
|
|
||||||
|
if(!form.validate()) {
|
||||||
|
msg_error('Valores inválidos en Comercio Exterior')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const controls = {
|
||||||
|
Exportacion: 'lst_ce_exportacion',
|
||||||
|
MotivoTraslado: 'lst_ce_motivo_traslado',
|
||||||
|
ClaveDePedimento: 'lst_ce_clave_pedimento',
|
||||||
|
CertificadoOrigen: 'lst_ce_certificado_origen',
|
||||||
|
NumCertificadoOrigen: 'txt_ce_numero_certificado',
|
||||||
|
NumeroExportadorConfiable: 'txt_ce_numero_exportador',
|
||||||
|
Incoterm: 'lst_ce_incoterm',
|
||||||
|
Observaciones: 'txt_ce_observaciones',
|
||||||
|
TipoCambioUSD: 'txt_ce_tipo_cambio_usd',
|
||||||
|
TotalUSD: 'txt_ce_total_usd',
|
||||||
|
};
|
||||||
|
|
||||||
|
var values = new Object()
|
||||||
|
|
||||||
|
Object.keys(controls).forEach(key => {
|
||||||
|
var value = $$(controls[key]).getValue().trim()
|
||||||
|
if(value){
|
||||||
|
values[key] = value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var propietarios = $$('grid_ce_propietarios').data.getRange()
|
||||||
|
propietarios.forEach(function(row, index){
|
||||||
|
delete row['id']
|
||||||
|
delete row['delete']
|
||||||
|
})
|
||||||
|
|
||||||
|
var mercancias = $$('grid_ce_mercancias').data.getRange()
|
||||||
|
mercancias.forEach(function(row, index){
|
||||||
|
delete row['id']
|
||||||
|
delete row['delete']
|
||||||
|
})
|
||||||
|
|
||||||
|
var emisor = $$('grid_ce_emisor').data.getRange()[0]
|
||||||
|
delete emisor['id']
|
||||||
|
|
||||||
|
var receptor = $$('grid_ce_receptor').data.getRange()[0]
|
||||||
|
delete receptor['id']
|
||||||
|
|
||||||
|
var destinatario = $$('grid_ce_destinatario').data.getRange()[0]
|
||||||
|
delete destinatario['id']
|
||||||
|
|
||||||
|
values['emisor'] = emisor
|
||||||
|
values['propietarios'] = propietarios
|
||||||
|
values['receptor'] = receptor
|
||||||
|
values['destinatario'] = destinatario
|
||||||
|
values['mercancias'] = mercancias
|
||||||
|
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cmd_ce_import_ods_click(){
|
||||||
|
win_ce_import_ods.init()
|
||||||
|
$$('win_ce_import_ods').show()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cmd_ce_upload_ods_click(){
|
||||||
|
var form = $$('form_ce_import_ods')
|
||||||
|
|
||||||
|
var values = form.getValues()
|
||||||
|
|
||||||
|
if(!$$('lst_ce_up_template').count()){
|
||||||
|
$$('win_ce_import_ods').close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if($$('lst_ce_up_template').count() > 1){
|
||||||
|
msg = 'Selecciona solo un archivo'
|
||||||
|
msg_error(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var template = $$('ce_up_template').files.getItem($$('ce_up_template').files.getFirstId())
|
||||||
|
|
||||||
|
if(template.type.toLowerCase() != 'ods'){
|
||||||
|
msg = 'Archivo inválido.\n\nSe requiere un archivo ODS'
|
||||||
|
msg_error(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = '¿Estás seguro de importar este archivo?'
|
||||||
|
webix.confirm({
|
||||||
|
title: 'Importar datos de plantilla',
|
||||||
|
ok: 'Si',
|
||||||
|
cancel: 'No',
|
||||||
|
type: 'confirm-error',
|
||||||
|
text: msg,
|
||||||
|
callback:function(result){
|
||||||
|
if(result){
|
||||||
|
$$('ce_up_template').send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function ce_up_template_complete(response){
|
||||||
|
if(response.status != 'server'){
|
||||||
|
msg = 'Ocurrio un error al subir el archivo'
|
||||||
|
msg_error(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msg = 'Archivo subido correctamente.\n\nComenzando importación.'
|
||||||
|
msg_ok(msg)
|
||||||
|
$$('win_ce_import_ods').close()
|
||||||
|
|
||||||
|
webix.ajax().get('/values/importceods', {
|
||||||
|
error: function(text, data, xhr) {
|
||||||
|
msg_error('Error al consultar')
|
||||||
|
},
|
||||||
|
success: function(text, data, xhr){
|
||||||
|
var values = data.json()
|
||||||
|
if (values.ok){
|
||||||
|
//~ set values
|
||||||
|
msg_ok('OK')
|
||||||
|
}else{
|
||||||
|
webix.alert({
|
||||||
|
title: 'Error al importar',
|
||||||
|
text: values.msg,
|
||||||
|
type: 'alert-error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
|
@ -1463,6 +1463,8 @@ var controls_comercio_exterior = [
|
||||||
{},
|
{},
|
||||||
{view: 'button', id: 'cmd_import_json_comercioe', label: 'Importar JSON',
|
{view: 'button', id: 'cmd_import_json_comercioe', label: 'Importar JSON',
|
||||||
icon: 'upload', type: 'iconButton', autowidth: true, align: 'center'},
|
icon: 'upload', type: 'iconButton', autowidth: true, align: 'center'},
|
||||||
|
{view: 'button', id: 'cmd_ce_import_ods', label: 'Importar ODS',
|
||||||
|
icon: 'upload', type: 'iconButton', autowidth: true, align: 'center'},
|
||||||
{maxWidth: 15}]},
|
{maxWidth: 15}]},
|
||||||
{view: 'fieldset', label: 'Datos generales', body: body_ce_datos_generales},
|
{view: 'fieldset', label: 'Datos generales', body: body_ce_datos_generales},
|
||||||
{view: 'fieldset', label: 'Emisor', body: body_ce_emisor},
|
{view: 'fieldset', label: 'Emisor', body: body_ce_emisor},
|
||||||
|
@ -1577,7 +1579,13 @@ var win_import_invoice = {
|
||||||
width: 400,
|
width: 400,
|
||||||
modal: true,
|
modal: true,
|
||||||
position: 'center',
|
position: 'center',
|
||||||
head: 'Importar Factura de Plantilla',
|
head: {view: 'toolbar',
|
||||||
|
elements: [
|
||||||
|
{view: 'label', label: 'Importar Factura en Lote'},
|
||||||
|
{view: 'icon', icon: 'times-circle',
|
||||||
|
click: '$$("win_import_invoice").close()'},
|
||||||
|
]
|
||||||
|
},
|
||||||
body: body_upload_invoice,
|
body: body_upload_invoice,
|
||||||
})
|
})
|
||||||
$$('cmd_upload_invoice').attachEvent('onItemClick', cmd_upload_invoice_click)
|
$$('cmd_upload_invoice').attachEvent('onItemClick', cmd_upload_invoice_click)
|
||||||
|
@ -1726,3 +1734,41 @@ var win_global_information = {
|
||||||
$$('cmd_win_global_close').attachEvent('onItemClick', cmd_win_global_close_click)
|
$$('cmd_win_global_close').attachEvent('onItemClick', cmd_win_global_close_click)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var body_win_ce_import_ods = {rows: [
|
||||||
|
{view: 'form', id: 'form_ce_import_ods', rows: [
|
||||||
|
{cols: [{},
|
||||||
|
{view: 'uploader', id: 'ce_up_template', autosend: false,
|
||||||
|
link: 'lst_ce_up_template', value: 'Seleccionar Archivo',
|
||||||
|
upload: '/files/ceods'}, {}]},
|
||||||
|
{cols: [
|
||||||
|
{view: 'list', id: 'lst_ce_up_template',
|
||||||
|
type: 'uploader', autoheight: true, borderless: true}]},
|
||||||
|
{cols: [{}, {view: 'button', id: 'cmd_ce_upload_ods',
|
||||||
|
label: 'Importar Plantilla'}, {}]},
|
||||||
|
]},
|
||||||
|
]}
|
||||||
|
|
||||||
|
|
||||||
|
var win_ce_import_ods = {
|
||||||
|
init: function(){
|
||||||
|
webix.ui({
|
||||||
|
view: 'window',
|
||||||
|
id: 'win_ce_import_ods',
|
||||||
|
width: 400,
|
||||||
|
modal: true,
|
||||||
|
position: 'center',
|
||||||
|
head: {view: 'toolbar',
|
||||||
|
elements: [
|
||||||
|
{view: 'label', label: 'Importar desde archivo ODS'},
|
||||||
|
{view: 'icon', icon: 'times-circle',
|
||||||
|
click: '$$("win_ce_import_ods").close()'},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
body: body_win_ce_import_ods,
|
||||||
|
})
|
||||||
|
$$('cmd_ce_upload_ods').attachEvent('onItemClick', cmd_ce_upload_ods_click)
|
||||||
|
$$('ce_up_template').attachEvent('onUploadComplete', ce_up_template_complete)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue