Пример #1
0
    def scriptTipos(self):
        self.viewTipo.clear()

        for t in self.mem.types.arr:
            total = Money(self.mem, 0, self.mem.localcurrency)
            for i in self.mem.data.investments_active().arr:
                if i.product.type == t:
                    if self.radCurrent.isChecked():
                        total = total + i.balance().local()
                    else:
                        total = total + i.invertido().local()
            if t.id == 11:  #Accounts
                total = total + self.accounts
            if total.isGTZero():
                if t.id == 11:  #Accounts
                    self.viewTipo.pie.appendData(t.name.upper(), total, True)
                else:
                    self.viewTipo.pie.appendData(t.name.upper(), total)
        if self.radCurrent.isChecked():
            self.viewTipo.pie.setTitle(
                self.tr("Investment current balance by product type"))
        else:
            self.viewTipo.pie.setTitle(
                self.tr("Invested balance by product type"))
        self.viewTipo.display()
Пример #2
0
 def balance(self, fecha=None, type=eMoneyCurrency.User):
     """Función que calcula el balance de una cuenta
     Solo asigna balance al atributo balance si la fecha es actual, es decir la actual
     Parámetros:
         - pg_cursor cur Cursor de base de datos
         - date fecha Fecha en la que calcular el balance
     Devuelve:
         - Decimal balance Valor del balance
     type=2, account currency
     type=3 localcurrency
     """
     cur = self.mem.con.cursor()
     if fecha == None:
         fecha = date.today()
     cur.execute(
         'select sum(amount) from accountsoperations where accounts_id=' +
         str(self.id) + " and datetime::date<='" + str(fecha) + "';")
     res = cur.fetchone()[0]
     cur.close()
     if res == None:
         return Money(self.mem, 0, self.resultsCurrency(type))
     if type == eMoneyCurrency.Account:
         return Money(self.mem, res, self.currency)
     elif type == eMoneyCurrency.User:
         if fecha == None:
             dt = self.mem.localzone.now()
         else:
             dt = dtaware_day_end_from_date(fecha, self.mem.localzone_name)
         return Money(self.mem, res,
                      self.currency).convert(self.mem.localcurrency, dt)
Пример #3
0
    def reload(self):
        #Junta accountsoperations y creditcardsoperations y sobre esa subquery uni hace un group by
        rows = self.mem.con.cursor_rows("""
        select date_part('year',datetime)::int as year,  date_part('month',datetime)::int as month, sum(amount) as value 
        from ( 
                    SELECT accountsoperations.datetime, accountsoperations.concepts_id,  accountsoperations.amount  FROM accountsoperations where concepts_id={0} 
                        UNION ALL 
                    SELECT creditcardsoperations.datetime, creditcardsoperations.concepts_id, creditcardsoperations.amount FROM creditcardsoperations where concepts_id={0}
                ) as uni 
        group by date_part('year',datetime), date_part('month',datetime) order by 1,2 ;
        """.format(self.concept.id))

        if len(rows) == 0:  #Due it may have no data
            return

        self.firstyear = int(rows[0]['year'])

        hh = [
            self.tr("Year"),
            self.tr("January"),
            self.tr("February"),
            self.tr("March"),
            self.tr("April"),
            self.tr("May"),
            self.tr("June"),
            self.tr("July"),
            self.tr("August"),
            self.tr("September"),
            self.tr("October"),
            self.tr("November"),
            self.tr("December"),
            self.tr("Total")
        ]
        data = []
        # Create all data spaces filling year
        for year in range(self.firstyear, date.today().year + 1):
            data.append([
                year,
            ] + [None] * 13)
        # Fills spaces with values
        for row in rows:
            for rowdata in data:
                if rowdata[0] == row['year']:
                    rowdata[row['month']] = Money(self.mem, row['value'],
                                                  self.mem.localcurrency)
                rowdata[13] = lor_sum_row(
                    rowdata, 1, 12, Money(self.mem, 0, self.mem.localcurrency))

        total = lor_sum_column(data, 13, 0,
                               len(data) - 1,
                               Money(self.mem, 0, self.mem.localcurrency))
        data.append([self.tr("Total")] + ["#crossedout"] * 12 + [
            total,
        ])
        self.mqtwReport.setData(hh, None, data)
Пример #4
0
 def net(self, type=eMoneyCurrency.Product):
     if type == 1:
         return Money(self.mem, self._net, self.investment.product.currency)
     elif type == 2:
         return Money(self.mem, self._net,
                      self.investment.product.currency).convert_from_factor(
                          self.investment.account.currency,
                          self.currency_conversion)
     elif type == 3:
         return Money(self.mem, self._net,
                      self.investment.product.currency).convert_from_factor(
                          self.investment.account.currency,
                          self.currency_conversion).local(self.datetime)
Пример #5
0
    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"))
Пример #6
0
 def dps(self, type=eMoneyCurrency.Product):
     "Dividend per share"
     if type == 1:
         return Money(self.mem, self.dpa, self.investment.product.currency)
     elif type == 2:
         return Money(self.mem, self.dpa,
                      self.investment.product.currency).convert_from_factor(
                          self.investment.account.currency,
                          self.currency_conversion)
     elif type == 3:
         return Money(self.mem, self.dpa,
                      self.investment.product.currency).convert_from_factor(
                          self.investment.account.currency,
                          self.currency_conversion).local(self.datetime)
Пример #7
0
 def amount(self, type=eMoneyCurrency.Product):
     money = Money(
         self.mem,
         self.shares * self.price *
         self.investment.product.real_leveraged_multiplier(),
         self.investment.product.currency)
     if type == eMoneyCurrency.Product:
         return money
     elif type == eMoneyCurrency.Account:
         dt = dtaware_day_end_from_date(self.date, self.mem.localzone_name)
         return money.convert(self.investment.account.currency, dt)
     elif type == eMoneyCurrency.User:
         dt = dtaware_day_end_from_date(self.date, self.mem.localzone_name)
         return money.convert(self.investment.account.currency,
                              dt).convert(self.mem.localcurrency, dt)
Пример #8
0
    def shares(self):
        resultado = Decimal(0)

        if self.radDes.isChecked():  #DESINVERSION
            perdida = Money(self.mem, self.txtSimulacion.decimal(),
                            self.investment.product.currency
                            )  #Va disminuyendo con las distintas operaciones
            q = Quote(self.mem).init__create(
                self.investment.product,
                datetime.now(timezone(self.mem.localzone_name)),
                self.txtValorAccion.decimal())
            for rec in self.investment.op_actual.arr:
                pendiente = rec.pendiente(q)
                if (perdida + pendiente).isZero():
                    resultado = resultado + rec.shares
                    break
                elif (perdida + pendiente).isGTZero():
                    resultado = resultado + rec.shares
                    perdida = perdida + pendiente
                elif (perdida + pendiente).isLTZero():
                    # Si de tantas shares queda pendiente "pendiente"
                    # X                                queda la perdida
                    shares = abs(
                        int(perdida.amount * rec.shares / pendiente.amount))
                    resultado = resultado + Decimal(
                        shares
                    )  #Se resta porque se debe calcular antes de quitarse el pendiente
                    break
        else:  #REINVERSION
            resultado = Decimal(
                int(self.txtSimulacion.decimal() /
                    self.txtValorAccion.decimal()))
        return resultado
Пример #9
0
 def on_txtBruto_textChanged(self):
     self.wdgCurrencyConversion.setConversion(
         Money(self.mem, self.txtBruto.decimal(),
               self.investment.product.currency),
         self.investment.account.currency, self.wdgDT.datetime(),
         self.wdgCurrencyConversion.factor)
     self.calcular()
Пример #10
0
    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))
Пример #11
0
 def m_target_gains(self, dInvested):
     try:
         shares=dInvested/self.entry
         value= (self.target-self.entry)*shares
         value=-value if self.short==True else value
     except:
         value= Decimal(0)
     return Money(self.mem, value, self.product.currency)
Пример #12
0
 def m_stop_loss_losses(self, dInvested):
     try:
         shares=dInvested/self.entry
         value= (self.stoploss-self.entry)*shares
         value=-value if self.short==True else value
     except:
         value= Decimal(0)
     return Money(self.mem, value, self.product.currency)
Пример #13
0
 def net(self, emoneycurrency, current):
     r = Money(self.mem, 0, self.investment.resultsCurrency(emoneycurrency))
     for d in self.arr:
         if current == True and self.investment.op_actual.length(
         ) > 0 and d.datetime < self.investment.op_actual.first().datetime:
             continue
         else:
             r = r + d.net(emoneycurrency)
     return r
Пример #14
0
    def update_tables(self):
        #Actualiza el indice de referencia porque ha cambiado
        self.investment.op_actual.get_valor_benchmark(self.mem.data.benchmark)

        self.on_chkOperaciones_stateChanged(self.chkOperaciones.checkState())
        self.chkOperaciones.setEnabled(True)

        self.investment.op_actual.myqtablewidget(
            self.mqtwInvestmentCurrent,
            self.investment.product.result.basic.last,
            type=1)
        self.investment.op_historica.myqtablewidget(
            self.mqtwInvestmentHistorical, type=1)
        if self.investment.product.currency == self.investment.account.currency:  #Multidivisa
            self.grpCurrentAccountCurrency.hide()
            self.grpHistoricalAccountCurrency.hide()
        else:
            m = Money(self.mem, 1, self.investment.account.currency)

            self.grpCurrentAccountCurrency.setTitle(
                self.tr("Current status in account currency ( {} = {} at {} )"
                        ).format(
                            m.string(6),
                            m.convert(self.investment.product.currency,
                                      self.mem.localzone.now()).string(6),
                            m.conversionDatetime(
                                self.investment.product.currency,
                                self.mem.localzone.now())))
            self.investment.op_actual.myqtablewidget(
                self.mqtwInvestmentCurrentAccountCurrency,
                self.investment.product.result.basic.last,
                type=2)
            self.investment.op_historica.myqtablewidget(
                self.mqtwInvestmentHistoricalAccountCurrency, type=2)

        self.lblAge.setText(
            self.tr("Current operations average age: {0}".format(
                days2string(self.investment.op_actual.average_age()))))

        if self.investment != None:  #We are adding a new investment
            self.on_chkHistoricalDividends_stateChanged(
                self.chkHistoricalDividends.checkState())
            self.chkHistoricalDividends.setEnabled(True)
Пример #15
0
def RankingManager_from_current_operations(mem):
    r = RankingManager(mem)
    for product in mem.data.investments.ProductManager_with_investments_distinct_products(
    ).arr:
        current = Money(mem, 0, mem.localcurrency)
        historical = Money(mem, 0, mem.localcurrency)
        dividends = Money(mem, 0, mem.localcurrency)

        for inv in mem.data.investments.arr:
            if inv.product.id == product.id:
                current = current + inv.op_actual.pendiente(
                    inv.product.result.basic.last, 3)
                historical = historical + inv.op_historica.consolidado_bruto(
                    type=3)
                dividends = dividends + inv.dividends.gross(
                    eMoneyCurrency.User, current=False)
        r.append(Ranking(mem, product, current, historical, dividends))
    r.sort_by_total()
    return r
