예제 #1
0
 def on_actionDividends_triggered(self):
     """Shows products with current year estimations_dps and with quotes in current year"""
     from xulpymoney.ui.wdgProducts import wdgProducts
     self.w.close()
     prod = ProductManager(self.mem)
     prod.load_from_db(
         "select * from products where id in (select products_id from estimations_dps where year=date_part('year',now()) and estimation is not null) and id in (select distinct(id) from quotes where date_part('year', datetime)=date_part('year',now()))"
     )
     self.w = wdgProducts(self.mem, prod.array_of_ids())
     self.layout.addWidget(self.w)
     self.w.on_actionSortDividend_triggered()
     self.w.show()
예제 #2
0
 def on_actionProductsWithoutISIN_triggered(self):
     from xulpymoney.ui.wdgProducts import wdgProducts
     self.w.close()
     prod = ProductManager(self.mem)
     prod.load_from_db(
         "select * from products  where obsolete=false and (isin is null or isin ='') order by name,id"
     )
     arrInt = []
     for p in prod.arr:
         arrInt.append(p.id)
     self.w = wdgProducts(self.mem, arrInt)
     self.layout.addWidget(self.w)
     self.w.show()
예제 #3
0
 def on_actionProductsInvestmentInactive_triggered(self):
     from xulpymoney.ui.wdgProducts import wdgProducts
     self.w.close()
     prod = ProductManager(self.mem)
     prod.load_from_db(
         "select * from products where id in (select products_id from investments where active=false) order by name"
     )
     arrInt = []
     for p in prod.arr:
         arrInt.append(p.id)
     self.w = wdgProducts(self.mem, arrInt)
     self.layout.addWidget(self.w)
     self.w.show()
예제 #4
0
 def on_actionProductsWithOldPrice_triggered(self):
     from xulpymoney.ui.wdgProducts import wdgProducts
     self.w.close()
     prod = ProductManager(self.mem)
     prod.load_from_db(
         "select p.* from products p, quote(p.id, now()) q where p.id=q.id and q.datetime<now() -interval '30 day' and obsolete=False order by name"
     )
     arrInt = []
     for p in prod.arr:
         arrInt.append(p.id)
     self.w = wdgProducts(self.mem, arrInt)
     self.layout.addWidget(self.w)
     self.w.show()
예제 #5
0
 def on_actionProductsNotAutoUpdate_triggered(self):
     from xulpymoney.ui.wdgProducts import wdgProducts
     self.w.close()
     prod = ProductManager(self.mem)
     prod.load_from_db("""select * from products 
             where obsolete=false and id not in ({})
             order by name
             """.format(list2string(list(self.mem.autoupdate))))
     arrInt = []
     for p in prod.arr:
         arrInt.append(p.id)
     self.w = wdgProducts(self.mem, arrInt)
     self.layout.addWidget(self.w)
     self.w.show()
