Nuevos controles para carta porte terminada

This commit is contained in:
El Mau 2021-12-30 19:41:40 -06:00
parent 46d6329754
commit 2f22ad4cc8
8 changed files with 327 additions and 1 deletions

View File

@ -769,3 +769,21 @@ class AppUsers(object):
user = req.env['beaker.session']['userobj']
req.context['result'] = self._db.users_post(values, user)
resp.status = falcon.HTTP_200
class AppSATUnidadesPeso(object):
def __init__(self, db):
self._db = db
def on_get(self, req, resp):
values = req.params
user = req.env['beaker.session']['userobj']
req.context['result'] = self._db.sat_unidades_peso_get(values, user)
resp.status = falcon.HTTP_200
def on_post(self, req, resp):
values = req.params
user = req.env['beaker.session']['userobj']
req.context['result'] = self._db.sat_unidades_peso_post(values, user)
resp.status = falcon.HTTP_200

View File

@ -251,6 +251,26 @@ def get_sat_unidades(key):
return tuple(data)
def get_sat_unidadespeso(key):
con = sqlite3.connect(DB_SAT)
con.row_factory = sqlite3.Row
cursor = con.cursor()
filtro = '%{}%'.format(key)
sql = "SELECT * FROM unidad_peso WHERE key LIKE ? OR name LIKE ?"
cursor.execute(sql, [filtro, filtro])
data = cursor.fetchall()
cursor.close()
con.close()
if data is None:
return ()
data = tuple([dict(r) for r in data])
return data
def get_sat_productos(key):
con = sqlite3.connect(DB_SAT)
con.row_factory = sqlite3.Row

View File

@ -24,6 +24,7 @@ from controllers.main import (AppEmpresas,
AppUsers,
AppWareHouse,
AppWareHouseProduct,
AppSATUnidadesPeso,
)
@ -76,6 +77,7 @@ api.add_route('/warehouse', AppWareHouse(db))
api.add_route('/warehouseproduct', AppWareHouseProduct(db))
api.add_route('/ticketsdetails', AppTicketsDetails(db))
api.add_route('/users', AppUsers(db))
api.add_route('/satunidadespeso', AppSATUnidadesPeso(db))
session_options = {

View File

@ -236,6 +236,9 @@ class StorageEngine(object):
def _get_satunidades(self, values):
return main.get_sat_unidades(values['key'])
def _get_satunidadespeso(self, values):
return main.get_sat_unidadespeso(values['key'])
def _get_satproductos(self, values):
return main.get_sat_productos(values['key'])
@ -514,6 +517,12 @@ class StorageEngine(object):
def nomina_get(self, filters, user):
return main.CfdiNomina.get_data(filters, user)
def sat_unidades_peso_get(self, filters, user):
return main.SATUnidadesPeso.get_data(filters, user)
def sat_unidades_peso_post(self, args, user):
return main.SATUnidadesPeso.post(args, user)
# Companies only in MV
def _get_empresas(self, values):
return main.companies_get()

View File

@ -1358,6 +1358,77 @@ class CondicionesPago(BaseModel):
return obj
class SATUnidadesPeso(BaseModel):
key = TextField(unique=True, index=True)
name = TextField(default='', index=True)
activo = BooleanField(default=False)
class Meta:
order_by = ('name',)
indexes = (
(('key', 'name'), True),
)
def __str__(self):
return '{} ({})'.format(self.name, self.key)
@classmethod
def _get_all(cls, values, user):
rows = tuple(SATUnidadesPeso.select().dicts())
return rows
@classmethod
def _get_active(cls, values, user):
fields = (
SATUnidadesPeso.key.alias('id'),
SATUnidadesPeso.name.alias('value'),
)
where = (SATUnidadesPeso.activo==True)
rows = tuple(
SATUnidadesPeso.select(*fields).where(where).dicts()
)
return rows
@classmethod
def get_data(cls, values, user):
opt = values.pop('opt')
return getattr(cls, f'_get_{opt}')(values, user)
@classmethod
def _add(cls, values, user):
result = True
try:
SATUnidadesPeso.create(**values)
except:
result = False
return {'ok': result}
@classmethod
def _delete(cls, values, user):
id = values['id']
q = SATUnidadesPeso.delete().where(SATUnidadesPeso.id==id)
result = bool(q.execute())
response = {'ok': result}
return response
@classmethod
def _update_active(cls, values, user):
id = values['id']
update = {'activo': bool(values['activo'])}
where = (SATUnidadesPeso.id==id)
q = SATUnidadesPeso.update(**update).where(where)
result = bool(q.execute())
response = {'ok': result}
return response
@classmethod
def post(cls, values, user):
opt = values['opt']
args = utils.loads(values['values'])
return getattr(cls, f'_{opt}')(args, user)
class SATUnidades(BaseModel):
key = TextField(unique=True, index=True)
name = TextField(default='', index=True)
@ -10249,6 +10320,10 @@ def get_sat_unidades(key):
return util.get_sat_unidades(key)
def get_sat_unidadespeso(key):
return util.get_sat_unidadespeso(key)
def get_sat_productos(key):
return util.get_sat_productos(key)
@ -10345,6 +10420,7 @@ def _crear_tablas(rfc):
InventoryEntries,
PartnerInvoices,
WareHouseProduct,
SATUnidadesPeso,
]
log.info('Creando tablas...')
database_proxy.create_tables(tablas, True)
@ -10402,6 +10478,7 @@ def _migrate_tables(rfc=''):
InventoryEntries,
PartnerInvoices,
WareHouseProduct,
SATUnidadesPeso,
]
log.info('Creando tablas nuevas...')
database_proxy.create_tables(tablas, True)

