Refactory method for import file
This commit is contained in:
parent
535cc9d527
commit
702ac88b38
|
@ -778,3 +778,12 @@ def read_csv(path, args={'delimiter': '|'}):
|
|||
rows = [r for r in reader]
|
||||
return rows
|
||||
|
||||
|
||||
def _products_from_xml(obj):
|
||||
return {'status': 'server', 'data': {'uno': 1}}
|
||||
|
||||
|
||||
def upload_file(rfc, opt, file_obj):
|
||||
if opt == 'productsadd':
|
||||
result = _products_from_xml(file_obj)
|
||||
return result
|
||||
|
|
|
@ -117,6 +117,12 @@ def upload_file(rfc, opt, file_obj):
|
|||
if opt == 'emisorlogo':
|
||||
return Emisor.save_logo(file_obj)
|
||||
|
||||
# ~ v2
|
||||
names = ('productsadd',)
|
||||
if opt in names:
|
||||
result = utils.upload_file(rfc, opt, file_obj)
|
||||
return result
|
||||
|
||||
result = util.upload_file(rfc, opt, file_obj)
|
||||
if result['ok']:
|
||||
names = ('bdfl', 'employees', 'nomina', 'products', 'invoiceods')
|
||||
|
|
|
@ -458,42 +458,53 @@ function cmd_add_products_from_xml_click(){
|
|||
//~ Upload XML
|
||||
function cmd_upload_products_from_xml_click(){
|
||||
var form = $$('form_upload_products_from_xml')
|
||||
var values = form.getValues()
|
||||
var list = $$('lst_up_products_from_xml')
|
||||
var upload = $$('up_products_from_xml')
|
||||
|
||||
$$('win_add_products_from_xml').close()
|
||||
if(!list.count()){
|
||||
$$('win_add_products_from_xml').close()
|
||||
return
|
||||
}
|
||||
|
||||
//~ var values = form.getValues()
|
||||
if(list.count() > 1){
|
||||
msg = 'Selecciona solo un archivo'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
//~ if(!$$('lst_upload_products').count()){
|
||||
//~ $$('win_import_products').close()
|
||||
//~ return
|
||||
//~ }
|
||||
var template = upload.files.getItem(upload.files.getFirstId())
|
||||
|
||||
//~ if($$('lst_upload_products').count() > 1){
|
||||
//~ msg = 'Selecciona solo un archivo'
|
||||
//~ msg_error(msg)
|
||||
//~ return
|
||||
//~ }
|
||||
if(template.type.toLowerCase() != 'xml'){
|
||||
msg = 'Archivo inválido.\n\nSe requiere un archivo XML'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
//~ var template = $$('up_products').files.getItem($$('up_products').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 Productos',
|
||||
//~ ok: 'Si',
|
||||
//~ cancel: 'No',
|
||||
//~ type: 'confirm-error',
|
||||
//~ text: msg,
|
||||
//~ callback:function(result){
|
||||
//~ if(result){
|
||||
//~ $$('up_products_from_xml').send()
|
||||
//~ }
|
||||
//~ }
|
||||
//~ })
|
||||
msg = '¿Estás seguro de importar este archivo?'
|
||||
webix.confirm({
|
||||
title: 'Importar Productos',
|
||||
ok: 'Si',
|
||||
cancel: 'No',
|
||||
type: 'confirm-error',
|
||||
text: msg,
|
||||
callback:function(result){
|
||||
if(result){
|
||||
upload.send()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function up_products_from_xml_upload_complete(response){
|
||||
if(response.status != 'server'){
|
||||
msg = 'Ocurrio un error al subir el archivo'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
$$('win_add_products_from_xml').close()
|
||||
msg = 'Archivo subido correctamente.\n\nComenzando importación.'
|
||||
msg_ok(msg)
|
||||
}
|
||||
|
|
|
@ -407,6 +407,6 @@ var win_add_products_from_xml = {
|
|||
body: body_add_products_from_xml,
|
||||
})
|
||||
$$('cmd_upload_products_from_xml').attachEvent('onItemClick', cmd_upload_products_from_xml_click)
|
||||
//~ $$('up_products').attachEvent('onUploadComplete', up_products_upload_complete)
|
||||
$$('up_products_from_xml').attachEvent('onUploadComplete', up_products_from_xml_upload_complete)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue