Exemplo n.º 1
0
 def change_products_status_after_save(self,
                                       added,
                                       updated,
                                       status,
                                       downgrade_to=None,
                                       progress=True):
     from xulpymoney.objects.product import ProductManager
     products = ProductManager(self.mem)
     for manager in [added, updated]:
         for quote in manager.arr:
             if quote.product not in products.arr:
                 products.append(quote.product)
     products.needStatus(status,
                         downgrade_to=downgrade_to,
                         progress=progress)
     self.mem.data.benchmark.needStatus(
         2)  #If it's in products it has been downgraded
     self.mem.data.currencies.needStatus(
         3)  #If it's in products it has been downgraded
Exemplo n.º 2
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()