def actualizar_productos(self, objeto, user_id, ip): fecha = BitacoraManager(self.db).fecha_actual() for i in objeto.detalle: objeto_inventario = self.db.query(self.entity).filter( self.entity.fksucursal == objeto.fksucursal).filter( self.entity.fkproducto == i.fkproducto).first() if objeto_inventario: nueva_cantidad = int(i.cantidad) + int( objeto_inventario.cantidad) objeto_inventario.cantidad = nueva_cantidad a = super().update(objeto_inventario) else: dict_inventario = dict(cantidad=i.cantidad, fkproducto=i.fkproducto, fksucursal=objeto.fksucursal) objeto = InventarioManager(self.db).entity(**dict_inventario) a = super().insert(objeto) b = Bitacora(fkusuario=user_id, ip=ip, accion="Registró entrada del inventario.", fecha=fecha, tabla="negocio_inventario", identificador=a.id) super().insert(b)
def update(self, objeto): fecha = BitacoraManager(self.db).fecha_actual() a = super().update(objeto) b = Bitacora(fkusuario=objeto.user, ip=objeto.ip, accion="Modificó producto.", fecha=fecha,tabla="negocio_producto", identificador=a.id) super().insert(b) return a
def transaccion_item(self, item): ip = item['ip'] user = item['user'] accion = item['accion'] idsucursal = item['fksucursal'] cantidad = int(item['cantidad']) idproducto = int(item['fkproducto']) fecha = BitacoraManager(self.db).fecha_actual() obj_invent = self.db.query( self.entity).filter(self.entity.fksucursal == idsucursal).filter( self.entity.fkproducto == idproducto).first() mensaje = "Registró entrada del inventario." if accion == 'ingreso' else "Registró salida del inventario." if obj_invent: obj_invent.cantidad += int( cantidad) if accion == 'ingreso' else -int(cantidad) a = super().update(obj_invent) else: dict_inventario = dict(cantidad=cantidad, fkproducto=idproducto, fksucursal=idsucursal) objeto = InventarioManager(self.db).entity(**dict_inventario) a = super().insert(objeto) b = Bitacora(fkusuario=user, ip=ip, accion=mensaje, fecha=fecha, tabla="negocio_inventario", identificador=a.id) super().insert(b)
def post(self): """Inicia sesión en la aplicación. Si se inicia sesión con éxito enctonces se guarda el usuario en la cookie caso contrario se vuelve al login. """ self.check_xsrf_cookie() ip = self.request.remote_ip diccionary = json.loads(self.get_argument("object")) username = diccionary['username'] password = diccionary['password'] with transaction() as db: pass if username is not None and password is not None: user = LoginManager().login(username, password) if user: fecha = self.fecha_actual() b = Bitacora(fkusuario=user.id, ip=ip, accion="Inicio de sesión.", fecha=fecha) self.insertar_bitacora(b) self.set_user_id(user.id) self.respond(success=True, message='Sesión iniciada correctamente.') else: userb = LoginManager().not_enabled(username, password) if userb: self.render("sistema/usuarios/login/views/index.html", error=1) else: self.render("sistema/usuarios/login/views/index.html", error=2) else: self.render("sistema/usuarios/login/views/index.html", error=0)
def insert(self, diccionary): usuario = UsuarioManager(self.db).entity(**diccionary) user = self.db.query(Usuario).filter( Usuario.username == usuario.username).first() if user: return dict(response=None, success=False, message="Ya se le creo un usuario al personal") else: usuario.password = hashlib.sha512( usuario.password.encode()).hexdigest() codigo = self.get_random_string() Usuario.codigo = codigo _objeto = super().insert(usuario) fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=usuario.user_id, ip=usuario.ip, accion="Se registró un usuario.", fecha=fecha, identificador=_objeto.id) super().insert(b) _dict = _objeto.get_dict() return dict(response=_dict, success=True, message="Insertado correctamente")
def delete(self, id, user, ip): x = self.db.query(self.entity).filter(self.entity.id == id).one() x.enabled = False fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=user, ip=ip, accion="Eliminó producto", fecha=fecha, tabla="negocio_producto", identificador=id) super().insert(b) self.db.merge(x) self.db.commit()
def update(self, rol): fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=rol.user, ip=rol.ip, accion="Se modificó un rol.", fecha=fecha) super().insert(b) a = super().update(rol) return a
def insert(self, rol): fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=rol.user, ip=rol.ip, accion="Se registró un rol.", fecha=fecha) super().insert(b) a = super().insert(rol) return a
def state(self, id, estado, user, ip): x = self.db.query(self.entity).filter(self.entity.id == id).one() mensaje = "Habilitó producto" if estado else "Deshabilitó producto" x.estado = estado fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=user, ip=ip, accion=mensaje, fecha=fecha, tabla="negocio_producto", identificador=id) super().insert(b) self.db.merge(x) self.db.commit() return x
def get(self): try: user_id = self.get_user_id() ip = self.request.remote_ip fecha = self.fecha_actual() b = Bitacora(fkusuario=user_id, ip=ip, accion="Finalizó sesión.", fecha=fecha) self.insertar_bitacora(b) self.clear_cookie('user') self.redirect(self.get_argument("next", "/")) except Exception as e: self.clear_cookie('user') self.redirect(self.get_argument("next", "/"))
def insert(self, objeto): fecha = BitacoraManager(self.db).fecha_actual() a = super().insert(objeto) b = Bitacora(fkusuario=objeto.user, ip=objeto.ip, accion="Registró sucursal.", fecha=fecha, tabla="negocio_sucursal", identificador=a.id) super().insert(b) return a
def update(self, persona): fecha = BitacoraManager(self.db).fecha_actual() a = super().update(persona) b = Bitacora(fkusuario=persona.user, ip=persona.ip, accion="Modificó persona.", fecha=fecha, tabla="usuarios_persona", identificador=a.id) super().insert(b) return a
def insert_person(self, personadt): fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=personadt.user, ip=personadt.ip, accion="Se registró una persona.", fecha=fecha, tabla="usuarios_persona") super().insert(personadt) super().insert(b) return dict(respuesta=True, Mensaje="Insertado correctamente", data=personadt.id)
def delete(self, id, estado, user, ip): x = self.db.query(Persona).filter(Persona.id == id).one() message = "Habilitó persona." if estado else "Inhabilitó persona." x.enabled = estado fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=user, ip=ip, accion=message, fecha=fecha, tabla="usuarios_persona") super().insert(b) self.db.merge(x) self.db.commit() return True
def state(self, id, estado, userid, ip): x = self.db.query(self.entity).filter(self.entity.id == id).one() x.estado = estado neg_estado = not estado message = "Se habilitó un rol." if estado else "Se inhabilitó un rol y usuarios relacionados." users = self.db.query(Usuario).filter( Usuario.estado == neg_estado).filter(Usuario.fkrol == id).all() for u in users: u.estado = estado fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=userid, ip=ip, accion=message, fecha=fecha) super().insert(b) self.db.merge(x) self.db.commit() return True
def update(self, usuario): if not usuario.password or usuario.password == '': usuario.password = (self.db.query( Usuario.password).filter(Usuario.id == usuario.id).first())[0] else: usuario.password = hashlib.sha512( usuario.password.encode()).hexdigest() fecha = BitacoraManager(self.db).fecha_actual() a = super().update(usuario) b = Bitacora(fkusuario=usuario.user_id, ip=usuario.ip, accion="Modificó Usuario.", fecha=fecha, tabla="cb_usuarios_usuario", identificador=a.id) super().insert(b) return a
def state(self, id, estado, userid, ip): x = self.db.query(Usuario).filter(Usuario.id == id).one() if estado: r = self.db.query(Rol).filter(Rol.id == x.fkrol).one() if r.estado and r.enabled: x.estado = estado else: return False message = "Se habilitó un usuario." else: x.estado = estado message = "Se inhabilitó un usuario." fecha = BitacoraManager(self.db).fecha_actual() b = Bitacora(fkusuario=userid, ip=ip, accion=message, fecha=fecha) super().insert(b) self.db.merge(x) self.db.commit() return True