Пример #16
0
    def scriptCountry(self):
        self.viewCountry.clear()

        for c in self.mem.countries.arr:
            total = Money(self.mem, 0, self.mem.localcurrency)
            for i in self.mem.data.investments_active().arr:
                if i.product.stockmarket.country == c:
                    if self.radCurrent.isChecked():
                        total = total + i.balance().local()
                    else:
                        total = total + i.invertido().local()
            if total.isGTZero():
                self.viewCountry.pie.appendData(c.name.upper(), total)
        if self.radCurrent.isChecked():
            self.viewCountry.pie.setTitle(
                self.tr("Investment current balance by country"))
        else:
            self.viewCountry.pie.setTitle(
                self.tr("Invested balance by country"))
        self.viewCountry.display()
Пример #17
0
    def scriptApalancado(self):
        self.viewApalancado.clear()

        for a in self.mem.leverages.arr:
            total = Money(self.mem, 0, self.mem.localcurrency)
            for i in self.mem.data.investments_active().arr:
                if i.product.leveraged == a:
                    if self.radCurrent.isChecked():
                        total = total + i.balance().local()
                    else:
                        total = total + i.invertido().local()
            if a.id == eLeverageType.NotLeveraged:  #Accounts
                total = total + self.accounts
            if total.isGTZero():
                self.viewApalancado.pie.appendData(a.name.upper(), total)
        if self.radCurrent.isChecked():
            self.viewApalancado.pie.setTitle(
                self.tr("Investment current balance by leverage"))
        else:
            self.viewApalancado.pie.setTitle(
                self.tr("Invested balance by leverage"))
        self.viewApalancado.display()
Пример #18
0
 def scriptTPC(self):
     self.viewTPC.clear()
     for r in range(0, 11):
         total = Money(self.mem, 0, self.mem.localcurrency)
         for i in self.mem.data.investments_active().arr:
             if ceil(i.product.percentage / 10.0) == r:
                 if self.radCurrent.isChecked():
                     total = total + i.balance().local()
                 else:
                     total = total + i.invertido().local()
         if r == 0:
             total = total + self.accounts
         if total.isGTZero():
             self.viewTPC.pie.appendData("{0}% variable".format(r * 10),
                                         total)
     if self.radCurrent.isChecked():
         self.viewTPC.pie.setTitle(
             self.tr("Investment current balance by variable percentage"))
     else:
         self.viewTPC.pie.setTitle(
             self.tr("Invested balance by variable percentage"))
     self.viewTPC.display()
Пример #19
0
    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()
Пример #20
0
    def __calcular(self):
        #Setting self.investmentsoperations variable
        if self.chkPonderanAll.checkState()==Qt.Checked:#Results are in self.mem.localcurrency
            self.investmentsoperations=self.mem.data.investments_active().Investment_merging_current_operations_with_same_product(self.investment.product).op_actual
            self.investmentsoperations.myqtablewidget(self.mqtw)
        else:#Results in account currency
            self.investmentsoperations=InvestmentOperationCurrentHomogeneusManager(self.mem, self.investment)

            if self.chkGainsTime.checkState()==Qt.Checked:
                self.investmentsoperations=self.investment.op_actual.ObjectManager_copy_until_datetime(self.mem.localzone.now()-datetime.timedelta(days=365))
            else:
                self.investmentsoperations=self.investment.op_actual.ObjectManager_copy_until_datetime(self.mem.localzone.now())
            self.investmentsoperations.myqtablewidget(self.mqtw, self.investment.product.result.basic.last,  eMoneyCurrency.Account)
        sumacciones=self.investmentsoperations.shares()
        
        #Calculations
        if sumacciones==Decimal(0):
            self.puntoventa=Money(self.mem, 0, self.investment.account.currency)
        else:
            if self.radTPC.isChecked()==True:
                percentage=Percentage(self.spnGainsPercentage.value(), 100)
                self.puntoventa=self.investmentsoperations.selling_price_to_gain_percentage_of_invested(percentage, eMoneyCurrency.Account)
            elif self.radPrice.isChecked()==True:
                if self.txtPrice.isValid():#Si hay un number bien
                    self.puntoventa=Money(self.mem,  self.txtPrice.decimal(),  self.investment.product.currency)
                    self.cmd.setEnabled(True)
                else:
                    self.puntoventa=Money(self.mem, 0, self.investment.product.currency)
                    self.cmd.setEnabled(False)
            elif self.radGain.isChecked()==True:
                if self.txtGanancia.isValid():#Si hay un number bien
                    self.puntoventa=self.investmentsoperations.selling_price_to_gain_money(Money(self.mem, self.txtGanancia.decimal(), self.investment.product.currency))
                    self.cmd.setEnabled(True)
                else:
                    self.puntoventa=Money(self.mem, 0, self.investment.account.currency)
                    self.cmd.setEnabled(False)

        quote=Quote(self.mem).init__create(self.investment.product, self.mem.localzone.now(), self.puntoventa.amount)
        self.tab.setTabText(1, self.tr("Selling point: {0}".format(self.puntoventa)))
        self.tab.setTabText(0, self.tr("Current state: {0}".format(quote.money())))
        self.investmentsoperations.myqtablewidget(self.mqtwSP, quote, eMoneyCurrency.Account) 
        
        if self.chkPonderanAll.checkState()==Qt.Checked:
            self.cmd.setText(self.tr("Set selling price to all investments  of {0} to gain {1}").format(self.puntoventa, self.investmentsoperations.pendiente(quote, eMoneyCurrency.Account)))
        else:
            self.cmd.setText(self.tr("Set {0} shares selling price to {1} to gain {2}").format(sumacciones, self.puntoventa, self.investmentsoperations.pendiente(quote, eMoneyCurrency.Account)))
