Exemplo n.º 1
0
    def __init__(self, mem, account,  parent=None):
        QDialog.__init__(self, parent)
        self.mem=mem
        self.account=account#Registro de account
        self.setupUi(self)
        self.showMaximized()
        self.cmdDatos.setEnabled(False)     
        self.wdgDtPago.show_microseconds(False)
        self.wdgDtPago.show_timezone(False)
        self.wdgDtPago.setTitle(self.tr("Select payment time"))
        
        self.creditcardoperations=CreditCardOperationManager(self.mem)#CreditCardOperationManager. Selected will be another CreditCardOperationManager
          
        self.mqtwOperations.setSettings(self.mem.settings, "frmAccountsReport", "mqtwOperations")
        self.mqtwOperations.table.customContextMenuRequested.connect(self.on_mqtwOperations_customContextMenuRequested)

        self.mqtwCreditCards.setSettings(self.mem.settings, "frmAccountsReport", "mqtwCreditCards")
        self.mqtwCreditCards.table.customContextMenuRequested.connect(self.on_mqtwCreditCards_customContextMenuRequested)

        self.mqtwCreditCardOperations.setSettings(self.mem.settings, "frmAccountsReport", "mqtwCreditCardOperations")
        self.mqtwCreditCardOperations.table.customContextMenuRequested.connect(self.on_mqtwCreditCardOperations_customContextMenuRequested)
        self.mqtwCreditCardOperations.setSelectionMode(QAbstractItemView.SelectRows, QAbstractItemView.MultiSelection)

        self.mqtwCreditCardOperationsHistorical.setSettings(self.mem.settings, "frmAccountsReport", "mqtwCreditCardOperationsHistorical")
    
        self.wdgDtPago.set(datetime.now(), self.mem.localzone_name)
        
        currencies_qcombobox(self.cmbCurrency)
        self.mem.data.banks_active().qcombobox(self.cmbEB)
                    
        if self.account is None:
            self.account_insert=True
            self.account=Account(self.mem)
            self.lblTitulo.setText(self.tr("New account data"))
            self.tab.setCurrentIndex(0)
            self.tab.setTabEnabled(1, False)
            self.tab.setTabEnabled(2, False)
            self.chkActiva.setChecked(True)
            self.chkActiva.setEnabled(False)
            self.mqtwOperations.setEnabled(False)
            self.cmdDatos.setText(self.tr("Add a new account"))
        else:
            self.account_insert=False
            self.account.needStatus(1)
            self.tab.setCurrentIndex(0)
            self.lblTitulo.setText(self.account.name)
            self.txtAccount.setText(self.account.name)
            self.txtNumero.setText(str(self.account.number))            
            self.cmbEB.setCurrentIndex(self.cmbEB.findData(self.account.bank.id))
            self.cmbEB.setEnabled(False)    
            self.cmbCurrency.setCurrentIndex(self.cmbCurrency.findData(self.account.currency))
            self.cmbCurrency.setEnabled(False)
            self.chkActiva.setChecked(self.account.active)
            self.cmdDatos.setText(self.tr("Update account data"))

            dtFirst=Assets(self.mem).first_datetime_allowed_estimated()       
            dtLast=Assets(self.mem).last_datetime_allowed_estimated()
            self.wdgYM.initiate(dtFirst.year,  dtLast.year, date.today().year, date.today().month)
            self.on_wdgYM_changed()
            self.mqtwCreditCards_update()
Exemplo n.º 2
0
    def __init__(self, mem,  parent=None):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.mem=mem
        self.selected=None
        
        self.viewIncomes=VCPie()
        self.viewIncomes.setSettings(self.mem.settings, "wdgConcepts", "viewIncomes")
        self.layIncomes.addWidget(self.viewIncomes)
        self.viewExpenses=VCPie()
        self.viewExpenses.setSettings(self.mem.settings, "wdgConcepts", "viewExpenses")
        self.layExpenses.addWidget(self.viewExpenses)
        self.expenses=ConceptManager_by_operationtype(mem, 1)
        self.expenseslist=None
        self.incomes=ConceptManager_by_operationtype(mem, 2)
        self.incomeslist=None

        self.mqtwExpenses.setSettings(self.mem.settings, "wdgConcepts", "mqtwExpenses")
        self.mqtwExpenses.table.customContextMenuRequested.connect(self.on_mqtwExpenses_customContextMenuRequested)
        self.mqtwIncomes.setSettings(self.mem.settings, "wdgConcepts", "mqtwIncomes")
        self.mqtwIncomes.table.customContextMenuRequested.connect(self.on_mqtwIncomes_customContextMenuRequested)
        
        dtFirst=Assets(self.mem).first_datetime_allowed_estimated()       
        dtLast=Assets(self.mem).last_datetime_allowed_estimated()
        self.wdgYM.initiate(dtFirst.year,  dtLast.year, date.today().year, date.today().month)
        self.wdgYM.changed.connect(self.on_wdgYM_changed)
        
        
        self.on_wdgYM_changed()
        
        self.tab.setCurrentIndex(0)
