joining table allocation to actifs
This commit is contained in:
@@ -17,7 +17,6 @@ def portfolio(request):
|
||||
|
||||
# lire les categories
|
||||
items = PFService.get_allocation(request, '0')
|
||||
import pdb;pdb.set_trace()
|
||||
# construire la liste pour donut
|
||||
donut_cible=[]
|
||||
donut_cible.append(('Allocation cible', 'Pourcent'))
|
||||
@@ -52,9 +51,9 @@ def portfolio(request):
|
||||
PFService.update_actif_devise(request, 'USD', ticker.info.get('regularMarketPrice'))
|
||||
|
||||
for item in actifs:
|
||||
if item.type == 'ACTION':
|
||||
if item.Allocation.type == 'ACTION':
|
||||
# lire le cours de l'action
|
||||
ticker = yf.Ticker(item.symbole)
|
||||
ticker = yf.Ticker(item.Actifs.symbole)
|
||||
# ticker delisted ?
|
||||
if ticker.info == None:
|
||||
price = 0
|
||||
@@ -62,7 +61,7 @@ def portfolio(request):
|
||||
price = ticker.info.get('regularMarketPrice')
|
||||
# caluler son rendement
|
||||
dividends = PFService.get_dividends(ticker)
|
||||
PFService.update_actif_valeur(request, item.symbole, price, dividends)
|
||||
PFService.update_actif_valeur(request, item.Actifs.symbole, price, dividends)
|
||||
# time.sleep(1) # attendre 2 secondes
|
||||
|
||||
# update du portefeuille
|
||||
@@ -74,14 +73,15 @@ def portfolio(request):
|
||||
total_valeur = 0
|
||||
total_pv = 0
|
||||
total_rdt = 0
|
||||
|
||||
for item in actifs:
|
||||
total_valeur += item.valeur
|
||||
total_pv += item.plus_value
|
||||
total_valeur += item.Actifs.valeur
|
||||
total_pv += item.Actifs.plus_value
|
||||
if total_valeur == 0:
|
||||
total_pc_value = 0
|
||||
else:
|
||||
total_pc_value = total_pv / total_valeur * 100
|
||||
total_rdt += item.rendement
|
||||
total_rdt += item.Actifs.rendement
|
||||
|
||||
# lire l'historique
|
||||
histos = PFService.get_histo(request,'0')
|
||||
@@ -126,14 +126,10 @@ def allocation_edit(request):
|
||||
no_cat = request.matchdict['no_cat']
|
||||
url = request.route_url('allocation_edit', no_cat=no_cat)
|
||||
|
||||
# lire les classes
|
||||
classes_list = PFService.get_classes(request, '0')
|
||||
|
||||
if no_cat == '0':
|
||||
# create a new allocation
|
||||
entry = Allocation()
|
||||
form = AllocationForm(request.POST, entry)
|
||||
form.classe.choices = [(row.classe, row.classe) for row in classes_list]
|
||||
page_title = "Nouvelle allocation"
|
||||
|
||||
else:
|
||||
@@ -143,10 +139,9 @@ def allocation_edit(request):
|
||||
request.session.flash(u"Allocation non trouvée : %s" % no_cat, 'warning')
|
||||
return HTTPFound(location=request.route_url('portfolio'))
|
||||
form = AllocationForm(request.POST, entry)
|
||||
form.classe.choices = [(row.classe, row.classe) for row in classes_list]
|
||||
page_title = "Modifier Allocation : " + str(entry.no_cat)
|
||||
|
||||
if 'form.submitted' in request.params and form.validate():
|
||||
if 'form.submitted' in request.params :
|
||||
if no_cat == '0':
|
||||
form.populate_obj(entry)
|
||||
entry.pc_atteint = 0
|
||||
|
||||
Reference in New Issue
Block a user