Пример #21
0
    def derivatives_adjustments(self):
        if hasattr(self, "_derivatives_adjustments") is False:
            ## WRONG IF SEVERAL CURRENCY IN ADJUSTMENTS
            self._derivatives_adjustments = self.mem.con.cursor_one_field(
                """
select 
    sum(amount)
from 
    accountsoperations 
where 
    concepts_id in (%s) AND
    date_part('year',datetime)=%s and 
    date_part('month',datetime)=%s
""", (eConcept.DerivativesAdjustment, self.year, self.month))
        return Money(self.mem, self._derivatives_adjustments,
                     self.mem.localcurrency)
Пример #22
0
    def load_data(self):        
        inicio=datetime.now()
        self.mqtw.applySettings()
        self.mqtw.table.setRowCount(date.today().year-self.wdgYear.year+1+1)
        lastsaldo=Money(self.mem)
        sumdividends=Money(self.mem)
        sumgains=Money(self.mem)
        sumexpenses=Money(self.mem)
        sumincomes=Money(self.mem)
        sumicdg=Money(self.mem)
        
        hh=[self.tr("Year"), self.tr("Initial balance"), self.tr("Final balance"), self.tr("Difference"), self.tr("Incomes"), self.tr("Net gains"), self.tr("Net dividends"), self.tr("Expenses"), self.tr("I+G+D-E")]
        data=[]
        for i in range(self.dt_report_start.year, self.dt_report_end.year+1):
            #dt_start=dtaware_year_start(i, self.mem.localzone_name)
            dt_end=dtaware_year_end(i, self.mem.localzone_name)
            if self.progress.wasCanceled():
                break;
            else:
                self.progress.setValue(self.progress.value()+1)
            si=lastsaldo
            sf=Assets(self.mem).saldo_total(self.mem.data.investments, dt_end.date())
            expenses=Assets(self.mem).saldo_anual_por_tipo_operacion( i,1)#+Assets(self.mem).saldo_anual_por_tipo_operacion (cur,i, 7)#expenses + Facturación de tarjeta
            dividends=Assets(self.mem).dividends_neto( i)
            incomes=Assets(self.mem).saldo_anual_por_tipo_operacion(  i,2)-dividends #Se quitan los dividends que luego se suman
            gains=Assets(self.mem).consolidado_neto(self.mem.data.investments,  i)
            
            self.dates.append(dt_end.date())
            self.expenses.append(-expenses.amount)
            self.dividends.append(dividends.amount)
            self.incomes.append(incomes.amount)
            self.gains.append(gains.amount)

            gi=incomes+dividends+gains+expenses     
            data.append([
                i, 
                si, 
                sf, 
                (sf-si), 
                incomes, 
                gains, 
                dividends,
                expenses, 
                gi, 
            ])
            sumdividends=sumdividends+dividends
            sumgains=sumgains+gains
            sumexpenses=sumexpenses+expenses
            sumincomes=sumincomes+incomes
            sumicdg=sumicdg+gi
            lastsaldo=sf
        data.append([self.tr("Total"), "#crossedout","#crossedout","#crossedout",sumincomes,sumgains,sumdividends,sumexpenses,sumicdg])
        self.mqtw.setData(hh, None, data)
        debug("wdgAPR > load_data: {}".format(datetime.now()-inicio))
