Exemple #1
0
    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))
Exemple #2
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()
Exemple #3
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()
Exemple #4
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()
Exemple #5
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()
Exemple #6
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()
Exemple #7
0
    def __init__(self, parent, mem):
        QDialog.__init__(self, parent)
        self.mem=mem
        self.products=ProductManager(self.mem)
        self.resize(1024, 500)
        self.horizontalLayout_2 = QHBoxLayout(self)
        self.verticalLayout = QVBoxLayout()
        self.lbl = QLabel(self)
        font = QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.lbl.setFont(font)
        self.lbl.setAlignment(Qt.AlignCenter)
        self.verticalLayout.addWidget(self.lbl)
        self.horizontalLayout = QHBoxLayout()
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.widget = wdgProductSelector(self)
        self.horizontalLayout.addWidget(self.widget)
        self.label = QLabel(self)
        self.horizontalLayout.addWidget(self.label)
        self.txt = QLineEdit(self)
        self.horizontalLayout.addWidget(self.txt)
        self.cmd = QToolButton(self)
        icon = QIcon()
        icon.addPixmap(QPixmap(":/xulpymoney/document-preview-archive.png"), QIcon.Normal, QIcon.Off)
        self.cmd.setIcon(icon)
        self.horizontalLayout.addWidget(self.cmd)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.mqtwProducts = mqtwObjects(self)
        self.mqtwProducts.setSettings(self.mem.settings, "frmProductSelector", "mqtwProducts")
        self.verticalLayout.addWidget(self.mqtwProducts)
        self.lblFound = QLabel(self)
        self.verticalLayout.addWidget(self.lblFound)
        self.horizontalLayout_2.addLayout(self.verticalLayout)
        self.setWindowTitle(self.tr("Select a product"))
        self.lbl.setText(self.tr("Product list"))
        self.label.setText(self.tr("Search by code, ISIN, ticker or product name"))
        self.lblFound.setText(self.tr("Found registers"))

        self.setTabOrder(self.txt, self.cmd)
        self.setTabOrder(self.cmd, self.mqtwProducts)
        self.cmd.released.connect(self.on_cmd_released)
        self.txt.returnPressed.connect(self.on_cmd_released)                    
        self.mqtwProducts.table.cellDoubleClicked.connect(self.on_mqtwProducts_cellDoubleClicked)
Exemple #8
0
    def __init__(self, mem, parent=0, flags=False):
        frmMain.__init__(self, mem, parent, flags)
        self.mem.insertProducts = ProductManager(self.mem)
        self.mem.updateProducts = ProductManager(self.mem)
        self.mem.deleteProducts = ProductManager(self.mem)
        self.setWindowTitle(
            self.tr(
                "Xulpymoney 2010-{0} \xa9 (Products maintenance mode)").format(
                    __versiondate__.year)
        )  #print ("Xulpymoney 2010-{0} © €".encode('unicode-escape'))
        self.setWindowIcon(self.mem.qicon_admin())

        for action in [
                self.actionAccounts,
                self.actionBanks,
                self.actionCalculator,
                self.actionConcepts,
                self.actionDerivativesReport,
                self.actionDividendsReport,
                self.actionEvolutionReport,
                self.actionGlobalReport,
                self.actionLastOperation,
                self.actionOrders,
                self.actionIndexRange,
                self.actionInvestmentRanking,
                self.actionInvestmentsClasses,
                self.actionInvestmentsOperations,
                self.actionInvestmentsZeroRisk,
                self.actionInvestments,
                self.actionSimulations,
                self.actionAuxiliarTables,
                self.actionTotalReport,
                self.actionTransfer,
                self.actionProductRange,
                self.actionProductsComparation,
                self.actionPurchaseOpportunities,
        ]:
            action.setEnabled(False)
Exemple #9
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
Exemple #10
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()
Exemple #11
0
class frmProductSelector(QDialog):
    def __init__(self, parent, mem):
        QDialog.__init__(self, parent)
        self.mem=mem
        self.products=ProductManager(self.mem)
        self.resize(1024, 500)
        self.horizontalLayout_2 = QHBoxLayout(self)
        self.verticalLayout = QVBoxLayout()
        self.lbl = QLabel(self)
        font = QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.lbl.setFont(font)
        self.lbl.setAlignment(Qt.AlignCenter)
        self.verticalLayout.addWidget(self.lbl)
        self.horizontalLayout = QHBoxLayout()
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.widget = wdgProductSelector(self)
        self.horizontalLayout.addWidget(self.widget)
        self.label = QLabel(self)
        self.horizontalLayout.addWidget(self.label)
        self.txt = QLineEdit(self)
        self.horizontalLayout.addWidget(self.txt)
        self.cmd = QToolButton(self)
        icon = QIcon()
        icon.addPixmap(QPixmap(":/xulpymoney/document-preview-archive.png"), QIcon.Normal, QIcon.Off)
        self.cmd.setIcon(icon)
        self.horizontalLayout.addWidget(self.cmd)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.mqtwProducts = mqtwObjects(self)
        self.mqtwProducts.setSettings(self.mem.settings, "frmProductSelector", "mqtwProducts")
        self.verticalLayout.addWidget(self.mqtwProducts)
        self.lblFound = QLabel(self)
        self.verticalLayout.addWidget(self.lblFound)
        self.horizontalLayout_2.addLayout(self.verticalLayout)
        self.setWindowTitle(self.tr("Select a product"))
        self.lbl.setText(self.tr("Product list"))
        self.label.setText(self.tr("Search by code, ISIN, ticker or product name"))
        self.lblFound.setText(self.tr("Found registers"))

        self.setTabOrder(self.txt, self.cmd)
        self.setTabOrder(self.cmd, self.mqtwProducts)
        self.cmd.released.connect(self.on_cmd_released)
        self.txt.returnPressed.connect(self.on_cmd_released)                    
        self.mqtwProducts.table.cellDoubleClicked.connect(self.on_mqtwProducts_cellDoubleClicked)
        
    def on_cmd_released(self):
        if len(self.txt.text().upper())<=2:            
            qmessagebox(self.tr("Search too wide. You need more than 2 characters"))
            return
                
        self.products=self.mem.data.products.ProductManager_contains_string(self.txt.text().upper())
        self.products.setSelectionMode(ManagerSelectionMode.Object)
        self.products.needStatus(1, progress=True)
        self.products.order_by_name()
        self.lblFound.setText(self.tr("Found {0} registers").format(self.products.length()))
        self.products.myqtablewidget(self.mqtwProducts)  
        
    def on_mqtwProducts_cellDoubleClicked(self, row, column):
        self.done(0)