View File

@ -160,6 +160,10 @@ var controllers = {
$$('cmd_add_sucursal').attachEvent('onItemClick', cmd_add_sucursal_click)
$$('grid_sucursales').attachEvent('onItemClick', grid_sucursales_click)
//~ Carta Porte
$$('grid_unidadpeso_found').attachEvent('onValueSuggest', grid_unidadpeso_found_click)
$$('grid_carta_unidades_peso').attachEvent('onItemClick', grid_carta_unidades_peso_click)
$$('grid_carta_unidades_peso').attachEvent('onCheck', grid_carta_unidades_peso_on_check)
}
}
@ -1568,6 +1572,27 @@ function agregar_nueva_unidad(obj){
}
function agregar_nueva_unidadpeso(obj){
var grid = $$('grid_carta_unidades_peso')
var args = {
opt: 'add',
values: {key: obj.key, name: obj.name},
}
webix.ajax().post('/satunidadespeso', args, {
error: function(text, data, xhr) {
webix.message({type: 'error', text: 'Error al agregar'})
},
success: function(text, data, xhr){
var values = data.json()
if (values.ok){
grid.add(obj)
}
}
})
}
function grid_unidad_found_click(obj){
msg = '¿Estás seguro de agregar la siguiente unidad?'
msg += '(' + obj.key + ')<BR>'
@ -1589,6 +1614,27 @@ function grid_unidad_found_click(obj){
}
function grid_unidadpeso_found_click(obj){
msg = '¿Estás seguro de agregar la siguiente unidad?'
msg += '(' + obj.key + ')<BR>'
msg += obj.name
webix.confirm({
title: 'Agregar Unidad',
ok: 'Si',
cancel: 'No',
type: 'confirm-error',
text: msg,
callback:function(result){
if(result){
agregar_nueva_unidadpeso(obj)
}
}
})
$$('buscar_carta_unidades_peso').setValue('')
}
function agregar_impuesto(impuesto, tasa){
var grid = $$('grid_admin_taxes')
var values = {impuesto: impuesto, tasa: tasa}
@ -3178,3 +3224,71 @@ function grid_warehouse_click(id, e, node){
}
})
}
function delete_unit_weight(id){
var grid = $$('grid_carta_unidades_peso')
var values = {
opt: 'delete',
values: {id: id},
}
webix.ajax().post('/satunidadespeso', values, {
error:function(text, data, XmlHttpRequest){
msg = 'Ocurrio un error, consulta a soporte técnico'
msg_error(msg)
},
success:function(text, data, XmlHttpRequest){
var values = data.json()
if(values.ok){
grid.remove(id)
msg_ok('Unidad de Peso eliminada correctamente')
}else{
msg_error(values.msg)
}
}
})
}
function grid_carta_unidades_peso_click(id, e, node){
if(id.column != 'delete'){
return
}
msg = '¿Estás seguro de borrar la Unidad de Peso seleccionada?'
webix.confirm({
title: 'Borrar Unidad',
ok: 'Si',
cancel: 'No',
type: 'confirm-error',
text: msg,
callback:function(result){
if(result){
delete_unit_weight(id.row)
}
}
})
}
function grid_carta_unidades_peso_on_check(row, column, state){
var values = {
opt: 'update_active',
values: {id: row, activo: state},
}
webix.ajax().post('/satunidadespeso', values, {
error:function(text, data, XmlHttpRequest){
msg = 'Ocurrio un error, consulta a soporte técnico'
msg_error(msg)
},
success:function(text, data, XmlHttpRequest){
var values = data.json()
if(!values.ok){
msg_error(values.msg)
}
}
})
}