Пример #23
0
 def calculate(self):
     """Checks if compulsory fields are ok, if not changes style to red, else calculate mqtw and shares"""
     if self.txtAmount.isValid() and self.txtFinalPrice.isValid():
         finalprice = Money(self.mem, self.txtFinalPrice.decimal(),
                            self.product.currency).convert(
                                self.mem.localcurrency).amount
         if self.product.type.id in (eProductType.Share,
                                     eProductType.ETF):  #Shares
             self.txtShares.setText(
                 round(self.txtAmount.decimal() / finalprice, 0))
         else:
             self.txtShares.setText(
                 round(self.txtAmount.decimal() / finalprice, 6))
         porcentages = [2.5, 5, 7.5, 10, 15, 30]
         self.mqtw.table.setColumnCount(3)
         self.mqtw.table.setHorizontalHeaderItem(
             0, QTableWidgetItem(self.tr("% Gains")))
         self.mqtw.table.setHorizontalHeaderItem(
             1, QTableWidgetItem(self.tr("Price")))
         self.mqtw.table.setHorizontalHeaderItem(
             2, QTableWidgetItem(self.tr("Gains")))
         self.mqtw.table.clearContents()
         self.mqtw.applySettings()
         self.mqtw.table.setRowCount(len(porcentages))
         for i, tpc in enumerate(porcentages):
             self.mqtw.table.setItem(
                 i, 0,
                 Percentage(tpc, 100).qtablewidgetitem())
             tpcprice = self.txtFinalPrice.decimal() * Decimal(1 +
                                                               tpc / 100)
             self.mqtw.table.setItem(
                 i, 1,
                 self.product.money(tpcprice).qtablewidgetitem())
             self.mqtw.table.setItem(
                 i, 2,
                 self.product.money(
                     self.txtShares.decimal() *
                     (tpcprice -
                      self.txtFinalPrice.decimal())).qtablewidgetitem())
Пример #24
0
 def scriptPCI(self):
     self.viewPCI.clear()
     for mode in self.mem.investmentsmodes.arr:
         total = Money(self.mem, 0, self.mem.localcurrency)
         for i in self.mem.data.investments_active().arr:
             for o in i.op_actual:
                 if o.pci_position() == mode.id:
                     if self.radCurrent.isChecked():
                         total = total + o.balance(
                             i.product.result.basic.last,
                             eMoneyCurrency.User)
                     else:
                         total = total + o.invertido(eMoneyCurrency.User)
         if mode.id == 'c':
             total = total + self.accounts
         self.viewPCI.pie.appendData(mode.name.upper(), total)
     if self.radCurrent.isChecked():
         self.viewPCI.pie.setTitle(
             self.tr("Investment current balance by Put / Call / Inline"))
     else:
         self.viewPCI.pie.setTitle(
             self.tr("Invested balance by Put / Call / Inline"))
     self.viewPCI.display()
