forked from elmau/empresa-libre
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]
|
rows = [r for r in reader]
|
||||||
return rows
|
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':
|
if opt == 'emisorlogo':
|
||||||
return Emisor.save_logo(file_obj)
|
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)
|
result = util.upload_file(rfc, opt, file_obj)
|
||||||
if result['ok']:
|
if result['ok']:
|
||||||
names = ('bdfl', 'employees', 'nomina', 'products', 'invoiceods')
|
names = ('bdfl', 'employees', 'nomina', 'products', 'invoiceods')
|
||||||
|
|
|
@ -458,42 +458,53 @@ function cmd_add_products_from_xml_click(){
|
||||||
//~ Upload XML
|
//~ Upload XML
|
||||||
function cmd_upload_products_from_xml_click(){
|
function cmd_upload_products_from_xml_click(){
|
||||||
var form = $$('form_upload_products_from_xml')
|
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()){
|
var template = upload.files.getItem(upload.files.getFirstId())
|
||||||
//~ $$('win_import_products').close()
|
|
||||||
//~ return
|
|
||||||
//~ }
|
|
||||||
|
|
||||||
//~ if($$('lst_upload_products').count() > 1){
|
if(template.type.toLowerCase() != 'xml'){
|
||||||
//~ msg = 'Selecciona solo un archivo'
|
msg = 'Archivo inválido.\n\nSe requiere un archivo XML'
|
||||||
//~ msg_error(msg)
|
msg_error(msg)
|
||||||
//~ return
|
return
|
||||||
//~ }
|
}
|
||||||
|
|
||||||
//~ var template = $$('up_products').files.getItem($$('up_products').files.getFirstId())
|
msg = '¿Estás seguro de importar este archivo?'
|
||||||
|
webix.confirm({
|
||||||
//~ if(template.type.toLowerCase() != 'ods'){
|
title: 'Importar Productos',
|
||||||
//~ msg = 'Archivo inválido.\n\nSe requiere un archivo ODS'
|
ok: 'Si',
|
||||||
//~ msg_error(msg)
|
cancel: 'No',
|
||||||
//~ return
|
type: 'confirm-error',
|
||||||
//~ }
|
text: msg,
|
||||||
|
callback:function(result){
|
||||||
//~ msg = '¿Estás seguro de importar este archivo?'
|
if(result){
|
||||||
//~ webix.confirm({
|
upload.send()
|
||||||
//~ title: 'Importar Productos',
|
}
|
||||||
//~ ok: 'Si',
|
}
|
||||||
//~ cancel: 'No',
|
})
|
||||||
//~ type: 'confirm-error',
|
|
||||||
//~ text: msg,
|
|
||||||
//~ callback:function(result){
|
|
||||||
//~ if(result){
|
|
||||||
//~ $$('up_products_from_xml').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,
|
body: body_add_products_from_xml,
|
||||||
})
|
})
|
||||||
$$('cmd_upload_products_from_xml').attachEvent('onItemClick', cmd_upload_products_from_xml_click)
|
$$('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