Ejemplo n.º 1
0
 def setQuery(self,  str,  db=None):
     if db == None:
         self.query = QSqlQuery(str)
     else:
         self.query = str
     QSqlQueryModel.setQuery(self,  str)
     del self.data
     self.data = []
     self.rCount = QSqlQueryModel.rowCount(self)
     if self.rCount > 10000:
         self.rCount = 10000
     self.cCount = QSqlQueryModel.columnCount(self)
     for i in range(self.rCount ):
         row = []
         for j in range(self.cCount):
             row.append(QSqlQueryModel.data(self, QSqlQueryModel.index(self, i, j)))
         self.data.append(row)
     self.clear()
     print self.rowCount(), self.columnCount()
Ejemplo n.º 2
0
 def setQuery(self, str, db=None):
     if db == None:
         self.query = QSqlQuery(str)
     else:
         self.query = str
     QSqlQueryModel.setQuery(self, str)
     del self.data
     self.data = []
     self.rCount = QSqlQueryModel.rowCount(self)
     if self.rCount > 10000:
         self.rCount = 10000
     self.cCount = QSqlQueryModel.columnCount(self)
     for i in range(self.rCount):
         row = []
         for j in range(self.cCount):
             row.append(
                 QSqlQueryModel.data(self, QSqlQueryModel.index(self, i,
                                                                j)))
         self.data.append(row)
     self.clear()
     print self.rowCount(), self.columnCount()
Ejemplo n.º 3
0
class DlgApertura ( QDialog, Ui_dlgApertura ):
    def __init__( self, parent, cerrar = False ):
        """
        Constructor para agregar un nuevo articulo
        """
        super( DlgApertura, self ).__init__( parent )
        self.parentWindow = parent
        self.setupUi( self )
        
        self.fechaApertura = None
        self.capitalMaximo = Decimal(0)
        self.editmodel = AperturaModel( parent.datosSesion )
        
        self.cerrar = cerrar


        self.txtUsuario.setText( parent.user.user )
        self.txtUsuario.setReadOnly( True )

#        self.txtUser.setFocus()
        self.txtPassword.setEchoMode( QLineEdit.Password )
        self.setWindowIcon( QIcon( ":/icons/res/logo.png" ) )


        self.txtSaldoC.setAlignment( Qt.AlignRight )
        self.txtSaldoD.setAlignment( Qt.AlignRight )
        self.txtSaldoC.setPrefix("C$")
        self.txtSaldoD.setPrefix("US$")
        
        self.supervisor = None

        if cerrar:
            self.swcaja.setCurrentIndex( 1 )
            self.txtcaja.setText( parent.cajaNombre )
            self.txtcaja.setReadOnly( True )
            self.editmodel.cajaId = parent.datosSesion.cajaId

        else:
            self.swcaja.setCurrentIndex( 0 )
            self.cajasmodel = QSqlQueryModel()
            try:
                if not QSqlDatabase.database().isOpen():
                    if not QSqlDatabase.database().open():
                        raise UserWarning( u"No se pudo abrir la conexión "
                                           + "con la base de datos" )

                
                q = """
                SELECT
                    d.idcaja,
                    c.descripcion,
                    SUM(IF(m.idtipomoneda = %d,m.monto,0)) AS totalC,
                    SUM(IF(m.idtipomoneda = %d,m.monto,0)) AS totalD
                FROM
                movimientoscaja m
                JOIN documentos d ON d.iddocumento = m.iddocumento
                JOIN cajas c ON c.idcaja = d.idcaja
                WHERE d.idcaja is not null AND m.idtipomovimiento=%d
                GROUP BY  d.idcaja;""" % ( constantes.IDCORDOBAS,
                        constantes.IDDOLARES, constantes.IDPAGOEFECTIVO)
                self.cajasmodel.setQuery( q )
                if self.cajasmodel.rowCount() == 0:
                    q = """
                    SELECT
                        c.idcaja,
                        c.descripcion,
                        0 AS totalC,
                        0 AS totalD
                    FROM cajas c;
                    """
                    self.cajasmodel.setQuery( q )