Пример #25
0
 def balance(self, date=None):
     """Give the sum of all accounts balances in self.arr"""
     res = Money(self.mem, 0, self.mem.localcurrency)
     for ac in self.arr:
         res = res + ac.balance(date, type=3)
     return res
Пример #26
0
 def money(self, amount):
     return Money(self.mem, amount, self.currency)
Пример #27
0
    def myqtablewidget(self, wdg, emoneycurrency, current=True):
        wdg.table.setColumnCount(7)
        wdg.table.setHorizontalHeaderItem(0, qcenter(self.tr("Date")))
        wdg.table.setHorizontalHeaderItem(1, qcenter(self.tr("Concept")))
        wdg.table.setHorizontalHeaderItem(2, qcenter(self.tr("Gross")))
        wdg.table.setHorizontalHeaderItem(3, qcenter(self.tr("Withholding")))
        wdg.table.setHorizontalHeaderItem(4, qcenter(self.tr("Comission")))
        wdg.table.setHorizontalHeaderItem(5, qcenter(self.tr("Net")))
        wdg.table.setHorizontalHeaderItem(6, qcenter(self.tr("DPS")))
        #DATA
        wdg.applySettings()
        wdg.table.clearContents()

        currency = self.investment.resultsCurrency(emoneycurrency)

        wdg.table.setRowCount(self.length() + 1)
        sumneto = Money(self.mem, 0, currency)
        sumbruto = Money(self.mem, 0, currency)
        sumretencion = Money(self.mem, 0, currency)
        sumcomision = Money(self.mem, 0, currency)
        for i, d in enumerate(self.arr):
            if current == True and self.investment.op_actual.length(
            ) > 0 and d.datetime < self.investment.op_actual.first().datetime:
                wdg.table.hideRow(i)
                continue
            else:
                wdg.table.showRow(i)
            sumneto = sumneto + d.net(emoneycurrency)
            sumbruto = sumbruto + d.gross(emoneycurrency)
            sumretencion = sumretencion + d.retention(emoneycurrency)
            sumcomision = sumcomision + d.commission(emoneycurrency)
            wdg.table.setItem(i, 0,
                              qdatetime(d.datetime, self.mem.localzone_name))
            wdg.table.setItem(i, 1, qleft(d.opercuenta.concept.name))
            wdg.table.setItem(i, 2, d.gross(emoneycurrency).qtablewidgetitem())
            wdg.table.setItem(i, 3,
                              d.retention(emoneycurrency).qtablewidgetitem())
            wdg.table.setItem(i, 4,
                              d.commission(emoneycurrency).qtablewidgetitem())
            wdg.table.setItem(i, 5, d.net(emoneycurrency).qtablewidgetitem())
            wdg.table.setItem(i, 6, d.dps(emoneycurrency).qtablewidgetitem())
        wdg.table.setItem(self.length(), 1, qleft(self.tr("TOTAL")))
        wdg.table.setItem(self.length(), 2, sumbruto.qtablewidgetitem())
        wdg.table.setItem(self.length(), 3, sumretencion.qtablewidgetitem())
        wdg.table.setItem(self.length(), 4, sumcomision.qtablewidgetitem())
        wdg.table.setItem(self.length(), 5, sumneto.qtablewidgetitem())
        return (sumneto, sumbruto, sumretencion, sumcomision)
Пример #28
0
 def commission(self):
     r = Money(self.mem, 0, self.mem.localcurrency)
     for d in self.arr:
         r = r + d.commission(eMoneyCurrency.User)
     return r
Пример #29
0
 def retention(self):
     r = Money(self.mem, 0, self.mem.localcurrency)
     for d in self.arr:
         r = r + d.retention(eMoneyCurrency.User)
     return r
Пример #30
0
 def gross(self):
     r = Money(self.mem, 0, self.mem.localcurrency)
     for d in self.arr:
         r = r + d.gross(eMoneyCurrency.User)
     return r