예제 #6
0
class DBData(QObject):
    def __init__(self, mem):
        QObject.__init__(self)
        self.mem = mem

    ## Create a QProgressDialog to load Data
    def __qpdStart(self):
        qpdStart = QProgressDialog(self.tr("Loading Xulpymoney data"), None, 0,
                                   6)
        qpdStart.setWindowIcon(QIcon(":/xulpymoney/coins.png"))
        qpdStart.setModal(True)
        qpdStart.setWindowTitle(
            QApplication.translate("Mem", "Loading Xulpymoney..."))
        qpdStart.forceShow()
        return qpdStart

    ## Increases qpdStart value
    ## @param qpdStart QProgressDialog
    def __qpdStart_increaseValue(self, qpdStart):
        qpdStart.setValue(qpdStart.value() + 1)
        if qpdStart.value() == 1:
            qpdStart.setLabelText(self.tr("Loading products definitions"))
        elif qpdStart.value() == 2:
            qpdStart.setLabelText(self.tr("Loading benchmark"))
        elif qpdStart.value() == 3:
            qpdStart.setLabelText(self.tr("Loading currencies"))
        elif qpdStart.value() == 4:
            qpdStart.setLabelText(self.tr("Loading banks and accounts"))
        elif qpdStart.value() == 5:
            qpdStart.setLabelText(self.tr("Loading investments"))
        elif qpdStart.value() == 6:
            qpdStart.setLabelText(self.tr("Loading products information"))
        qpdStart.update()
        QApplication.processEvents()

    def load(self, progress=True):
        """
            This method will subsitute load_actives and load_inactives
        """
        inicio = datetime.now()
        qpdStart = self.__qpdStart()

        self.__qpdStart_increaseValue(qpdStart)
        start = datetime.now()
        self.products = ProductManager(self.mem)
        self.products.load_from_db("select * from products", progress=False)
        debug("DBData > Products took {}".format(datetime.now() - start))

        self.__qpdStart_increaseValue(qpdStart)
        self.benchmark = self.products.find_by_id(
            self.mem.settingsdb.value_integer("mem/benchmarkid", 79329))
        self.benchmark.needStatus(2)

        self.__qpdStart_increaseValue(qpdStart)
        #Loading currencies
        start = datetime.now()
        self.currencies = ProductManager(self.mem)
        for p in self.products.arr:
            if p.type.id == 6:
                p.needStatus(3)
                self.currencies.append(p)
                print(p.name, p.result.all.length())
        debug("DBData > Currencies took {}".format(datetime.now() - start))

        self.__qpdStart_increaseValue(qpdStart)
        self.banks = BankManager(self.mem)
        self.banks.load_from_db("select * from banks order by name")

        self.accounts = AccountManager_from_sql(
            self.mem, "select * from accounts order by name")

        self.__qpdStart_increaseValue(qpdStart)
        start = datetime.now()
        self.investments = InvestmentManager(self.mem)
        self.investments.load_from_db("select * from investments",
                                      progress=False)
        self.investments.needStatus(2, progress=False)
        debug("DBData > Investments took {}".format(datetime.now() - start))

        self.__qpdStart_increaseValue(qpdStart)
        #change status to 1 to self.investments products
        start = datetime.now()
        pros = self.investments.ProductManager_with_investments_distinct_products(
        )
        pros.needStatus(1, progress=False)
        debug("DBData > Products status 1 took {}".format(datetime.now() -
                                                          start))

        self.__qpdStart_increaseValue(qpdStart)
        info("DBData loaded: {}".format(datetime.now() - inicio))

    def accounts_active(self):
        r = AccountManager(self.mem)
        for b in self.accounts.arr:
            if b.active == True:
                r.append(b)
        return r

    def accounts_inactive(self):
        r = AccountManager(self.mem)
        for b in self.accounts.arr:
            if b.active == False:
                r.append(b)
        return r

    def banks_active(self):
        r = BankManager(self.mem)
        for b in self.banks.arr:
            if b.active == True:
                r.append(b)
        return r

    def banks_inactive(self):
        r = BankManager(self.mem)
        for b in self.banks.arr:
            if b.active == False:
                r.append(b)
        return r

    def investments_active(self):
        r = InvestmentManager(self.mem)
        for b in self.investments.arr:
            if b.active == True:
                r.append(b)
        return r

    def investments_inactive(self):
        r = InvestmentManager(self.mem)
        for b in self.investments.arr:
            if b.active == False:
                r.append(b)
        return r

    def banks_set(self, active):
        """Function to point to list if is active or not"""
        if active == True:
            return self.banks_active()
        else:
            return self.banks_inactive()

    def accounts_set(self, active):
        """Function to point to list if is active or not"""
        if active == True:
            return self.accounts_active()
        else:
            return self.accounts_inactive()

    def investments_set(self, active):
        """Function to point to list if is active or not"""
        if active == True:
            return self.investments_active()
        else:
            return self.investments_inactive()