Buscar Estado y Municipio por CP en Carta Porte
This commit is contained in:
parent
fe3f743e32
commit
61548c9135
|
@ -10378,7 +10378,7 @@ def get_cp(cp):
|
|||
con = sqlite3.connect(PATH_CP)
|
||||
cursor = con.cursor()
|
||||
sql = """
|
||||
SELECT colonia, municipio, estado
|
||||
SELECT colonia, municipio, estado, municipios.id_municipio
|
||||
FROM colonias, municipios, estados
|
||||
WHERE colonias.id_municipio=municipios.id
|
||||
AND municipios.id_estado=estados.id
|
||||
|
@ -10394,7 +10394,9 @@ def get_cp(cp):
|
|||
data = {
|
||||
'estado': rows[0][2],
|
||||
'municipio': rows[0][1],
|
||||
'key_municipio': str(rows[0][3]).zfill(3),
|
||||
}
|
||||
print(data)
|
||||
if len(rows) == 1:
|
||||
data['colonia'] = rows[0][0]
|
||||
else:
|
||||
|
|
|
@ -90,6 +90,7 @@ var invoices_controllers = {
|
|||
tv_invoice.attachEvent('onChange', tv_invoice_change)
|
||||
|
||||
$$('grid_carta_mercancias').attachEvent('onItemClick', grid_carta_mercancias_click)
|
||||
$$('grid_carta_ubicaciones').attachEvent('onBeforeEditStop', grid_carta_ubicaciones_before_edit_stop)
|
||||
$$('cmd_carta_add_product').attachEvent('onItemClick', cmd_carta_add_product_click)
|
||||
$$('cmd_carta_copy_from_invoice').attachEvent('onItemClick', cmd_carta_copy_from_invoice_click)
|
||||
$$('cmd_carta_import_json').attachEvent('onItemClick', cmd_carta_import_json_click)
|
||||
|
@ -1120,6 +1121,68 @@ function grid_details_before_edit_start(id){
|
|||
}
|
||||
|
||||
|
||||
function grid_carta_ubicaciones_before_edit_stop(state, editor){
|
||||
if(editor.column != 'CodigoPostal'){
|
||||
return true
|
||||
}
|
||||
|
||||
var g = $$('grid_carta_ubicaciones')
|
||||
var row = g.getItem(editor.row)
|
||||
var cp = state.value.trim()
|
||||
|
||||
if(!cp){
|
||||
msg = 'El Código Postal no puede estar vacío'
|
||||
msg_error(msg)
|
||||
g.blockEvent()
|
||||
state.value = state.old
|
||||
g.editCancel()
|
||||
g.unblockEvent()
|
||||
return true
|
||||
}
|
||||
|
||||
if(cp.length != 5){
|
||||
msg = 'El Código Postal debe ser de 5 digitos'
|
||||
msg_error(msg)
|
||||
g.blockEvent()
|
||||
state.value = state.old
|
||||
g.editCancel()
|
||||
g.unblockEvent()
|
||||
return true
|
||||
}
|
||||
|
||||
if(cp.match(/\d/) == null){
|
||||
msg = 'El Código Postal deben ser solo digitos'
|
||||
msg_error(msg)
|
||||
g.blockEvent()
|
||||
state.value = state.old
|
||||
g.editCancel()
|
||||
g.unblockEvent()
|
||||
return true
|
||||
}
|
||||
|
||||
webix.ajax().get('/values/cp', {cp: cp}, {
|
||||
error: function(text, data, xhr) {
|
||||
msg_error('Error al consultar el C.P.')
|
||||
},
|
||||
success: function(text, data, xhr) {
|
||||
var values = data.json();
|
||||
if (values.estado == undefined){
|
||||
msg = 'No se encontró el C.P., asegurate de que sea correcto'
|
||||
msg_error(msg)
|
||||
} else {
|
||||
row['Estado'] = opt_carta_estados.find(x => x.value === values.estado).id
|
||||
row['Municipio'] = values.key_municipio
|
||||
//~ $$('colonia').define('suggest', [])
|
||||
//~ $$('colonia').define('suggest', values.colonia)
|
||||
//~ $$('colonia').refresh()
|
||||
g.refresh()
|
||||
msg_ok('Municipio:\n' + values.municipio)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function grid_details_before_edit_stop(state, editor){
|
||||
var row = grid.getItem(editor.row)
|
||||
|
||||
|
|
Loading…
Reference in New Issue