Exemplo n.º 3
0
    def __init__(self, mem, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.mem = mem
        dtFirst = Assets(self.mem).first_datetime_allowed_estimated()
        dtLast = Assets(self.mem).last_datetime_allowed_estimated()

        self.wy.initiate(dtFirst.year, dtLast.year, date.today().year)
        self.wy.changed.connect(self.on_wy_mychanged)
        self.wy.label.hide()
        self.wy.hide()

        self.wym.initiate(dtFirst.year, dtLast.year,
                          date.today().year,
                          date.today().month)
        self.wym.changed.connect(self.on_wym_mychanged)
        self.wym.label.hide()

        self.mqtw.setSettings(self.mem.settings, "wdgInvestmentsOperations",
                              "mqtw")
        self.mqtw.table.customContextMenuRequested.connect(
            self.on_mqtw_customContextMenuRequested)
        self.mqtwCurrent.setSettings(self.mem.settings,
                                     "wdgInvestmentsOperations", "mqtwCurrent")
        self.mqtwCurrent.table.customContextMenuRequested.connect(
            self.on_mqtwCurrent_customContextMenuRequested)
        self.tab.setCurrentIndex(0)
        self.load()
        self.load_current()
Exemplo n.º 4
0
    def __init__(self, mem, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.mem = mem

        dtFirst = Assets(self.mem).first_datetime_allowed_estimated()
        dtLast = Assets(self.mem).last_datetime_allowed_estimated()

        #Adding more months that needed to allow month and december previous calculations
        self.tmm = TotalMonthManager_from_month(self.mem, dtFirst.year,
                                                dtFirst.month, dtLast.year, 12)

        self.mqtwTotal.setSettings(self.mem.settings, "wdgDerivativesReport",
                                   "mqtwTotal")
        self.mqtwTotal.table.cellDoubleClicked.connect(
            self.on_mqtwTotal_cellDoubleClicked)
        self.mqtwTotal.table.customContextMenuRequested.connect(
            self.on_mqtwTotal_customContextMenuRequested)
        self.mqtwTotal.table.setSelectionBehavior(
            QAbstractItemView.SelectItems)
        self.mqtwTotal.table.itemSelectionChanged.connect(
            self.on_mqtwTotal_itemSelectionChanged)

        self.wyData.initiate(dtFirst.year, dtLast.year, date.today().year)
        self.tab.setCurrentIndex(0)

        self.tmm_data = TotalMonthManager_from_manager_extracting_year(
            self.tmm, self.wyData.year)
        self.load_data()
        self.load_data_second_tab()
        self.wyData.changed.connect(
            self.on_wyData_mychanged
        )  #Used my due to it took default on_wyData_changed
Exemplo n.º 5
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))
Exemplo n.º 6
0
 def __init__(self, mem, parent=None, name=None):
     """Simulations is the SimulationManager where the new simulation is going to be appended"""
     QWidget.__init__(self, parent)
     self.setupUi(self)
     self.mem = mem
     self.parent = parent
     self.simulation = None  #Simulation to be created
     self.mem.simulationtypes.qcombobox(self.cmbSimulationTypes)
     self.wdgStarting.set(
         Assets(self.mem).first_datetime_allowed_estimated(),
         self.mem.localzone_name)
     self.wdgEnding.set(
         Assets(self.mem).last_datetime_allowed_estimated(),
         self.mem.localzone_name)
     self.simcon = None  #Simulation connection
