def on_cmdConnect_released(self): if not self.mem.con.is_superuser(): qmessagebox( self.tr("The role of the user is not an administrator")) return simcon = ConnectionQt().init__create( self.mem.con.user, self.mem.con.password, self.mem.con.server, self.mem.con.port, self.simulations.selected.simulated_db()) simcon.connect() self.mem_sim = MemXulpymoney() self.mem_sim.con = simcon ##Update database update = xulpymoney.libdbupdates.Update(self.mem_sim, "Qt") if update.need_update() == True: update.run() self.mem_sim.frmMain = xulpymoney.ui.frmMain.frmMain(self.mem_sim) #No puedo visualizarlo, luego voy a usar un qdialog , ya que qmainwindow viene de qwidget. d = QDialog(self) d.setStyleSheet("QDialog { background-color: rgb(255, 182, 182); }") d.setWindowTitle( self.tr("Xulpymoney SIMULATED IN {} 2010-{} \xa9").format( self.simulations.selected.simulated_db(), __versiondate__.year)) icon = QIcon() icon.addPixmap(QPixmap(":/xulpymoney/replication.png"), QIcon.Normal, QIcon.Off) d.setWindowIcon(icon) d.showMaximized() lay = QVBoxLayout(d) lay.addWidget(self.mem_sim.frmMain) d.exec_()
def on_actionSharesTransferUndo_triggered(self): if self.mem.data.investments_active().traspaso_valores_deshacer( self.op.selected) == False: qmessagebox(self.tr("Shares transfer couldn't be done."), ":/xulpymoney/coins.png") return self.update_tables()
def on_actionProductDelete_triggered(self): if len(self.mqtwInvestments.selected) > 0: if self.mqtwInvestments.selected[0].is_deletable() == False: qmessagebox( self. tr("This product can't be removed, because is marked as not remavable" )) return if self.mqtwInvestments.selected[0].is_system() == True: qmessagebox( self. tr("This product can't be removed, because is a system product" )) return respuesta = QMessageBox.warning( self, self.tr("Xulpymoney"), self. tr("Deleting data from selected product ({0}). If you use manual update mode, data won't be recovered. Do you want to continue?" .format(self.mqtwInvestments.selected[0].id)), QMessageBox.Ok | QMessageBox.Cancel) if respuesta == QMessageBox.Ok: self.arrInt.remove(self.mqtwInvestments.selected[0].id) self.mem.data.products.remove(self.mqtwInvestments.selected[0]) self.mem.con.commit() self.build_array_from_arrInt()
def on_cmd_pressed(self): if len(self.txt.text().upper()) <= 2: qmessagebox( self.tr("Search too wide. You need more than 2 characters")) return # To filter by stockmarket sm = None if self.chkStockExchange.checkState() == Qt.Checked: sm = self.mem.stockmarkets.find_by_id( self.cmbStockExchange.itemData( self.cmbStockExchange.currentIndex())) del self.arrInt self.arrInt = [] #Temporal ProductManager pros = self.mem.data.products.ProductManager_contains_string( self.txt.text()) for p in pros.arr: #Filter sm if sm != None and sm.id != p.stockmarket.id: continue else: self.arrInt.append(p.id) self.build_array_from_arrInt()
def update_due_to_quotes_change(self): self.load_product() if self.product.id is not None: self.product.needStatus(2) if self.product.result.ohclDaily.length() > 0: self.product.estimations_dps.load_from_db( ) #No cargada por defecto en product self.product.estimations_eps.load_from_db( ) #No cargada por defecto en product self.product.estimations_dps.myqtablewidget( self.mqtwDividendsEstimations) self.product.estimations_eps.myqtablewidget(self.mqtwEPS) self.product.dps.myqtablewidget(self.mqtwDPSPaid) self.product.splits.myqtablewidget(self.mqtwSplits) inicio = datetime.now() self.load_information() info("Datos informacion cargados: {}".format(datetime.now() - inicio)) self.load_graphics() info("Datos gráficos cargados: {}".format(datetime.now() - inicio)) self.load_mensuales() info("Datos mensuales cargados: {}".format(datetime.now() - inicio)) self.on_tabHistorical_currentChanged( self.tabHistorical.currentIndex()) else: qmessagebox(self.tr("Not enough quotes for this product"))
def on_tab_tabCloseRequested(self, index): """Only removes dinamic tabs""" if index in (0, 1): qmessagebox(self.tr("You can't close this tab")) else: self.tab.setCurrentIndex(0) self.tab.removeTab(index)
def __init__(self, mem, inversion, allProduct=False, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self.mem = mem if allProduct == False: self.investment = inversion else: self.investment = self.mem.data.investments_active( ).Investment_merging_current_operations_with_same_product( inversion.product) self.txtValorAccion.setText( self.investment.product.result.basic.last.quote) self.txtSimulacion.setText( self.investment.recommended_amount_to_invest()) self.tabOps.setCurrentIndex(1) self.mqtwOps.setSettings(self.mem.settings, "wdgDisReinvest", "mqtwOps") self.mqtwCurrentOps.setSettings(self.mem.settings, "wdgDisReinvest", "mqtwCurrentOps") self.mqtwHistoricalOps.setSettings(self.mem.settings, "wdgDisReinvest", "mqtwHistoricalOps") if self.investment.op_actual.length() == 0: qmessagebox(self.tr("There aren't shares for this investment")) return self.on_radRe_clicked()
def __init__(self, mem, inversion , parent=None): QDialog.__init__(self, parent) self.setupUi(self) self.showMaximized() self.mem=mem self.investment=inversion if self.investment.id==None: qmessagebox(self.tr("You can't set a selling price to a unsaved investment")) return if self.investment.op_actual.length()==0: qmessagebox(self.tr("You don't have shares to sale in this investment")) return self.puntoventa=Decimal(0)#Guarda el resultado de los cálculos self.investmentsoperations=None if self.mem.gainsyear==True: self.chkGainsTime.setCheckState(Qt.Checked) else: self.chkGainsTime.setEnabled(False) self.mqtw.setSettings(self.mem.settings, "frmSellingPoint", "mqtw") self.mqtwSP.setSettings(self.mem.settings, "frmSellingPoint", "mqtwSP") self.spnGainsPercentage.setValue(self.mem.settingsdb.value_float("frmSellingPoint/lastgainpercentage", "10")) self.lblPriceSymbol.setText(currency_symbol(self.investment.product.currency)) self.lblAmountSymbol.setText(currency_symbol(self.investment.account.currency))
def on_bb_accepted(self): if self.chkDeleteFile.isChecked() == True: remove(self.fileToDelete()) if path.exists(self.fileToDelete()) == True: qmessagebox(self.tr("There was an error deleting file")) self.mem.con.commit() self.accept()
def qmessagebox_inactive(self): if self.active == False: qmessagebox( self. tr("The associated account is not active. You must activate it first" )) return True return False
def order_by_percentage_from_current_price(self): try: self.arr = sorted(self.arr, key=lambda o: o.percentage_from_current_price(), reverse=True) except: qmessagebox( self.tr("I couldn't order data due to they have null values"))
def on_cmdPairsDelete_released(self): self.pcmanager.selected = self.pcmanager.find_by_id_builtin( self.cmbPairs.itemData(self.cmbPairs.currentIndex())) if self.pcmanager.selected is not None: self.pcmanager.remove(self.pcmanager.selected) self.cmbPairs_refresh() else: qmessagebox(self.tr("You must select a pair"))
def on_actionCreditCardDelete_triggered(self): if self.mqtwCreditCards.selected.is_deletable()==False: qmessagebox(self.tr("I can't delete the credit card, because it has dependent registers"), ":/xulpymoney/coins.png") else: self.mqtwCreditCards.selected.delete() self.mem.con.commit() self.mqtwCreditCards.clear()#Must be before needStatus (Crashed) self.account.needStatus(1, downgrade_to=0) self.mqtwCreditCards_update()
def on_actionConceptDelete_triggered(self): if self.mqtwConcepts.selected.borrar(): self.mem.con.commit() self.mem.concepts.remove(self.mqtwConcepts.selected) self.regenerate_list() self.mqtwConcepts.table.clearSelection() self.mqtwConcepts.selected = None self.mqtwConcepts_reload() else: qmessagebox(self.tr("This concept can't be deleted"))
def on_actionFavorites_triggered(self): from xulpymoney.ui.wdgProducts import wdgProducts favorites = self.mem.settingsdb.value_list_of_integers( "mem/favorites", "") if len(favorites) == 0: qmessagebox(self.tr("There aren't favorite products")) return self.w.close() self.w = wdgProducts(self.mem, favorites) self.layout.addWidget(self.w) self.w.show()
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_database_created(connectionqt): from xulpymoney.database_update import database_update from xulpymoney.version import __versiondatetime__ from xulpymoney.ui.myqwidgets import qmessagebox database_update(connectionqt, "xulpymoney", __versiondatetime__, "Console") connectionqt.commit() qmessagebox( qApp.translate( "Mem", "Xulpymoney have been correctly installed. Please login again")) exit(qApp.exec_())
def on_actionIndexRange_triggered(self): from xulpymoney.ui.wdgIndexRange import wdgIndexRange if self.mem.data.benchmark.result.ohclDaily.length() == 0: qmessagebox(self.tr("There isn't any benchmark data yet.")) return self.w.close() self.w = wdgIndexRange(self.mem, self) self.layout.addWidget(self.w) self.w.show()
def on_cmdPairsNew_released(self): if self.selector1.selected is None or self.selector2.selected is None: qmessagebox(self.tr("You need to select both products")) return p = ProductComparation(self.mem, self.selector1.selected, self.selector2.selected) if p in self.pcmanager: qmessagebox(self.tr("This pair is already added")) return self.pcmanager.append(p) self.cmbPairs_refresh(p)
def qmessagebox_reminder(self): if self.shares < 0: type = "Sell" else: type = "Buy" qmessagebox( self. tr("Don't forget to tell your bank to add and order for:\n{} ({})\n{} {} shares to {}" .format(self.investment.name, self.investment.account.name, type, abs(self.shares), self.investment.money(self.price).string(6))))
def on_actionBankDelete_triggered(self): if self.mqtwBanks.selected.qmessagebox_inactive(): return if self.mqtwBanks.selected.is_deletable() == False: qmessagebox( self. tr("This bank has dependent accounts and it can't be deleted")) else: self.mem.data.banks.delete(self.mqtwBanks.selected) self.mem.con.commit() self.on_chkActives_stateChanged(self.chkActives.checkState())
def on_cmdPurge_pressed(self): all = QuoteAllIntradayManager(self.mem) all.load_from_db(self.product) numpurged = all.purge(progress=True) if numpurged != None: #Canceled self.mem.con.commit() qmessagebox( self.tr("{0} quotes have been purged from {1}".format( numpurged, self.product.name))) else: self.mem.con.rollback()
def on_actionPurge_triggered(self): if len(self.mqtwInvestments.selected) > 0: all = QuoteAllIntradayManager(self.mem) all.load_from_db(self.mqtwInvestments.selected[0]) numpurged = all.purge(progress=True) if numpurged != None: #Canceled self.mem.con.commit() qmessagebox( self.tr("{0} quotes have been purged from {1}".format( numpurged, self.mqtwInvestments.selected[0].name))) else: self.mem.con.rollback()
def on_buttonbox_accepted(self): if self.mem.con.is_superuser() == False: qmessagebox("The role of the user is not an administrator") self.parent.reject() return type_id = self.cmbSimulationTypes.itemData( self.cmbSimulationTypes.currentIndex()) print(type_id) self.simulation = Simulation(self.mem, self.mem.con.db).init__create( type_id, self.wdgStarting.datetime(), self.wdgEnding.datetime()) self.simulation.save() newdb = None #newdb=XulpymoneyDatabase(self.mem.con.user, self.mem.con.password, self.mem.con.server, self.mem.con.port, self.simulation.simulated_db()) if newdb.create() == False: qmessagebox(self.tr("I couldn't create simulation")) return if type_id == 1: #Copy between dates print("Copying") cur = newdb.newdbcon.cursor( ) #Deleting tables with register from empty creation cur.execute("delete from public.products") cur.execute("delete from public.concepts") cur.close() newdb.copy(self.mem.con, newdb.newdbcon, "select * from banks where id not in (3)", "banks") #Due to 3 already is in schema newdb.copy(self.mem.con, newdb.newdbcon, "select * from accounts where accounts_id not in (4)", "accounts") newdb.copy(self.mem.con, newdb.newdbcon, "select * from creditcards", "creditcards") newdb.copy(self.mem.con, newdb.newdbcon, "select * from products", "products") newdb.copy(self.mem.con, newdb.newdbcon, "select * from quotes", "quotes") newdb.copy(self.mem.con, newdb.newdbcon, "select * from dps", "dps") newdb.copy(self.mem.con, newdb.newdbcon, "select * from estimations_dps", "estimations_dps") newdb.copy(self.mem.con, newdb.newdbcon, "select * from estimations_eps ", "estimations_eps") newdb.copy(self.mem.con, newdb.newdbcon, "select * from investments", "investments") newdb.copy(self.mem.con, newdb.newdbcon, "select * from concepts", "concepts") newdb.copy(self.mem.con, newdb.newdbcon, "select * from dividends", "dividends") newdb.newdbcon.commit() self.parent.accept()
def on_cmd_pressed(self): if self.txtMaximum.isValid(): self.creditcard.name = self.txtCreditCard.text() self.creditcard.account = self.account self.creditcard.deferred = c2b(self.chkDelayed.checkState()) self.creditcard.maximumbalance = self.txtMaximum.decimal() self.creditcard.number = self.txtNumber.text() self.creditcard.save() self.mem.con.commit() self.account.needStatus(1, downgrade_to=0) self.done(0) else: qmessagebox(self.tr("You have written and invalid number"))
def on_cmd_released(self): self.investment_simulated = self.investment.Investment_At_Datetime( self.mem.localzone.now()) if self.txtSimulacion.decimal() <= Decimal('0'): qmessagebox(self.tr("Simulation value must be positive")) return price = self.txtValorAccion.decimal() taxes = 0 commission = self.txtComision.decimal() if price == 0: qmessagebox(self.tr("Share price can't be 0")) return shares = self.shares() amount = price * shares self.txtAcciones.setText(shares) self.txtImporte.setText(amount) error("Factor de conversion no siempre es 1") currency_conversion = 1 #Creamos un nuevo investmentsoperations investmentsoperations_id = self.investment_simulated.op.get_highest_io_id( ) + 1 ##Para simular un investmentsoperations_id real, le asignamos uno if self.radDes.isChecked(): #DESINVERSION d = InvestmentOperation( self.mem, self.mem.tiposoperaciones.find_by_id(5), datetime.now(timezone(self.mem.localzone_name)), self.investment, -shares, taxes, commission, price, "", True, currency_conversion, investmentsoperations_id) else: #REINVERSION d = InvestmentOperation( self.mem, self.mem.tiposoperaciones.find_by_id(4), datetime.now(timezone(self.mem.localzone_name)), self.investment, shares, taxes, commission, price, "", True, currency_conversion, investmentsoperations_id) self.investment_simulated.op.append(d) ( self.investment_simulated.op_actual, self.investment_simulated.op_historica ) = self.investment_simulated.op.get_current_and_historical_operations( ) self.cmbPrices_reload() self.cmdOrder.setEnabled(True) self.cmdGraph.setEnabled(True)
def on_cmdSave_pressed(self): if (self.mem.isProductsMaintenanceMode() == False and (self.product.id is None or self.product.id < 0)) or ( self.mem.isProductsMaintenanceMode() == True and (self.product.id is None or self.product.id > 0)): self.product.name = self.txtName.text() self.product.isin = None if self.txtISIN.text( ) == "" else self.txtISIN.text() self.product.currency = self.cmbCurrency.itemData( self.cmbCurrency.currentIndex()) self.product.type = self.mem.types.find_by_id( self.cmbTipo.itemData(self.cmbTipo.currentIndex())) self.product.agrupations = self.cmsAgrupations.selected() self.product.obsolete = c2b(self.chkObsolete.checkState()) self.product.high_low = c2b(self.chkHL.checkState()) self.product.web = self.txtWeb.text() self.product.address = self.txtAddress.text() self.product.phone = self.txtPhone.text() self.product.mail = self.txtMail.text() self.product.percentage = int(self.txtTPC.text()) self.product.mode = self.mem.investmentsmodes.find_by_id( self.cmbPCI.itemData(self.cmbPCI.currentIndex())) self.product.leveraged = self.mem.leverages.find_by_id( self.cmbApalancado.itemData(self.cmbApalancado.currentIndex())) self.product.stockmarket = self.mem.stockmarkets.find_by_id( self.cmbBolsa.itemData(self.cmbBolsa.currentIndex())) for i in range(self.mqtwTickers.table.rowCount()): self.product.tickers[i] = None if self.mqtwTickers.table.item( i, 1).text() == "- - -" else self.mqtwTickers.table.item( i, 1).text() self.product.comment = self.txtComentario.text() self.product.decimals = self.spnDecimals.value() self.product.save() if self.mem.isProductsMaintenanceMode(): if self.__insert == True: self.mem.data.products.append( self.product) #Manager of the singleton self.mem.insertProducts.append(self.product) else: self.mem.updateProducts.append(self.product) else: #Not maintainer mode if self.__insert == True: self.mem.data.products.append( self.product) #Manager of the singleton self.mem.con.commit() self.product.needStatus(1, downgrade_to=0) self.done(0) else: qmessagebox(self.tr("This product can be edited at this moment"))
def on_actionPurgeAll_triggered(self): """Purga todas las quotes de todas inversión. """ products = [] curms = self.mem.con.cursor() curms.execute( "select * from products where id in ( select distinct( id) from quotes) order by name;" ) for row in curms: products.append(Product(self.mem).init__db_row(row)) curms.close() pd = QProgressDialog( QApplication.translate( "Mem", "Purging innecesary data from all products"), QApplication.translate("Mem", "Cancel"), 0, len(products)) pd.setModal(True) pd.setWindowTitle( QApplication.translate("Mem", "Purging quotes from all products")) pd.setWindowIcon(QIcon(":/xulpymoney/coins.png")) pd.setMinimumDuration(0) counter = 0 for i, inv in enumerate(products): pd.setValue(i) pd.setLabelText( QApplication.translate( "Mem", "Purging quotes from {0}.\nTotal purged in global process: {1}" ).format(inv.name, counter)) pd.update() QApplication.processEvents() if pd.wasCanceled(): self.mem.con.rollback() return pd.update() QApplication.processEvents() pd.update() inv.result.all.load_from_db(inv) invcounter = inv.result.all.purge(progress=True) if invcounter == None: #Pulsado cancelar self.mem.con.rollback() break else: counter = counter + invcounter self.mem.con.commit() qmessagebox( self.tr("{0} quotes have been purged from {1} products".format( counter, len(products))))
def on_cmdComparationData_released(self): if self.comparation == None: qmessagebox(self.tr("You need to compare products first")) return d = QDialog(self) d.resize(800, 600) d.setWindowTitle(self.tr("Comparation data table")) mqtwQuotes = mqtw(d) mqtwQuotes.setSettings(self.mem.settings, "wdgProductsComparation", "mqtwQuotes") mqtwQuotes.showSearchOptions(True) self.comparation.myqtablewidget(mqtwQuotes) lay = QVBoxLayout(d) lay.addWidget(mqtwQuotes) d.show()
def on_actionAccountDelete_triggered(self): if self.mqtwAccounts.selected.bank.qmessagebox_inactive( ) or self.mqtwAccounts.selected.qmessagebox_inactive(): return if self.mqtwAccounts.selected.is_deletable() == False: qmessagebox( self. tr("This account has associated investments, credit cards or operations. It can't be deleted" )) else: self.mqtwAccounts.selected.borrar() self.mem.con.commit() #Only can't be deleted an active account, so I remove from active set self.mem.data.accounts.remove(self.mqtwAccounts.selected) self.on_chkInactivas_stateChanged(self.chkInactivas.checkState())