sqlalchemy.func.SUM

Here are the examples of the python api sqlalchemy.func.SUM taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

0 Source : CrudContaAPagar.py
with MIT License
from andrersp

    def movDespesa(self):

        try:

            # Abrindo Sessao
            conecta = Conexao()
            sessao = conecta.Session()

            # Query
            row = (sessao.query(func.COALESCE(
                func.SUM(ContaAPagar.valor_pago), 0
            ).label('valorPago'))

                .filter(ContaAPagar.data_pagamento.between(
                    self.dataPagamento, self.dataFim))
            )
            row.all()

            # Salvando resultado
            for row in row:
                self.valorPago = row.valorPago

            # Query
            row = (sessao.query(func.COALESCE(
                func.SUM(ContaAPagar.valor), 0
            ).label('valorAPagar'))

                .filter(ContaAPagar.data_vencimento.between(
                    self.dataPagamento, self.dataFim))
            )
            row.all()

            # Salvando resultado
            for row in row:
                self.valorAPagar = row.valorAPagar

            # Fechando a Conexao
            sessao.close

        except IntegrityError as err:
            print(err)

    # detalhes entrada por categoria de receita
    def detalheDespesa(self):

0 Source : CrudContaAPagar.py
with MIT License
from andrersp

    def detalheDespesa(self):

        try:

            # Abrindo Sessao
            conecta = Conexao()
            sessao = conecta.Session()

            # Query
            self.query = (sessao.query(func.SUM(ContaAPagar.valor_pago),
                                       CatAPagar.categoria_a_pagar,
                                       FormaPagamento.forma_pagamento)
                          .join(CatAPagar)
                          .join(FormaPagamento)
                          .filter(ContaAPagar.data_pagamento
                                  .between(self.dataPagamento,
                                           self.dataFim))
                          .group_by(ContaAPagar.forma_pagamento, ContaAPagar.categoria)
                          )

            # Convertendo variaveis em lista
            self.valorPago = []
            self.categoria = []
            self.formaPagamento = []

            # Salvando resultado em suas listas
            for row in self.query:
                self.categoria.append(row.categoria_a_pagar)
                self.valorPago.append(row[0])
                self.formaPagamento.append(row.forma_pagamento)

            # Fechando a Conexao
            sessao.close()

        except IntegrityError as err:
            print(err)

    # Total a Pagar Hoje
    def aPagarHoje(self):

0 Source : CrudContaAPagar.py
with MIT License
from andrersp

    def aPagarHoje(self):

        try:

            # Abrindo Sessao
            conecta = Conexao()
            sessao = conecta.Session()

            # Query
            row = (sessao.query(func.COALESCE(
                func.SUM(ContaAPagar.valor), 0).label('total'))
                .filter(ContaAPagar.data_vencimento == date.today(), ContaAPagar.pagamento == 2))

            # Salvando Resultado
            for row in row:
                self.valorAPagar = row.total

        except IntegrityError as err:
            print(err)

        return self.valorAPagar

0 Source : CrudContaAReceber.py
with MIT License
from andrersp

    def movEntrada(self):

        try:

            # Abrindo Sessao
            conecta = Conexao()
            sessao = conecta.Session()

            # Query
            row = (sessao.query(func.COALESCE(
                func.SUM(ContaAReceber.valor_recebido), 0
            ).label('valorRecebido'))

                .filter(ContaAReceber.data_recebimento.between(
                    self.dataRecebimento, self.dataFim))
            )
            row.all()

            # Salvando resultado
            for row in row:
                self.valorRecebido = row.valorRecebido

            # Query
            row = (sessao.query(func.COALESCE(
                func.SUM(ContaAReceber.valor), 0
            ).label('valorAReceber'))

                .filter(ContaAReceber.data_vencimento.between(
                    self.dataRecebimento, self.dataFim))
            )
            row.all()

            # Salvando resultado
            for row in row:
                self.valorAReceber = row.valorAReceber

            # Fechando a Conexao
            sessao.close

        except IntegrityError as err:
            print(err)

        pass

    # detalhes entrada por categoria de receita
    def detalheEntrada(self):

0 Source : CrudContaAReceber.py
with MIT License
from andrersp

    def detalheEntrada(self):

        try:

            # Abrindo Sessao
            conecta = Conexao()
            sessao = conecta.Session()

            # Query
            self.query = (sessao.query(func.SUM(ContaAReceber.valor_recebido).label('entrada'),
                                       CatAReceber.categoria_a_receber,
                                       FormaPagamento.forma_pagamento)
                          .join(CatAReceber)
                          .join(FormaPagamento)
                          .filter(ContaAReceber.data_recebimento
                                  .between(self.dataRecebimento,
                                           self.dataFim))
                          .group_by(ContaAReceber.forma_pagamento, ContaAReceber.categoria)
                          )

            # Convertendo variaveis em lista
            self.valorRecebido = []
            self.categoria = []
            self.formaPagamento = []

            # Salvando resultado em suas listas
            for row in self.query:
                self.categoria.append(row.categoria_a_receber)
                self.valorRecebido.append(row.entrada)
                self.formaPagamento.append(row.forma_pagamento)

            # Fechando a Conexao
            sessao.close()

        except IntegrityError as err:
            print(err)

    # Total a Receber Hoje
    def aReceberHoje(self):

0 Source : CrudContaAReceber.py
with MIT License
from andrersp

    def aReceberHoje(self):

        try:

            # Abrindo Sessao
            conecta = Conexao()
            sessao = conecta.Session()

            # Query
            row = (sessao.query(func.COALESCE(
                func.SUM(ContaAReceber.valor), 0).label('total'))
                .filter(ContaAReceber.data_vencimento == date.today(), ContaAReceber.pagamento == 2))

            # Salvando Resultado
            for row in row:
                self.valorAReceber = row.total

        except IntegrityError as err:
            print(err)

        return self.valorAReceber

0 Source : CrudVenda.py
with MIT License
from andrersp

    def relatValorDia(self):

        try:

            # Abrindo Sessao
            conecta = Conexao()
            sessao = conecta.Session()

            # Query
            row = (sessao.query(func.COALESCE(
                func.SUM(Venda.valor_recebido), 0).label('vendido'),
                func.COUNT(distinct(Venda.id_cliente)).label('cliente'))
                .filter(Venda.data_emissao.between(self.dataEmissao,
                                                   self.dataFim)))
            row.all()

            # salvando resultado
            for query in row:
                self.valorRecebido = str(query.vendido).replace('.', ',')
                self.idCliente = query.cliente

            # Fechando a COnexao
            sessao.close()

        except IntegrityError as err:
            print(err)