Exemplo n.º 7
0
    def __init__(self, mem, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.mem = mem
        self.hoy = date.today()

        self.viewTPC = VCPie()
        self.viewTPC.setSettings(self.mem.settings, "wdgInvestmentClasses",
                                 "viewTPC")
        self.layTPC.addWidget(self.viewTPC)
        self.viewPCI = VCPie()
        self.viewPCI.setSettings(self.mem.settings, "wdgInvestmentClasses",
                                 "viewPCI")
        self.layPCI.addWidget(self.viewPCI)
        self.viewTipo = VCPie()
        self.viewTipo.setSettings(self.mem.settings, "wdgInvestmentClasses",
                                  "viewTipo")
        self.layTipo.addWidget(self.viewTipo)
        self.viewApalancado = VCPie()
        self.viewApalancado.setSettings(self.mem.settings,
                                        "wdgInvestmentClasses",
                                        "viewApalancado")
        self.layApalancado.addWidget(self.viewApalancado)
        self.viewCountry = VCPie()
        self.viewCountry.setSettings(self.mem.settings, "wdgInvestmentClasses",
                                     "viewCountry")
        self.layCountry.addWidget(self.viewCountry)
        self.viewProduct = VCPie()
        self.viewProduct.setSettings(self.mem.settings, "wdgInvestmentClasses",
                                     "viewProduct")
        self.layProduct.addWidget(self.viewProduct)

        self.accounts = Assets(self.mem).saldo_todas_accounts(self.hoy).local()
        self.tab.setCurrentIndex(2)
Exemplo n.º 8
0
 def __init__(self, mem,  parent=None):
     QWidget.__init__(self, parent)
     self.setupUi(self)
     self.tab.setCurrentIndex(0)
     self.mem=mem
     self.progress = QProgressDialog(self.tr("Filling data of the report"), self.tr("Cancel"), 0,0)
     self.progress.setModal(True)
     self.progress.setWindowTitle(self.tr("Calculating data..."))
     self.progress.setWindowIcon(QIcon(":/xulpymoney/coins.png"))
     self.progress.setMinimumDuration(0)        
     self.mqtw.setSettings(self.mem.settings, "wdgAPR", "mqtw")
     self.mqtwReport.setSettings(self.mem.settings, "wdgAPR", "mqtwReport")
      
     
     dtFirst=Assets(self.mem).first_datetime_allowed_estimated()
     dtLast=Assets(self.mem).last_datetime_allowed_estimated()
     currentyear=self.mem.settingsdb.value_integer("wdgAPR/cmbYear", dtFirst.year)
     self.wdgYear.initiate(dtFirst.year,  dtLast.year, currentyear)#Push an wdgYear changed
     self.wdgYear.changed.connect(self.on_my_wdgYear_changed)
     self.on_my_wdgYear_changed()
Exemplo n.º 9
0
    def lblTotal_update(self):
        investments = self.investments.balance()
        accounts = self.mem.data.accounts_active().balance()
        total = Assets(self.mem).saldo_total(
            self.mem.data.investments_active(), self.mem.localzone.now())
        if self.chkInactivas.checkState() == Qt.Checked:
            self.lblTotal.setText(self.tr("There aren't invested assets"))
        else:
            self.lblTotal.setText(
                self.tr("""Accounts balance: {0}
Zero risk investments balance: {1}
Zero risk assests balance: {2} ( {3} from your total assets {4} )""").format(
                    accounts, investments, accounts + investments,
                    Percentage((accounts + investments).amount, total.amount),
                    total))
Exemplo n.º 10
0
 def init__from_db(self, year, lastyear_assests=None):
     cur=self.mem.con.cursor()
     
     if lastyear_assests==None:
         self.lastyear_assests=Assets(self.mem).saldo_total(self.mem.data.investments,  date(year-1, 12, 31))
     else:
         self.lastyear_assests=lastyear_assests
     
     cur.execute("select * from annualtargets where year=%s", (year, ))
     if cur.rowcount==0:
         self.year=year
         self.percentage=0
     else:
         row=cur.fetchone()
         self.year=year
         self.percentage=row['percentage']
         self.saved_in_db=True
     cur.close()
     return self
Exemplo n.º 11
0
    def load_data(self):
        self.product.needStatus(2)
        percentage_down=Percentage(self.spnDown.value(), 100)
        percentage_gains=Percentage(self.spnGains.value(), 100)
        self.prm=ProductRangeManager(self.mem, self.product, percentage_down, percentage_gains)
        self.prm.setInvestRecomendation(self.cmbRecomendations.currentIndex())
        
        onlyaccount=-1 if self.chkOnlyAccount.isChecked() is False else self.cmbOnlyAccount.itemData(self.cmbOnlyAccount.currentIndex())
        self.prm.mqtw(self.mqtw, self.chkOnlyFirst.isChecked(), onlyaccount)

        self.mem.settingsdb.setValue("wdgProductRange/spnDown_product_{}".format(self.product.id), self.spnDown.value())
        self.mem.settingsdb.setValue("wdgProductRange/spnGains_product_{}".format(self.product.id), self.spnGains.value())
        self.mem.settingsdb.setValue("wdgProductRange/invest_product_{}".format(self.product.id), self.txtInvertir.text())
        self.mem.settingsdb.setValue("wdgProductRange/invest_recomendation_{}".format(self.product.id), self.cmbRecomendations.currentIndex())
        self.mem.settingsdb.setValue("wdgProductRange/product", self.product.id)
        self.mem.settings.sync()

        s=self.tr("Product current price: {} at {}").format(
            self.product.result.basic.last.money(),
            self.product.result.basic.last.datetime, 
        )
        s=s + "\n" + self.tr("Product price limits: {}").format(self.product.result.ohclYearly.string_limits())
        s=s + "\n" + self.tr("Total invested: {}. Current balance: {} ({})").format(
            self.investment_merged.invertido(),  
            self.investment_merged.balance(), 
            self.investment_merged.op_actual.tpc_total(self.product.result.basic.last), 
        )
        s=s + "\n" + self.tr("Average price: {}").format(
            self.investment_merged.op_actual.average_price()
        )
        s=s + "\n" + self.tr("Selling price to gain {}: {}. Gains at this selling price: {} ({})").format(
            percentage_gains, 
            self.investment_merged.op_actual.selling_price_to_gain_percentage_of_invested(percentage_gains, eMoneyCurrency.Product), 
            self.investment_merged.op_actual.gains_from_percentage(percentage_gains, eMoneyCurrency.Product), 
            percentage_between(self.product.result.basic.last.money(), self.investment_merged.op_actual.selling_price_to_gain_percentage_of_invested(percentage_gains, eMoneyCurrency.Product)), 
        )
        
        s=s + "\n\n"+ self.tr("Zero risk assets: {}".format(Assets(self.mem).patrimonio_riesgo_cero(date.today())))

        self.lblTotal.setText(s)
Exemplo n.º 12
0
 def gains(self):
     if hasattr(self, "_gains") is False:
         self._gains = Assets(self.mem).consolidado_neto(
             self.mem.data.investments, self.year, self.month)
     return self._gains
Exemplo n.º 13
0
 def incomes(self):
     if hasattr(self, "_incomes") is False:
         self._incomes = Assets(self.mem).saldo_por_tipo_operacion(
             self.year, self.month, 2) - self.dividends()
     return self._incomes
Exemplo n.º 14
0
 def dividends(self):
     if hasattr(self, "_dividends") is False:
         self._dividends = Assets(self.mem).dividends_neto(
             self.year, self.month)
     return self._dividends
Exemplo n.º 15
0
 def expenses(self):
     if hasattr(self, "_expenses") is False:
         self._expenses = Assets(self.mem).saldo_por_tipo_operacion(
             self.year, self.month,
             1)  #La facturación de tarjeta dentro esta por el union
     return self._expenses
Exemplo n.º 16
0
 def total_invested_real(self):
     if hasattr(self, "_total_invested_real") is False:
         self._total_invested_real = Assets(self.mem).invested_real(
             self.last_day())
     return self._total_invested_real
Exemplo n.º 17
0
 def total_bonds(self):
     if hasattr(self, "_total_bonds") is False:
         self._total_bonds = Assets(self.mem).saldo_todas_inversiones_bonds(
             self.last_day())
     return self._total_bonds
Exemplo n.º 18
0
 def total_investments_with_daily_adjustments(self):
     if hasattr(self, "_total_investments_with_daily_adjustments") is False:
         self._total_investments_with_daily_adjustments = Assets(
             self.mem).saldo_todas_inversiones_with_daily_adjustment(
                 self.last_day())
     return self._total_investments_with_daily_adjustments
Exemplo n.º 19
0
 def variables(self):
     self.vTotalLastYear=Assets(self.mem).saldo_total(self.mem.data.investments,  date(date.today().year-1, 12, 31))
     self.vTotal=Assets(self.mem).saldo_total(self.mem.data.investments,  date.today())
Exemplo n.º 20
0
    def body(self):
        # About
        self.header(self.tr("About Xulpymoney"), 1)
        
        # Assets
        self.header(self.tr("Assets"), 1)
        self.simpleParagraph(self.tr("Total assets of the user are {}.").format(self.vTotal))
        if self.vTotalLastYear.isZero()==False:
            moreorless=self.tr("more")
            if (self.vTotal-self.vTotalLastYear).isLTZero():
                moreorless=self.tr("less")
            self.simpleParagraph(self.tr("It's a {} {} of the total assets at the end of the last year.").format(Percentage(self.vTotal-self.vTotalLastYear, self.vTotalLastYear), moreorless))
        
        # Assets by bank
        self.header(self.tr("Assets by bank"), 2)
        self.mem.frmMain.on_actionBanks_triggered()
        
        model=self.mem.frmMain.w.mqtwBanks.officegeneratorModel()
        model.removeColumns([1,])
        model.odt_table(self, 10,  8 )

        self.simpleParagraph(self.tr("Sum of all bank balances is {}").format(self.mem.frmMain.w.banks.balance()))
        self.pageBreak(True)

        # Assests current year
        self.header(self.tr("Assets current year evolution"), 2)
        
        #wdgTotal
        self.mem.frmMain.on_actionTotalReport_triggered()
        model=self.mem.frmMain.w.mqtw.officegeneratorModel("mqtwTotal")
        model.odt_table(self, 26, 6)
                
        ## Target
        target=AnnualTarget(self.mem).init__from_db(date.today().year)
        self.simpleParagraph(self.tr("The investment system has established a {} year target.").format(target.percentage)+" " +
                self.tr("With this target you will gain {} at the end of the year.").format(self.mem.localmoney(target.annual_balance())) +" " +
                self.tr("Up to date you have got  {} (gains + dividends) what represents a {} of the target.").format(self.mem.frmMain.w.tmm.dividends()+self.mem.frmMain.w.tmm.gains(), Percentage(self.mem.frmMain.w.tmm.gains()+self.mem.frmMain.w.tmm.dividends(), target.annual_balance())))
        self.pageBreak(True)
        
        ### Assets evolution graphic
        self.header(self.tr("Assets graphical evolution"), 2)
        
        self.mem.frmMain.w.load_graphic(animations=False)
        self.mem.frmMain.w.tab.setCurrentIndex(1)
        savefile="{}/wdgTotal.png".format(self.dir)
        self.mem.frmMain.w.wdgTS.ts.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak()
        
        
        ### Current year investment gains by product type
        self.header(self.tr("Current year investment gains group by product type"), 2)
        self.mem.frmMain.w.on_actionGainsByProductType_triggered()
        model=self.mem.frmMain.w.tab.currentWidget().children()[1].officegeneratorModel("mqtwTotal")#Widget generated dinamically. mqtw is childre[1]
        model.odt_table(self, 18, 9)
        self.pageBreak()

        ## Accounts
        self.header(self.tr("Current Accounts"), 1)
        data=[]
        self.mem.data.accounts_active().order_by_name()
        for account in self.mem.data.accounts_active().arr:
            data.append((account.name, account.bank.name, account.balance()))
        self.table( [self.tr("Account"), self.tr("Bank"),  self.tr("Balance")], data, [6, 6, 3], 9)       
        
        self.simpleParagraph(self.tr("Sum of all account balances is {}").format(self.mem.data.accounts_active().balance()))

        
        self.pageBreak(True)
        
        ## Investments
        self.header(self.tr("Current investments"), 1)
        
        self.header(self.tr("Investments list"), 2)
        self.simpleParagraph(self.tr("Next list is sorted by the distance in percent to the selling point."))
        self.mem.frmMain.on_actionInvestments_triggered()
        
        model=self.mem.frmMain.w.mqtwInvestments.officegeneratorModel()
        model.removeColumns([1, 2, 3, 4])
        model.odt_table(self, 26,  8 )
        
        suminvertido=self.mem.data.investments_active().invested()
        sumpendiente=self.mem.data.investments_active().pendiente()
        if suminvertido.isZero()==False:
            self.simpleParagraph(self.tr("Sum of all invested assets is {}.").format(suminvertido))
            self.simpleParagraph(self.tr("Investment gains (positive minus negative results): {} - {} are {}, what represents a {} of total assets.").format(self.mem.data.investments_active().pendiente_positivo(), self.mem.data.investments_active().pendiente_negativo(), sumpendiente, Percentage(sumpendiente, suminvertido)))
            self.simpleParagraph(self.tr(" Assets average age: {}").format(  days2string(self.mem.data.investments_active().average_age())))
        else:
            self.simpleParagraph(self.tr("There aren't invested assets"))
        self.pageBreak(True)
        
        
        ### Current Investment Operations list
        self.header(self.tr("Current investment operations"), 2)
        self.mem.frmMain.on_actionInvestmentsOperations_triggered()
        model=self.mem.frmMain.w.mqtwCurrent.officegeneratorModel(self.tr("CurrentInvestmentOperations"))
        model.removeColumns([8, 9, 11])        
        model.odt_table(self, 26,  6)       
        self.pageBreak(True)
        
        ### Graphics wdgInvestments clases
        self.mem.frmMain.on_actionInvestmentsClasses_triggered()
        self.mem.frmMain.w.open_all_tabs()#Load tabs to finish animations
        self.mem.frmMain.w.viewTPC.on_actionShowData_triggered()
        self.mem.frmMain.w.viewTipo.on_actionShowData_triggered()
        self.mem.frmMain.w.viewApalancado.on_actionShowData_triggered()
        self.mem.frmMain.w.viewProduct.on_actionShowData_triggered()
        self.mem.frmMain.w.viewCountry.on_actionShowData_triggered()
        self.mem.frmMain.w.viewPCI.on_actionShowData_triggered()
        
        self.header(self.tr("Investments group by variable percentage"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasTPC_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(0)
        self.sleep(2)
        self.mem.frmMain.w.viewTPC.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by investment type"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasTipo_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(2)
        self.sleep(2)
        self.mem.frmMain.w.viewTipo.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by leverage"), 2)        
        savefile="{}/wdgInvestmentsClasses_canvasApalancado_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(3)
        self.sleep(2)
        self.mem.frmMain.w.viewApalancado.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by investment product"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasProduct_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(5)
        self.sleep(2)
        self.mem.frmMain.w.viewProduct.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by country"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasCountry_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(4)
        self.sleep(2)
        self.mem.frmMain.w.viewCountry.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by Call/Put/Inline"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasPCI_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(1)
        self.sleep(2)
        self.mem.frmMain.w.viewPCI.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        
        self.mem.frmMain.showMaximized()
        self.pageBreak(True)
        
        #Orders report
        self.header(self.tr("Investments orders"), 1)
        self.mem.frmMain.on_actionOrders_triggered()        
        self.simpleParagraph(self.tr("These are the current investment orders that have been set in your banks"))
        model=self.mem.frmMain.w.mqtwOrders.officegeneratorModel("mqtwOrders")
        model.odt_table(self, 26, 8)
        self.pageBreak(True)
        
        #Dividend report
        self.header(self.tr("Dividend estimations report"), 1)
        self.mem.frmMain.on_actionDividendsReport_triggered()
        model=self.mem.frmMain.w.mqtw.officegeneratorModel("mqtwDividendsReport")
        model.odt_table(self, 26, 8)
        self.simpleParagraph(self.tr("If I keep this investment during a year, I'll get {0}").format(Assets(self.mem).dividends_estimated()))
        self.pageBreak(True)
        
        # Ranking de investments
        self.header(self.tr("Historical investments ranking"), 1)    
        self.mem.frmMain.on_actionInvestmentRanking_triggered()
        model=self.mem.frmMain.w.mqtwCurrentOperations.officegeneratorModel("mqtwCurrentOperations")
        model.vh=list(range(1, len(model.data)+1))
        model.odt_table(self, 26, 8)        
Exemplo n.º 21
0
    def load_data(self):
        def investments(arr, min, max):
            resultado = ""
            for i in arr:
                if i[0] >= min and i[0] < max:
                    o = i[1]
                    resultado = resultado + self.tr(
                        "{0} {1} ({2}): {3} shares of {4} = {5}\n".format(
                            str(o.datetime)[:16], o.investment.name,
                            o.investment.account.name, round(o.shares, 0),
                            o.money_price(type=1), o.gross(type=1)))
            return resultado[:-1]

        ######################################################
        inicio = datetime.datetime.now()

        #Makes and array arr with investment current operations and sorts it
        arr = []
        maxoper = 0
        for i in self.mem.data.investments_active().arr:
            for o in i.op_actual.arr:
                if self.cmbShowOptions.currentIndex(
                ) == 0 and o.show_in_ranges == True:  #Show qualified
                    if maxoper < o.referenciaindice.quote:
                        maxoper = o.referenciaindice.quote
                    arr.append((o.referenciaindice.quote, o))
                elif self.cmbShowOptions.currentIndex(
                ) == 1 and i.product.type.id in (
                        eProductType.Share, eProductType.Warrant,
                        eProductType.ETF):  #Shares, Warrants, ETF
                    if maxoper < o.referenciaindice.quote:
                        maxoper = o.referenciaindice.quote
                    arr.append((o.referenciaindice.quote, o))
                elif self.cmbShowOptions.currentIndex(
                ) == 2 and i.product.type.id in (
                        eProductType.PrivateBond,
                        eProductType.PublicBond):  #Bonds
                    if maxoper < o.referenciaindice.quote:
                        maxoper = o.referenciaindice.quote
                    arr.append((o.referenciaindice.quote, o))
                elif self.cmbShowOptions.currentIndex(
                ) == 3 and i.product.type.id in (eProductType.Fund, ):  #Funds
                    if maxoper < o.referenciaindice.quote:
                        maxoper = o.referenciaindice.quote
                    arr.append((o.referenciaindice.quote, o))
                elif self.cmbShowOptions.currentIndex() == 4:
                    if maxoper < o.referenciaindice.quote:
                        maxoper = o.referenciaindice.quote
                    arr.append((o.referenciaindice.quote, o))
        arr = sorted(arr, key=lambda row: row[1].datetime, reverse=False)

        #Makes and array from  minimum to benchmark maximum + 2% to minimum
        ranges = []
        if maxoper == 0:  ##NO hay operinvestments
            maximo = self.cmbBenchmarkCurrent_price() * (
                1 + 2 * Decimal(self.spin.value() / 100))
        else:
            maximo = maxoper * (1 + 2 * Decimal(self.spin.value() / 100)
                                )  ##1.04 en caso de 2
        minimo = self.txtMinimo.decimal()
        PuntRange = minimo
        while PuntRange < maximo:
            ranges.insert(0, PuntRange)
            PuntRange = PuntRange * (1 + Decimal(self.spin.value() / 100))

        #Calculate zero risk assests and range number covered
        zeroriskplusbonds = Assets(self.mem).patrimonio_riesgo_cero(
            datetime.date.today()
        )  # +Assets(self.mem).saldo_todas_inversiones_bonds(datetime.date.today()).amount
        rangescovered = int(zeroriskplusbonds.amount /
                            self.txtInvertir.decimal())

        self.mqtw.table.setColumnCount(2)
        for i, s in enumerate([self.tr("Range"), self.tr("Investments")]):
            self.mqtw.table.setHorizontalHeaderItem(i, QTableWidgetItem(s))
        #Iterates all ranges and prints mqtw
        self.mqtw.applySettings()
        self.mqtw.table.clearContents()
        self.mqtw.table.setRowCount(len(ranges))
        colorized = 0
        for i, r in enumerate(ranges):  ###De mayor a menor
            top = r * (1 + Decimal(self.spin.value() / 100))
            bottom = r
            self.mqtw.table.setItem(
                i, 0, qcenter("{}-{}".format(int(bottom), int(top))))
            self.mqtw.table.setItem(
                i, 1, QTableWidgetItem(investments(arr, bottom, top)))
            if bottom < self.cmbBenchmarkCurrent_price():
                if self.cmbBenchmarkCurrent_price(
                ) <= top:  ##Colorize current price
                    self.mqtw.table.item(i, 0).setBackground(eQColor.Red)
                if colorized <= rangescovered:
                    self.mqtw.table.item(i, 1).setBackground(eQColor.Green)
                    colorized = colorized + 1

        #Prints label
        self.lblTotal.setText(
            self.
            tr("{} green colorized ranges of {} benchmark are covered by zero risk and bonds balance ({})."
               ).format(colorized, self.benchmark.name, zeroriskplusbonds))
        print("wdgIndexRange > load_data: {0}".format(datetime.datetime.now() -
                                                      inicio))
Exemplo n.º 22
0
 def total_zerorisk(self):
     if hasattr(self, "_total_zerorisk") is False:
         self._total_zerorisk = Assets(self.mem).patrimonio_riesgo_cero(
             self.last_day())
     return self._total_zerorisk
Exemplo n.º 23
0
 def total_accounts(self):
     if hasattr(self, "_total_accounts") is False:
         self._total_accounts = Assets(self.mem).saldo_todas_accounts(
             self.last_day())
     return self._total_accounts
Exemplo n.º 24
0
    def load_report(self):
        inicio=datetime.now()
        sumgd=Money(self.mem, 0, self.mem.localcurrency)
        self.mqtwReport.applySettings()
        self.mqtwReport.table.setRowCount(date.today().year-self.wdgYear.year+1+1)
        hh=[self.tr("Year"), self.tr("Invested balance"), self.tr("Investment valoration"), self.tr("Difference"), 
            self.tr("%"), "", self.tr("Net gains + Dividends"), self.tr("Custody commissions"),  
            self.tr("Taxes"), "", self.tr("Investments Commissions")]
        data=[]
        for i in range(self.wdgYear.year, date.today().year+1):
            if self.progress.wasCanceled():
                break;
            else:
                self.progress.setValue(self.progress.value()+1)          
            dt_start=dtaware_year_start(i, self.mem.localzone_name)
            dt_end=dtaware_year_end(i, self.mem.localzone_name)           
            sinvested=Assets(self.mem).invested(date_last_of_the_year(i))
            sbalance=Assets(self.mem).saldo_todas_inversiones(date_last_of_the_year(i))+Assets(self.mem).saldo_todas_inversiones_with_daily_adjustment(date_last_of_the_year(i))
            gd=Assets(self.mem).consolidado_neto(self.mem.data.investments,  i)+Assets(self.mem).dividends_neto(i)
            sumgd=sumgd+gd
            
            data.append([
                i, 
                sinvested, 
                sbalance, 
                sbalance-sinvested, 
                percentage_between(sinvested, sbalance), 
                "#crossedout", 
                gd, 
                Assets(self.mem).custody_commissions(dt_start, dt_end),
                Assets(self.mem).taxes(dt_start, dt_end), 
                "#crossedout", 
                Assets(self.mem).investments_commissions(dt_start, dt_end)
            ])
            
        report_custody_commissions=Assets(self.mem).custody_commissions(self.dt_report_start, self.dt_report_end)
        report_taxes=Assets(self.mem).taxes(self.dt_report_start, self.dt_report_end)
        data.append([
            self.tr("Total"), 
            "#crossedout", 
            "#crossedout", 
            "#crossedout", 
            "#crossedout", 
            "#crossedout", 
            sumgd, 
            report_custody_commissions,
            report_taxes, 
            "#crossedout", 
            Assets(self.mem).investments_commissions(self.dt_report_start, self.dt_report_end)
            ])
        self.mqtwReport.setData(hh, None, data)

        diff=Assets(self.mem).saldo_todas_inversiones(date_last_of_the_year(date.today().year)) + Assets(self.mem).saldo_todas_inversiones_with_daily_adjustment(date_last_of_the_year(date.today().year)) - Assets(self.mem).invested(date_last_of_the_year(date.today().year))
        s=""
        s=s+"\n"+self.tr("Difference between invested amount and current invesment balance is {}.").format(diff)
        s=s+"\n"+self.tr("From {} I've generated {} gains (investment commisions are included).").format(self.wdgYear.year, sumgd)
        s=s+"\n"+self.tr("Sum of taxes and custody commissions is {}.".format(report_taxes+report_custody_commissions))
        s=s+"\n"+self.tr("So, I've generated {} gains.").format(sumgd+report_taxes+report_custody_commissions)
        balance=diff+sumgd+report_taxes+report_custody_commissions
        if balance.isGETZero():
            s=s+"\n"+self.tr("So I'm wining {} which is {} per year.").format(balance, self.mem.localmoney(balance.amount/(date.today().year-self.wdgYear.year+1)))
        else:
            s=s+"\n"+self.tr("So I'm losing {} which is {} per year.").format(balance, self.mem.localmoney(balance.amount/(date.today().year-self.wdgYear.year+1)))        

        self.lblReport.setText(s)

        debug("wdgAPR > load_report: {0}".format(datetime.now()-inicio))
Exemplo n.º 25
0
 def total_investments_real(self):
     if hasattr(self, "_total_investments_real") is False:
         self._total_investments_real = Assets(
             self.mem).saldo_todas_inversiones_real(self.last_day())
     return self._total_investments_real
Exemplo n.º 26
0
    def __init__(self, mem, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.mem = mem

        self.mem.data.benchmark.needStatus(2)

        c = wdgCuriosity(self.mem)
        c.setTitle(self.tr("Since when there is data in the database?"))
        c.setText("The first data is from {}".format(
            Assets(self.mem).first_database_datetime()))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        c.setTitle(
            self.
            tr("Which is the investment I gain more money in the last three years?"
               ))
        selected = None
        maxgains = Money(self.mem, 0, self.mem.localcurrency)
        for inv in self.mem.data.investments.arr:
            consolidado = inv.op_historica.consolidado_bruto(type=3)
            if maxgains < consolidado:
                maxgains = consolidado
                selected = inv
        if selected == None:
            c.setText(self.tr("You still hasn't gains"))
        else:
            c.setText(
                self.
                tr("The investment I gain more money is {} in {} ({}). I got {}."
                   .format(selected.name, selected.account.name,
                           selected.account.bank.name, maxgains)))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        c.setTitle(
            self.
            tr("Which is the product I gain more money in the last three years?"
               ))
        c.setText(self.tr(""))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        c.setTitle(self.tr("Which is the benchmark highest and lowest price?"))
        if self.mem.data.benchmark.result.ohclDaily.length() == 0:
            c.setText(self.tr("Current benchmarck hasn't data."))
        else:
            highest = self.mem.data.benchmark.result.ohclDaily.highest()
            lowest = self.mem.data.benchmark.result.ohclDaily.lowest()
            c.setText(
                self.
                tr("Current benchmarck ({}) highest price is {}. It took place at {}. Lowest price is {} and took place at {}."
                   .format(self.mem.data.benchmark.name,
                           self.mem.data.benchmark.money(highest.high),
                           highest.date,
                           self.mem.data.benchmark.money(lowest.low),
                           lowest.date)))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        c.setTitle(self.tr("How many quotes are there in the database?"))
        c.setText(
            self.tr("There are {} quotes in this Xulpymoney database.".format(
                self.mem.con.cursor_one_field("select count(*) from quotes"))))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        c.setTitle(self.tr("Which product has the highest quote?"))
        c.setText(self.tr(""))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        operations = AccountOperationManagerHeterogeneus(self.mem)
        operations.load_from_db(
            "select * from accountsoperations where amount = (select max(amount) from accountsoperations) order by datetime desc limit 1"
        )
        c.setTitle(
            self.tr("Which is the amount of the largest account operation?"))
        if operations.length() == 1:
            o = operations.first()
            c.setText(
                self.
                tr("The largest account operation took place at {}. It's concept was '{}' and it's amount was {}."
                   .format(o.datetime, o.concept.name,
                           o.account.money(o.amount))))
        else:
            c.setText(self.tr("There are not account operations yet."))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        c.setTitle(
            self.tr(
                "Which is the amount of the largest credit card operation?"))
        c.setText(self.tr(""))
        self.layout.addWidget(c)

        c = wdgCuriosity(self.mem)
        c.setTitle(
            self.tr(
                "Which is the amount of the largest investment operation?"))
        c.setText(self.tr(""))
        self.layout.addWidget(c)
        self.layout.addSpacerItem(
            QSpacerItem(10, 10, QSizePolicy.Expanding, QSizePolicy.Expanding))