#                    FIXME:Esto no funciona en el caso de que hallan varias cajas y solo 
                    if self.cajasmodel.rowCount() == 0:
                        QMessageBox.critical( self, qApp.organizationName(),
                                         "No existe ninguna caja en la base de datos" )

                query = QSqlQuery( """
                SELECT
                    fechacreacion
                    FROM esquipulasdb.documentos d
                    LEFT JOIN personasxdocumento pd ON pd.iddocumento = d.iddocumento
                    WHERE pd.idpersona = %d AND idtipodoc =%d;
                    """ % ( self.editmodel.datosSesion.usuarioId,
                            constantes.IDARQUEO ) )
                query.first()
                self.fechaApertura = query.value( 0 ).toDate()
                
                

            except UserWarning as inst:
                QMessageBox.critical( self, qApp.organizationName(),
                                      unicode( inst ) )
                logging.error( unicode( inst ) )
            except Exception as inst:
                logging.critical( unicode( inst ) )
            finally:
                if QSqlDatabase.database().isOpen():
                    QSqlDatabase.database().close()

            self.dtFechaTime.setDisplayFormat( 'dd/MM/yyyy' )
            self.dtFechaTime.setMaximumDateTime( QDateTime.currentDateTime() )
            if self.fechaApertura is not None:
                self.dtFechaTime.setMinimumDate( self.fechaApertura )


            self.cbcaja.setModel( self.cajasmodel )
            self.cbcaja.setModelColumn( 1 )
            self.cbcaja.setCurrentIndex( -1 )
            self.dtFechaTime.setDateTime( QDateTime.currentDateTime() )

            self.buttonBox.rejected.connect( self.reject )

    def accept( self ):
        if not self.cerrar:
            self.editmodel.datosSesion.cajaId = self.cajasmodel.record( self.cbcaja.currentIndex() ).value( "idcaja" ).toInt()[0]

        if self.editmodel.valid:
            supervisor = User( self.txtUser.text(), self.txtPassword.text() )
            if supervisor.valid:
                if not supervisor.hasRole( 'gerencia' ):
                    QMessageBox.critical( self, qApp.organizationName() + u": Autenticación", "El usuario %s no tiene permisos para autorizar la apertura de caja" % supervisor.user )
                    logging.info( u"El usuario %s intento autorizar la apertura de una sesión" % supervisor.user )
                    return


                self.editmodel.supervisorId = supervisor.uid
                self.editmodel.datosSesion.fecha = self.dtFechaTime.date()

                if not self.editmodel.save():
                    QMessageBox.warning( self,
                                         qApp.organizationName(),
                                         self.editmodel.error )
                    logging.error( self.editmodel.error )
                    #else:
                        #QMessageBox.warning( None, u"La sesión no fue abierta", u"La sesión no fue abierta. Por favor Contacte al administrador del sistema")
                else:
                    QMessageBox.information( self,
                                             qApp.organizationName(),
                                              u"La sesión fue abierta exitosamente" )
                    logging.info( u"El usuario %s ha abierto una sesión de caja autorizada por el usuario %s " % ( self.parentWindow.user.user, supervisor.user ) )
                    super( DlgApertura, self ).accept()
            else:
                QMessageBox.critical( self,
                                      qApp.organizationName() + u": Autenticación",
                                      supervisor.error )
                self.txtUser.setFocus()
                self.txtPassword.setText( "" )
        else:
            self.cbcaja.setFocus()
            QMessageBox.warning( self, qApp.organizationName(),
                                  self.editmodel.error )
            #self.editmodel.errorId =0

    @pyqtSlot()
    def on_txtSaldoC_editingFinished( self ):
        if self.editmodel != None:
            self.editmodel.saldoCordoba = Decimal( str( self.txtSaldoC.value() ) )


    @pyqtSlot()
    def on_txtSaldoD_editingFinished( self ):
        if self.editmodel != None:
            self.editmodel.saldoDolar = Decimal( str( self.txtSaldoD.value() ) )
            
    @pyqtSlot(int)
    def on_cbcaja_currentIndexChanged(self,indice):
        if indice ==-1:
            self.txtSaldoC.setValue(0)
            self.txtSaldoD.setValue(0)
        else:
            self.txtSaldoC.setValue( Decimal( self.cajasmodel.data(self.cajasmodel.index(indice,2)).toString()))
            self.txtSaldoD.setValue( Decimal( self.cajasmodel.data(self.cajasmodel.index(indice,3)).toString()))
       

    @property
    def idsesion( self ):
        return self.sesion

    @property
    def fecha( self ):
        return self.dtFechaTime.date()