Importar carta porte desde json
This commit is contained in:
commit
d2f879c224
|
@ -1,3 +1,8 @@
|
|||
v 1.45.0 [20-Ene-2022]
|
||||
----------------------
|
||||
- Importar Carta Porte desde archivo JSON
|
||||
|
||||
|
||||
v 1.44.2 [19-Ene-2022]
|
||||
----------------------
|
||||
- Agregar opción STARTTLS que requieren algunos servidores de correo
|
||||
|
|
|
@ -956,7 +956,7 @@ class LIBO(object):
|
|||
self._set_cell(f'{{cp.{k}}}', v)
|
||||
|
||||
first = True
|
||||
count = len(ubicaciones)
|
||||
count = len(ubicaciones) - 1
|
||||
for i, ubicacion in enumerate(ubicaciones):
|
||||
tipo = ubicacion['TipoUbicacion']
|
||||
nombre = ubicacion['NombreRemitenteDestinatario']
|
||||
|
@ -973,7 +973,7 @@ class LIBO(object):
|
|||
cell_5 = self._set_cell('{cp.Domicilio}', domicilio)
|
||||
|
||||
row = cell_1.CellAddress.Row + 1
|
||||
self._sheet.getRows().insertByIndex(row, count - 1)
|
||||
self._sheet.getRows().insertByIndex(row, count)
|
||||
self._copy_paste_rows(cell_1, count)
|
||||
else:
|
||||
cell_1 = self._set_cell(v=tipo, cell=cell_1)
|
||||
|
@ -983,7 +983,7 @@ class LIBO(object):
|
|||
cell_5 = self._set_cell(v=domicilio, cell=cell_5)
|
||||
|
||||
first = True
|
||||
count = len(detalle)
|
||||
count = len(detalle) - 1
|
||||
for i, mercancia in enumerate(detalle):
|
||||
clave = mercancia['BienesTransp']
|
||||
descripcion = mercancia['Descripcion']
|
||||
|
@ -997,9 +997,9 @@ class LIBO(object):
|
|||
cell_3 = self._set_cell('{cp.ClaveUnidad}', unidad)
|
||||
cell_4 = self._set_cell('{cp.Cantidad}', cantidad)
|
||||
cell_5 = self._set_cell('{cp.PesoEnKg}', peso)
|
||||
if count > 1:
|
||||
if count > 0:
|
||||
row = cell_1.CellAddress.Row + 1
|
||||
self._sheet.getRows().insertByIndex(row, count - 1)
|
||||
self._sheet.getRows().insertByIndex(row, count)
|
||||
self._copy_paste_rows(cell_1, count)
|
||||
else:
|
||||
cell_1 = self._set_cell(v=clave, cell=cell_1)
|
||||
|
|
|
@ -783,8 +783,8 @@ def _cancel_with_cert(invoice, args, auth, certificado):
|
|||
|
||||
|
||||
def cancel_xml_sign(invoice, args, auth, certificado):
|
||||
# ~ if DEBUG:
|
||||
return _cancel_with_cert(invoice, args, auth, certificado)
|
||||
if DEBUG:
|
||||
return _cancel_with_cert(invoice, args, auth, certificado)
|
||||
|
||||
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
||||
pac = PACS[auth['pac']]()
|
||||
|
|
|
@ -161,6 +161,9 @@ class StorageEngine(object):
|
|||
def _get_unidades(self, values):
|
||||
return main.SATUnidades.get_activos()
|
||||
|
||||
def _get_unitbykey(self, values):
|
||||
return main.SATUnidades.get_activos_by_key()
|
||||
|
||||
def add_moneda(self, values):
|
||||
return main.SATMonedas.add(values)
|
||||
|
||||
|
|
|
@ -1511,6 +1511,17 @@ class SATUnidades(BaseModel):
|
|||
)
|
||||
return tuple(rows)
|
||||
|
||||
@classmethod
|
||||
def get_activos_by_key(cls):
|
||||
rows = (SATUnidades
|
||||
.select(
|
||||
SATUnidades.key.alias('id'),
|
||||
SATUnidades.name.alias('value'))
|
||||
.where(SATUnidades.activo==True)
|
||||
.dicts()
|
||||
)
|
||||
return tuple(rows)
|
||||
|
||||
@classmethod
|
||||
def remove(cls, id):
|
||||
with database_proxy.transaction():
|
||||
|
@ -5337,15 +5348,17 @@ class Facturas(BaseModel):
|
|||
total_weight = 0.00
|
||||
mercancias = values['mercancias']
|
||||
for mercancia in mercancias['mercancias']:
|
||||
mercancia['ClaveUnidad'] = SATUnidades.get_key_by_id(mercancia['ClaveUnidad'])
|
||||
total_weight += float(mercancia['PesoEnKg'])
|
||||
if isinstance(mercancia['PesoEnKg'], (int, float)):
|
||||
mercancia['PesoEnKg'] = f"{mercancia['PesoEnKg']:.2f}"
|
||||
mercancias['PesoBrutoTotal'] = f"{total_weight:.2f}"
|
||||
|
||||
ubicaciones = values['ubicaciones']
|
||||
for ubicacion in ubicaciones:
|
||||
if 'DistanciaRecorrida' in ubicacion:
|
||||
print(1, type(ubicacion['DistanciaRecorrida']), ubicacion['DistanciaRecorrida'])
|
||||
total_distance += float(ubicacion['DistanciaRecorrida'])
|
||||
if isinstance(ubicacion['DistanciaRecorrida'], (int, float)):
|
||||
ubicacion['DistanciaRecorrida'] = f"{ubicacion['DistanciaRecorrida']:.2f}"
|
||||
municipio = ubicacion.pop('Municipio')
|
||||
estado = ubicacion.pop('Estado')
|
||||
pais = ubicacion.pop('Pais')
|
||||
|
|
|
@ -42,7 +42,7 @@ except ImportError:
|
|||
|
||||
|
||||
DEBUG = DEBUG
|
||||
VERSION = '1.44.2'
|
||||
VERSION = '1.45.0'
|
||||
EMAIL_SUPPORT = ('soporte@empresalibre.mx',)
|
||||
TITLE_APP = '{} v{}'.format(TITLE_APP, VERSION)
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ var invoices_controllers = {
|
|||
$$('grid_carta_mercancias').attachEvent('onItemClick', grid_carta_mercancias_click)
|
||||
$$('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)
|
||||
|
||||
webix.extend($$('grid_invoices'), webix.ProgressBar)
|
||||
|
||||
|
@ -2637,7 +2638,7 @@ function _copy_from_invoice(){
|
|||
|
||||
function cmd_carta_copy_from_invoice_click(){
|
||||
msg = '¿Estás seguro de copiar los productos?<BR><BR> \
|
||||
Esto reemplazara todos los datos actuales'
|
||||
Esto reemplazara todos los datos actuales de las mercancías.'
|
||||
webix.confirm({
|
||||
title: 'Copiar productos',
|
||||
ok: 'Si',
|
||||
|
@ -2659,3 +2660,102 @@ function grid_carta_mercancias_click(id, e, node){
|
|||
}
|
||||
this.remove(id.row)
|
||||
}
|
||||
|
||||
|
||||
function _set_carta_porte_from_json(data){
|
||||
try{
|
||||
var values = JSON.parse(data)
|
||||
}catch(e){
|
||||
msg_error('Revisa el archivo JSON')
|
||||
webix.alert({
|
||||
title: 'Error al cargar JSON',
|
||||
text: e.message,
|
||||
type: 'alert-error'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var mercancias = values['mercancias']
|
||||
var ubicaciones = values['ubicaciones']
|
||||
var autotransporte = values['autotransporte']
|
||||
var operador = values['operador']
|
||||
|
||||
$$('lst_carta_UnidadPeso').setValue(values['unidad_de_peso'])
|
||||
var grid = $$('grid_carta_mercancias')
|
||||
grid.clearAll()
|
||||
mercancias.forEach(function(row, index){
|
||||
var data = new Object()
|
||||
data['delete'] = '-'
|
||||
data['BienesTransp'] = row.clave_sat
|
||||
data['Descripcion'] = row.descripcion
|
||||
data['Cantidad'] = row.cantidad
|
||||
data['ClaveUnidad'] = row.clave_unidad
|
||||
data['PesoEnKg'] = row.peso_en_kg
|
||||
grid.add(data)
|
||||
})
|
||||
|
||||
var grid = $$('grid_carta_ubicaciones')
|
||||
grid.clearAll()
|
||||
ubicaciones.forEach(function(row, index){
|
||||
var data = new Object()
|
||||
data['delete'] = '-'
|
||||
data['TipoUbicacion'] = row.tipo
|
||||
data['RFCRemitenteDestinatario'] = row.rfc
|
||||
data['NombreRemitenteDestinatario'] = row.nombre
|
||||
data['FechaHoraSalidaLlegada'] = new Date(row.fecha)
|
||||
if('distancia' in row){
|
||||
data['DistanciaRecorrida'] = row.distancia
|
||||
}
|
||||
data['Municipio'] = row.municipio
|
||||
data['Estado'] = row.estado
|
||||
data['Pais'] = 'MEX'
|
||||
data['CodigoPostal'] = row.codigo_postal
|
||||
grid.add(data)
|
||||
})
|
||||
|
||||
var grid = $$('grid_carta_autotransporte')
|
||||
grid.clearAll()
|
||||
var data = new Object()
|
||||
data['PermSCT'] = autotransporte.tipo_permiso
|
||||
data['NumPermisoSCT'] = autotransporte.numero
|
||||
data['ConfigVehicular'] = autotransporte.clave
|
||||
data['PlacaVM'] = autotransporte.placa
|
||||
data['AnioModeloVM'] = autotransporte.modelo
|
||||
if('remolque' in autotransporte){
|
||||
data['SubTipoRem'] = autotransporte.remolque
|
||||
data['Placa'] = autotransporte.placa_remolque
|
||||
}
|
||||
data['AseguraRespCivil'] = autotransporte.aseguradora
|
||||
data['PolizaRespCivil'] = autotransporte.poliza
|
||||
grid.add(data)
|
||||
|
||||
var grid = $$('grid_carta_tipos_figuras')
|
||||
grid.clearAll()
|
||||
var data = new Object()
|
||||
data['TipoFigura'] = '01'
|
||||
if('tipo' in operador){
|
||||
data['TipoFigura'] = operador.tipo
|
||||
}
|
||||
data['RFCFigura'] = operador.rfc
|
||||
data['NombreFigura'] = operador.nombre
|
||||
data['NumLicencia'] = operador.licencia
|
||||
grid.add(data)
|
||||
|
||||
$$('chk_cfdi_usar_cartaporte').setValue(1)
|
||||
}
|
||||
|
||||
|
||||
function cmd_carta_import_json_click(){
|
||||
win_carta_import_json.init()
|
||||
$$('win_carta_import_json').show()
|
||||
}
|
||||
|
||||
|
||||
function up_invoice_json_on_after_file_add(obj){
|
||||
let reader = new FileReader()
|
||||
reader.readAsText(obj.file)
|
||||
reader.onload = function(){
|
||||
_set_carta_porte_from_json(reader.result)
|
||||
}
|
||||
$$('win_carta_import_json').close()
|
||||
}
|
||||
|
|
|
@ -928,7 +928,7 @@ var grid_cols_carta_mercancias = [
|
|||
{id: 'BienesTransp', header: 'Clave SAT', editor: 'text', fillspace: 1},
|
||||
{id: 'Descripcion', header: 'Descripción', editor: 'text', fillspace: 1},
|
||||
{id: 'Cantidad', header: 'Cantidad', editor: 'text', format: webix.i18n.numberFormat, css: 'right', fillspace: 1},
|
||||
{id: 'ClaveUnidad', header: 'Unidad', editor: 'select', options: 'values/unidades', footer: 'Total peso:', fillspace: 1},
|
||||
{id: 'ClaveUnidad', header: 'Unidad', editor: 'select', options: 'values/unitbykey', footer: 'Total peso:', fillspace: 1},
|
||||
//~ {id: 'ValorMercancia', header: 'Valor Mercancia', format: webix.i18n.priceFormat, css: 'right', footer: 'Total peso:', fillspace: 1},
|
||||
{id: 'PesoEnKg', header: 'Peso (Kg)', format: webix.i18n.numberFormat, css: 'right', editor: 'text', footer: {content: 'summColumn', css: 'right'}, fillspace: 1},
|
||||
]
|
||||
|
@ -1139,8 +1139,12 @@ var body_carta_tipos_figuras = {rows:[
|
|||
var controls_carta_porte = [
|
||||
{cols: [{maxWidth: 15},
|
||||
{view: 'checkbox', id: 'chk_cfdi_usar_cartaporte', labelWidth: 0,
|
||||
labelRight: 'Usar el complemento Carta Porte'},
|
||||
{}]},
|
||||
labelRight: 'Usar el complemento Carta Porte'}, {},
|
||||
{view: 'button', id: 'cmd_carta_import_json', label: 'Importar JSON',
|
||||
icon: 'upload', type: 'iconButton', autowidth: true, align: 'center'},
|
||||
{view: 'button', id: 'cmd_carta_import_ods', label: 'Importar ODS',
|
||||
icon: 'upload', type: 'iconButton', autowidth: true, align: 'center'},
|
||||
{maxWidth: 15}]},
|
||||
{view: 'fieldset', label: 'Mercancias', body: body_carta_mercancias},
|
||||
{cols: [{maxWidth: 15},
|
||||
{view: 'richselect', id: 'lst_carta_TranspInternac', labelPosition: 'top',
|
||||
|
@ -1300,3 +1304,35 @@ var win_invoice_cancel = {
|
|||
$$('cmd_win_cancel_close').attachEvent('onItemClick', cmd_win_cancel_close_click)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var body_upload_carta_json = {rows: [
|
||||
{view: 'form', id: 'form_upload_carta', rows: [
|
||||
{cols: [{},
|
||||
{view: 'uploader', id: 'up_invoice_json', autosend: false,
|
||||
link: 'lst_upload_invoice', value: 'Seleccionar Archivo',
|
||||
accept:'application/json', upload: ''}, {}]},
|
||||
{cols: [
|
||||
{view: 'list', id: 'lst_upload_invoice', name: 'lst_upload_invoice',
|
||||
type: 'uploader', autoheight: true, borderless: true}]},
|
||||
//~ {cols: [{}, {view: 'button', id: 'cmd_upload_invoice',
|
||||
//~ label: 'Importar Factura'}, {}]},
|
||||
]},
|
||||
]}
|
||||
|
||||
|
||||
var win_carta_import_json = {
|
||||
init: function(){
|
||||
webix.ui({
|
||||
view: 'window',
|
||||
id: 'win_carta_import_json',
|
||||
width: 400,
|
||||
modal: true,
|
||||
position: 'center',
|
||||
head: 'Importar Carta Porte JSON',
|
||||
body: body_upload_carta_json,
|
||||
})
|
||||
//~ $$('cmd_upload_invoice').attachEvent('onItemClick', cmd_upload_invoice_click)
|
||||
$$('up_invoice_json').attachEvent('onAfterFileAdd', up_invoice_json_on_after_file_add)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue