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 __init__(self, mem, inversion, dividend=None, parent=None): """ Si dividend es None se insertar Si dividend es un objeto se modifica""" QWidget.__init__(self, parent) self.setupUi(self) self.mem = mem self.dividend = dividend self.investment = inversion self.net = 0 self.tpc = 0 self.wdgDT.setLocalzone(self.mem.localzone_name) self.wdgDT.show_microseconds(False) self.wdgDT.show_timezone(False) self.lblGross.setText( self.tr("Gross in {}").format( currency_symbol(self.investment.product.currency))) self.lblGrossAccount.setText( self.tr("Gross converted to {}").format( currency_symbol(self.investment.account.currency))) if dividend == None: #insertar ConceptManager_for_dividends(mem).qcombobox(self.cmb) self.cmb.setCurrentIndex(0) self.dividend = Dividend(self.mem) self.dividend.investment = inversion self.cmd.setText(self.tr("Add new dividend")) self.wdgDT.set(None, self.mem.localzone_name) self.wdgCurrencyConversion.setConversion( Money(self.mem, self.txtBruto.decimal(), self.investment.product.currency), self.investment.account.currency, self.wdgDT.datetime(), None) else: #modificar ConceptManager_for_dividends(mem).qcombobox( self.cmb, self.dividend.concept) self.wdgDT.set(self.dividend.datetime, self.mem.localzone_name) self.wdgCurrencyConversion.setConversion( Money(self.mem, self.txtBruto.decimal(), self.investment.product.currency), self.investment.account.currency, self.wdgDT.datetime(), self.dividend.currency_conversion) self.txtBruto.setText( self.dividend.gross(eMoneyCurrency.Account).amount) self.txtNeto.setText( self.dividend.net(eMoneyCurrency.Account).amount) self.txtRetencion.setText(self.dividend.taxes) self.txtComision.setText( self.dividend.commission(eMoneyCurrency.Account).amount) self.txtDPA.setText(self.dividend.dpa) self.cmd.setText(self.tr("Edit dividend"))
def cmbPrice_load(self): if self.product: self.cmbPrice.clear() self.cmbPrice.addItem( self.tr("Penultimate price at {} in {} ({})".format( str(self.product.result.basic.penultimate.datetime)[:16], self.product.currency, currency_symbol(self.product.currency)))) self.cmbPrice.addItem( self.tr("Last price at {} in {} ({})".format( str(self.product.result.basic.last.datetime)[:16], self.product.currency, currency_symbol(self.product.currency)))) self.cmbPrice.setCurrentIndex(1) #Last price else: self.cmbPrice.clear()
def set(self, mem, currencya, currencyb, factor): """Investement is used to set investment pointer. It's usefull to see investment data in product report factor is to mul A to get b""" self.mem = mem self.factor = factor self.currencya = currencya self.currencyb = currencyb if self.currencya == self.currencyb: self.lblCurrencyB.hide() self.txtB.hide() self.lblCurrencyA.setText(currency_symbol(self.currencya) + " ") self.lblCurrencyB.setText(currency_symbol(self.currencyb)) self.txtA.textChanged.disconnect() self.txtB.textChanged.disconnect() self.txtB.setText(self.txtA.decimal() * factor) self.textChanged.emit() self.txtA.textChanged.connect(self.on_txtA_textChanged) self.txtB.textChanged.connect(self.on_txtB_textChanged)
def on_cmbProducts_currentIndexChanged(self, index): """To invoke this function you must call self.cmbProducts.setCurrentIndex()""" self.product = self.mem.data.products.find_by_id( self.cmbProducts.itemData(index)) if self.product != None: self.lblFinalPrice.setText( self.tr("Final price in {} ({})").format( self.product.currency, currency_symbol(self.product.currency))) if self.product.hasSameLocalCurrency(): self.lblShares.setText(self.tr("Shares calculated")) else: self.lblShares.setText( self.tr("Shares calculated with {} at {}").format( Money(self.mem, 1, self.mem.localcurrency).conversionFactorString( self.product.currency, self.mem.localzone.now()), self.mem.localzone.now())) #Fills self.cmbInvestments with all product investments or with zero shares product investments if self.chkWithoutShares.checkState() == Qt.Checked: self.investments = self.mem.data.investments.InvestmentManager_with_investments_with_the_same_product_with_zero_shares( self.product) else: self.investments = self.mem.data.investments.InvestmentManager_with_investments_with_the_same_product( self.product) self.investments.qcombobox(self.cmbInvestments, tipo=3, selected=None, obsolete_product=False, investments_active=None, accounts_active=None) self.mem.settings.setValue("wdgCalculator/product", self.product.id) self.cmbPrice_load() self.txtLeveraged.setText(self.product.leveraged.multiplier) self.txtFinalPrice.textChanged.disconnect() self.txtFinalPrice.setText( round( self.txtProductPrice.decimal() * Decimal(1 + Decimal(self.spnProductPriceVariation.value()) * self.txtLeveraged.decimal() / 100), 6)) self.txtFinalPrice.textChanged.connect( self.on_txtFinalPrice_textChanged) self.calculate()
def __init__(self, mem, parent=None): """Compulsory fields are final price and amount""" QWidget.__init__(self, parent) self.setupUi(self) self.mem = mem self.mqtw.setSettings(self.mem.settings, "wdgCalculator", "mqtw") self.investments = None #SetINvestments of the selected product self.product = self.mem.data.products.find_by_id(int( self.mem.settings.value("wdgCalculator/product", -9999)), logging=True) self.mem.data.investments.ProductManager_with_investments_distinct_products( ).qcombobox_not_obsolete(self.cmbProducts, self.product) self.lblAmount.setText( self.tr("Amount to invest in {} ({})").format( self.mem.localcurrency, currency_symbol(self.mem.localcurrency)))
def load_product(self): debug("Entering product with self.__insert={}".format(self.__insert)) if self.__insert == True: self.mem.stockmarkets.qcombobox(self.cmbBolsa) self.cmbBolsa.setCurrentIndex(10) self.mem.investmentsmodes.qcombobox(self.cmbPCI) self.cmbPCI.setCurrentIndex(1) currencies_qcombobox(self.cmbCurrency, self.mem.localcurrency) self.mem.leverages.qcombobox(self.cmbApalancado) self.cmbApalancado.setCurrentIndex(1) self.mem.types.qcombobox(self.cmbTipo) self.cmbTipo.setCurrentIndex(0) self.product.mqtw_tickers(self.mqtwTickers) self.cmsAgrupations.setManagers(self.mem.settings, "frmProductReport", "cmsAgrupations", self.__agrupations_by_type(), None) elif self.__insert == False: self.cmsAgrupations.setManagers(self.mem.settings, "frmProductReport", "cmsAgrupations", self.__agrupations_by_type(), self.product.agrupations) self.lblInvestment.setText("{} ( {} )".format( self.product.name, self.product.id)) self.txtTPC.setText(str(self.product.percentage)) self.txtName.setText(self.product.name) self.txtISIN.setText(self.product.isin) self.product.mqtw_tickers(self.mqtwTickers) self.txtComentario.setText(self.product.comment) self.txtAddress.setText(self.product.address) self.txtWeb.setText(self.product.web) self.txtMail.setText(self.product.mail) self.txtPhone.setText(self.product.phone) self.spnDecimals.setValue(self.product.decimals) if self.product.has_autoupdate() == True: self.lblAutoupdate.setText( '<img src=":/xulpymoney/transfer.png" width="16" height="16"/> {}' .format( self.tr("Product prices are updated automatically"))) else: self.lblAutoupdate.setText( self.tr("Product prices are not updated automatically")) if self.product.obsolete == True: self.chkObsolete.setCheckState(Qt.Checked) if self.product.high_low == True: self.chkHL.setCheckState(Qt.Checked) self.mem.stockmarkets.qcombobox(self.cmbBolsa, self.product.stockmarket) self.mem.investmentsmodes.qcombobox(self.cmbPCI, self.product.mode) currencies_qcombobox(self.cmbCurrency, self.product.currency) self.mem.leverages.qcombobox(self.cmbApalancado, self.product.leveraged) self.mem.types.qcombobox(self.cmbTipo, self.product.type) else: #None, readonly mode self.lblInvestment.setText("{} ( {} )".format( self.product.name, self.product.id)) self.cmsAgrupations.setManagers(self.mem.settings, "frmProductReport", "cmsAgrupations", self.__agrupations_by_type(), None) self.txtTPC.setText(str(self.product.percentage)) self.txtName.setText(self.product.name) self.txtISIN.setText(self.product.isin) self.product.mqtw_tickers(self.mqtwTickers) self.txtComentario.setText(self.product.comment) self.txtAddress.setText(self.product.address) self.txtWeb.setText(self.product.web) self.txtMail.setText(self.product.mail) self.txtPhone.setText(self.product.phone) self.spnDecimals.setValue(self.product.decimals) if self.product.has_autoupdate() == True: self.lblAutoupdate.setText( '<img src=":/xulpymoney/transfer.png" width="16" height="16"/> {}' .format( self.tr("Product prices are updated automatically"))) else: self.lblAutoupdate.setText( self.tr("Product prices are not updated automatically")) if self.product.obsolete == True: self.chkObsolete.setCheckState(Qt.Checked) if self.product.high_low == True: self.chkHL.setCheckState(Qt.Checked) self.txtISIN.setReadOnly(True) self.txtName.setReadOnly(True) self.txtWeb.setReadOnly(True) self.txtAddress.setReadOnly(True) self.txtMail.setReadOnly(True) self.txtTPC.setReadOnly(True) self.txtPhone.setReadOnly(True) self.mqtwTickers.blockSignals(True) self.mqtwTickers.table.setEditTriggers( QAbstractItemView.NoEditTriggers) self.txtComentario.setReadOnly(True) setReadOnly(self.chkObsolete, True) setReadOnly(self.chkHL, True) self.cmdSave.setEnabled(False) self.spnDecimals.setReadOnly(True) bolsa = StockMarketManager(self.mem) bolsa.append(self.product.stockmarket) bolsa.qcombobox(self.cmbBolsa, self.product.stockmarket) productmodes = ProductModesManager(self.mem) productmodes.append(self.product.mode) productmodes.qcombobox(self.cmbPCI, self.product.mode) self.cmbCurrency.addItem( "{0} - {1} ({2})".format( self.product.currency, currency_name(self.product.currency), currency_symbol(self.product.currency)), self.product.currency) leverages = LeverageManager(self.mem) leverages.append(self.product.leveraged) leverages.qcombobox(self.cmbApalancado, self.product.leveraged) types = ProductTypeManager(self.mem) types.append(self.product.type) types.qcombobox(self.cmbTipo, self.product.type)
def wdgTS_update(self): self.wdgTS.clear() self.investment.needStatus(3) if self.investment.op.length() > 0: self.wdgTS.ts.setXFormat("date", self.tr("Date")) self.wdgTS.ts.setYFormat( self.investment.product.currency, self.tr("Amount ({})").format( currency_symbol(self.investment.account.currency)), self.investment.product.decimals) #Gets investment important datetimes: operations, dividends, init and current time. For each datetime adds another at the beginning of the day, to get mountains in graph datetimes = set() datetimes.add(self.investment.op.first().datetime - timedelta(days=30)) for op in self.investment.op.arr: datetimes.add(op.datetime) datetimes.add(op.datetime - timedelta(seconds=1)) for dividend in self.investment.dividends.arr: datetimes.add(dividend.datetime) datetimes.add(self.mem.localzone.now()) datetimes_list = list(datetimes) datetimes_list.sort() #Progress dialog self.wdgTS.ts.setProgressDialogEnabled(True) self.wdgTS.ts.setProgressDialogAttributes( None, self.tr("Loading {} special datetimes").format( len(datetimes_list)), QIcon(":xulpymoney/coins.png"), 0, len(datetimes_list)) #Draw lines invested = self.wdgTS.ts.appendTemporalSeries( self.tr("Invested amount")) balance = self.wdgTS.ts.appendTemporalSeries( self.tr("Investment balance")) gains = self.wdgTS.ts.appendTemporalSeries(self.tr("Net gains")) dividends = self.wdgTS.ts.appendTemporalSeries( self.tr("Net dividends")) gains_dividends = self.wdgTS.ts.appendTemporalSeries( self.tr("Net gains with dividends")) for i, dt in enumerate(datetimes_list): #Shows progress dialog self.wdgTS.ts.setProgressDialogNumber(i + 1) #Calculate dividends in datetime dividend_net = 0 for dividend in self.investment.dividends.arr: if dividend.datetime <= dt: dividend_net = dividend_net + dividend._net #Append data of that datetime tmp_investment = self.investment.Investment_At_Datetime(dt) gains_net = tmp_investment.op_historica.consolidado_neto( ).amount self.wdgTS.ts.appendTemporalSeriesData( invested, dt, tmp_investment.invertido().amount) self.wdgTS.ts.appendTemporalSeriesData( gains_dividends, dt, gains_net + dividend_net) self.wdgTS.ts.appendTemporalSeriesData( balance, dt, tmp_investment.balance(dt.date()).amount) self.wdgTS.ts.appendTemporalSeriesData(dividends, dt, dividend_net) self.wdgTS.ts.appendTemporalSeriesData(gains, dt, gains_net) self.wdgTS.display() #Markers are generated in display so working with markers must be after it self.wdgTS.ts.chart().legend().markers(gains)[0].clicked.emit() self.wdgTS.ts.chart().legend().markers(dividends)[0].clicked.emit() self.wdgTS.ts.chart().legend().markers(balance)[0].clicked.emit()