View File

@ -1303,6 +1303,91 @@ var sat_usos_cfdi = [
]
var suggest_sat_unidades_peso = {
view: 'gridsuggest',
id: 'grid_unidadpeso_found',
name: 'grid_unidadpeso_found',
body: {
autoConfig: false,
scroll:true,
autoheight:false,
header: true,
yCount: 10,
columns: [
{id: 'id', hidden: true},
{id: 'key', adjust: 'data', header: 'Clave'},
{id: 'name', adjust: 'data', header: 'Unidad'},
],
dataFeed:function(text){
if (text.length > 1){
this.load('/values/satunidadespeso?key=' + text)
}else{
this.hide()
}
}
},
}
var buscar_carta_unidades_peso = {
view: 'search',
id: 'buscar_carta_unidades_peso',
label: 'Buscar Unidad de Peso en el catálogo del SAT',
labelPosition: 'top',
suggest: suggest_sat_unidades_peso,
placeholder: 'Por clave o descripción. Captura al menos tres letras',
}
var columns_carta_unidades_peso = [
{id: 'id', header: 'ID', hidden: true},
{id: 'delete', header: '', width: 30, css: 'delete'},
{id: 'key', header: 'Clave'},
{id: 'name', header: 'Nombre', adjust: 'data'},
{id: 'activo', header: 'Activo', template: '{common.checkbox()}',
editor: 'checkbox'},
]
var grid_carta_unidades_peso = {
view: 'datatable',
id: 'grid_carta_unidades_peso',
url: 'satunidadespeso?opt=all',
select: 'cell',
adjust: true,
autowidth: true,
headermenu: true,
columns: columns_carta_unidades_peso,
on:{
'data->onStoreUpdated':function(){
this.data.each(function(obj, i){
obj.delete = '-'
})
}
},
}
var carta_porte_unidades_peso = [
{maxHeight: 20},
{cols: [{maxWidth: 15}, buscar_carta_unidades_peso, {}]},
{maxHeight: 20},
{cols: [{maxWidth: 15}, grid_carta_unidades_peso, {}]},
{maxHeight: 20},
]
var tab_sat_carta_porte = [{
view: 'tabview',
id: 'tab_sat_carta_porte',
multiview: true,
animate: true,
cells: [
{id: 'Unidades de Peso', rows: carta_porte_unidades_peso},
]
}]
var tab_sat = {
view: 'tabview',
id: 'tab_sat',
@ -1315,6 +1400,7 @@ var tab_sat = {
{id: 'Unidades', rows: sat_unidades},
{id: 'Formas de Pago', rows: sat_formasdepago},
{id: 'Usos de CFDI', rows: sat_usos_cfdi},
{id: 'Carta Porte', rows: tab_sat_carta_porte},
],
}

View File

@ -973,7 +973,7 @@ var grid_carta_tipos_figuras = {
var body_carta_mercancias = {rows:[
{cols: [{view: 'richselect', id: 'lst_carta_UnidadPeso', labelPosition: 'top',
label: 'Unidad de Peso', maxWidth: 300, options: []}, {}
label: 'Unidad de Peso', maxWidth: 300, options: '/satunidadespeso?opt=active'}, {}
]},
{maxHeight: 10},
grid_carta_mercancias,