joining table allocation to actifs
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
INSERT INTO "allocation" VALUES(5,'Obligations',20,28.899999999999998578,74481.0);
|
INSERT INTO "allocation" (no_cat, classe, pc_cible, pc_atteint, valeur, type, ordre, bg_color, pc_ecart) VALUES(5,'Obligations',22,28.30000000000000071,74481.0,'AUTRE',40,'success',6.3000000000000007105);
|
||||||
INSERT INTO "allocation" VALUES(10,'Actions World',60,54.0,139404.14999999999418);
|
INSERT INTO "allocation" (no_cat, classe, pc_cible, pc_atteint, valeur, type, ordre, bg_color, pc_ecart) VALUES(10,'Actions World',60,54.200000000000002841,142781.26000000000931,'ACTION',30,'warning',-5.7999999999999971578);
|
||||||
INSERT INTO "allocation" VALUES(12,'Cash',2,2.2000000000000001776,5591.0000000000000001);
|
INSERT INTO "allocation" (no_cat, classe, pc_cible, pc_atteint, valeur, type, ordre, bg_color, pc_ecart) VALUES(12,'Cash',2,2.1000000000000000888,5591.0000000000000001,'AUTRE',60,'success',0.10000000000000008881);
|
||||||
INSERT INTO "allocation" VALUES(16,'Actions REITS',2,6.0999999999999996447,15607.200000000000727);
|
INSERT INTO "allocation" (no_cat, classe, pc_cible, pc_atteint, valeur, type, ordre, bg_color, pc_ecart) VALUES(16,'Actions REITS',5,6.2999999999999998223,16690.799999999999273,'ACTION',12,'danger',1.2999999999999998223);
|
||||||
INSERT INTO "allocation" VALUES(17,'Actions Moment',15,8.1999999999999992894,21223.43999999999869);
|
INSERT INTO "allocation" (no_cat, classe, pc_cible, pc_atteint, valeur, type, ordre, bg_color, pc_ecart) VALUES(17,'Actions Moment',10,8.5,22332.240000000001601,'ACTION',5,'danger',-1.5);
|
||||||
INSERT INTO "allocation" VALUES(19,'Crypto',1,0.59999999999999997779,1623.349999999999909);
|
INSERT INTO "allocation" (no_cat, classe, pc_cible, pc_atteint, valeur, type, ordre, bg_color, pc_ecart) VALUES(19,'Crypto',1,0.59999999999999997779,1700.6400000000001,'ACTION',31,'warning',-0.4000000000000000222);
|
||||||
|
|
||||||
|
|||||||
BIN
cao_blogr.sqlite
BIN
cao_blogr.sqlite
Binary file not shown.
@@ -1,81 +0,0 @@
|
|||||||
"""add portfolio tables
|
|
||||||
|
|
||||||
Revision ID: 19d939dbc6d0
|
|
||||||
Revises: 7995372bd306
|
|
||||||
Create Date: 2023-01-23 14:49:31.713228
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '19d939dbc6d0'
|
|
||||||
down_revision = '7995372bd306'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_table('actifs',
|
|
||||||
sa.Column('no_id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('symbole', sa.Unicode(length=45), nullable=False),
|
|
||||||
sa.Column('libelle', sa.Unicode(length=45), nullable=False),
|
|
||||||
sa.Column('classe', sa.Unicode(length=45), nullable=False),
|
|
||||||
sa.Column('nombre', sa.Integer(), nullable=True),
|
|
||||||
sa.Column('cours', sa.Float(), nullable=True),
|
|
||||||
sa.Column('pru', sa.Float(), nullable=True),
|
|
||||||
sa.Column('valeur', sa.Float(), nullable=True),
|
|
||||||
sa.Column('plus_value', sa.Float(), nullable=True),
|
|
||||||
sa.Column('pc_plusvalue', sa.Float(), nullable=True),
|
|
||||||
sa.Column('rendement', sa.Float(), nullable=True),
|
|
||||||
sa.Column('pc_rdt', sa.Float(), nullable=True),
|
|
||||||
sa.Column('pc_allocation', sa.Float(), nullable=True),
|
|
||||||
sa.Column('ter', sa.Float(), nullable=True),
|
|
||||||
sa.Column('ter_pondere', sa.Float(), nullable=True),
|
|
||||||
sa.Column('devise', sa.Unicode(length=45), nullable=True),
|
|
||||||
sa.Column('parite', sa.Float(), nullable=True),
|
|
||||||
sa.Column('website', sa.Unicode(length=100), nullable=True),
|
|
||||||
sa.Column('modif_le', sa.DateTime(), nullable=True),
|
|
||||||
sa.PrimaryKeyConstraint('no_id', name=op.f('pk_actifs')),
|
|
||||||
sa.UniqueConstraint('symbole', name=op.f('uq_actifs_symbole'))
|
|
||||||
)
|
|
||||||
op.create_index('symbole_index', 'actifs', ['symbole'], unique=False)
|
|
||||||
op.create_table('allocation',
|
|
||||||
sa.Column('no_cat', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('classe', sa.Unicode(length=45), nullable=False),
|
|
||||||
sa.Column('pc_cible', sa.Integer(), nullable=True),
|
|
||||||
sa.Column('pc_atteint', sa.Float(), nullable=True),
|
|
||||||
sa.Column('valeur', sa.Float(), nullable=True),
|
|
||||||
sa.PrimaryKeyConstraint('no_cat', name=op.f('pk_allocation'))
|
|
||||||
)
|
|
||||||
op.create_table('classes',
|
|
||||||
sa.Column('classe', sa.Unicode(), nullable=False),
|
|
||||||
sa.Column('type', sa.Unicode(length=45), nullable=True),
|
|
||||||
sa.Column('ordre', sa.Integer(), nullable=True),
|
|
||||||
sa.Column('bg_color', sa.Unicode(length=45), nullable=True),
|
|
||||||
sa.PrimaryKeyConstraint('classe', name=op.f('pk_classes'))
|
|
||||||
)
|
|
||||||
op.create_index('ordre_index', 'classes', ['ordre'], unique=False)
|
|
||||||
op.create_table('histo',
|
|
||||||
sa.Column('no_id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('date', sa.DateTime(), nullable=True),
|
|
||||||
sa.Column('mvt_cash', sa.Float(), nullable=True),
|
|
||||||
sa.Column('valeur_pf', sa.Float(), nullable=True),
|
|
||||||
sa.Column('nb_part', sa.Float(), nullable=True),
|
|
||||||
sa.Column('val_part', sa.Float(), nullable=True),
|
|
||||||
sa.Column('cours_ref', sa.Float(), nullable=True),
|
|
||||||
sa.Column('val_part_ref', sa.Float(), nullable=True),
|
|
||||||
sa.PrimaryKeyConstraint('no_id', name=op.f('pk_histo'))
|
|
||||||
)
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_table('histo')
|
|
||||||
op.drop_index('ordre_index', table_name='classes')
|
|
||||||
op.drop_table('classes')
|
|
||||||
op.drop_table('allocation')
|
|
||||||
op.drop_index('symbole_index', table_name='actifs')
|
|
||||||
op.drop_table('actifs')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
"""add portfolio tables
|
|
||||||
|
|
||||||
Revision ID: 7995372bd306
|
|
||||||
Revises: fe8f8a5bfdb5
|
|
||||||
Create Date: 2023-01-23 14:43:22.632056
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '7995372bd306'
|
|
||||||
down_revision = 'fe8f8a5bfdb5'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
"""add portfolio tables
|
|
||||||
|
|
||||||
Revision ID: fe8f8a5bfdb5
|
|
||||||
Revises:
|
|
||||||
Create Date: 2023-01-23 14:42:10.171291
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'fe8f8a5bfdb5'
|
|
||||||
down_revision = None
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
"""added relationship allocation-classe
|
|
||||||
|
|
||||||
Revision ID: 42a297861f20
|
|
||||||
Revises: 19d939dbc6d0
|
|
||||||
Create Date: 2023-01-26 14:23:42.771763
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '42a297861f20'
|
|
||||||
down_revision = '19d939dbc6d0'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('allocation', sa.Column('classe_id', sa.Unicode(length=45), nullable=True))
|
|
||||||
op.create_foreign_key(op.f('fk_allocation_classe_id_classes'), 'allocation', 'classes', ['classe_id'], ['classe'])
|
|
||||||
op.drop_column('allocation', 'classe')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('allocation', sa.Column('classe', sa.VARCHAR(length=45), nullable=False))
|
|
||||||
op.drop_constraint(op.f('fk_allocation_classe_id_classes'), 'allocation', type_='foreignkey')
|
|
||||||
op.drop_column('allocation', 'classe_id')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
"""added relationship allocation-classe
|
|
||||||
|
|
||||||
Revision ID: bbfb79cb9dad
|
|
||||||
Revises: 42a297861f20
|
|
||||||
Create Date: 2023-01-26 14:41:29.955558
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'bbfb79cb9dad'
|
|
||||||
down_revision = '42a297861f20'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_table('allocation',
|
|
||||||
sa.Column('no_cat', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('classe_id', sa.Unicode(length=45), nullable=True),
|
|
||||||
sa.Column('pc_cible', sa.Integer(), nullable=True),
|
|
||||||
sa.Column('pc_atteint', sa.Float(), nullable=True),
|
|
||||||
sa.Column('valeur', sa.Float(), nullable=True),
|
|
||||||
sa.ForeignKeyConstraint(['classe_id'], ['classes.classe'], name=op.f('fk_allocation_classe_id_classes')),
|
|
||||||
sa.PrimaryKeyConstraint('no_cat', name=op.f('pk_allocation'))
|
|
||||||
)
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_table('allocation')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
42
cao_blogr/alembic/versions/20230129_b8f8216d72c7.py
Normal file
42
cao_blogr/alembic/versions/20230129_b8f8216d72c7.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
"""added foreign key to allocation
|
||||||
|
|
||||||
|
Revision ID: b8f8216d72c7
|
||||||
|
Revises:
|
||||||
|
Create Date: 2023-01-29 12:20:48.097107
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'b8f8216d72c7'
|
||||||
|
down_revision = None
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('allocation',
|
||||||
|
sa.Column('no_cat', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('classe', sa.Unicode(length=45), nullable=True),
|
||||||
|
sa.Column('pc_cible', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('pc_atteint', sa.Float(), nullable=True),
|
||||||
|
sa.Column('pc_ecart', sa.Float(), nullable=True),
|
||||||
|
sa.Column('valeur', sa.Float(), nullable=True),
|
||||||
|
sa.Column('type', sa.Unicode(length=45), nullable=True),
|
||||||
|
sa.Column('ordre', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('bg_color', sa.Unicode(length=45), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['classe'], ['actifs.classe'], name=op.f('fk_allocation_classe_actifs')),
|
||||||
|
sa.PrimaryKeyConstraint('no_cat', name=op.f('pk_allocation'))
|
||||||
|
)
|
||||||
|
op.create_index('classe_index', 'allocation', ['classe'], unique=False)
|
||||||
|
op.create_index('ordre_index', 'allocation', ['ordre'], unique=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index('ordre_index', table_name='allocation')
|
||||||
|
op.drop_index('classe_index', table_name='allocation')
|
||||||
|
op.drop_table('allocation')
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -22,13 +22,11 @@ class BlogSearchForm(Form):
|
|||||||
|
|
||||||
class TagForm(Form):
|
class TagForm(Form):
|
||||||
id = IntegerField(widget=HiddenInput())
|
id = IntegerField(widget=HiddenInput())
|
||||||
tag = StringField('Tag', validators=[InputRequired(), Length(min=1, max=25)],
|
tag = StringField('Tag', validators=[InputRequired(), Length(min=1, max=25)], filters=[strip_filter])
|
||||||
filters=[strip_filter])
|
|
||||||
|
|
||||||
|
|
||||||
class UserCreateForm(Form):
|
class UserCreateForm(Form):
|
||||||
username = StringField('Nom', validators=[InputRequired(), Length(min=1, max=255)],
|
username = StringField('Nom', validators=[InputRequired(), Length(min=1, max=255)], filters=[strip_filter])
|
||||||
filters=[strip_filter])
|
|
||||||
password = PasswordField('Mot de passe', validators=[InputRequired(), Length(min=6)])
|
password = PasswordField('Mot de passe', validators=[InputRequired(), Length(min=6)])
|
||||||
|
|
||||||
class HistoForm(Form):
|
class HistoForm(Form):
|
||||||
@@ -37,5 +35,9 @@ class HistoForm(Form):
|
|||||||
|
|
||||||
class AllocationForm(Form):
|
class AllocationForm(Form):
|
||||||
no_cat = IntegerField(widget=HiddenInput())
|
no_cat = IntegerField(widget=HiddenInput())
|
||||||
classe = SelectField('Classe')
|
classe = StringField('Classe', validators=[InputRequired(), Length(min=1, max=25)], filters=[strip_filter])
|
||||||
pc_cible = IntegerField(validators=[InputRequired()])
|
pc_cible = IntegerField(validators=[InputRequired()])
|
||||||
|
type = SelectField('Type', choices=[('ACTION','ACTION'),('AUTRE','AUTRE')])
|
||||||
|
ordre = IntegerField(validators=[InputRequired()])
|
||||||
|
bg_color = SelectField('Couleur de fond', choices=[('info','BLEU'),('danger','ROUGE'),('warning','ORANGE'),('success','VERT')])
|
||||||
|
|
||||||
|
|||||||
@@ -36,24 +36,20 @@ class Actifs(Base):
|
|||||||
modif_le = Column(DateTime, default=datetime.datetime.utcnow)
|
modif_le = Column(DateTime, default=datetime.datetime.utcnow)
|
||||||
__table_args__ = (Index('symbole_index', 'symbole'),)
|
__table_args__ = (Index('symbole_index', 'symbole'),)
|
||||||
|
|
||||||
|
|
||||||
class Allocation(Base):
|
class Allocation(Base):
|
||||||
__tablename__ = 'allocation'
|
__tablename__ = 'allocation'
|
||||||
no_cat = Column(Integer, primary_key=True)
|
no_cat = Column(Integer, primary_key=True)
|
||||||
classe_id = Column(Unicode(45), ForeignKey('classes.classe'))
|
classe = Column(Unicode(45), ForeignKey('actifs.classe'))
|
||||||
pc_cible = Column(Integer)
|
pc_cible = Column(Integer)
|
||||||
pc_atteint = Column(Float)
|
pc_atteint = Column(Float)
|
||||||
|
pc_ecart = Column(Float)
|
||||||
valeur = Column(Float)
|
valeur = Column(Float)
|
||||||
|
|
||||||
# relationship
|
|
||||||
classe = relationship('Classes', backref="allocation")
|
|
||||||
|
|
||||||
class Classes(Base):
|
|
||||||
__tablename__ = 'classes'
|
|
||||||
classe = Column(Unicode(45), primary_key=True)
|
|
||||||
type = Column(Unicode(45), default='ACTION')
|
type = Column(Unicode(45), default='ACTION')
|
||||||
ordre = Column(Integer)
|
ordre = Column(Integer)
|
||||||
bg_color = Column(Unicode(45))
|
bg_color = Column(Unicode(45))
|
||||||
__table_args__ = (Index('ordre_index', 'ordre'),)
|
__table_args__ = (Index('classe_index', 'classe'), Index('ordre_index', 'ordre'),)
|
||||||
|
|
||||||
|
|
||||||
class Histo(Base):
|
class Histo(Base):
|
||||||
__tablename__ = 'histo'
|
__tablename__ = 'histo'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
from ..models.portfolio import Actifs, Allocation, Classes, Histo
|
from ..models.portfolio import Actifs, Allocation, Histo
|
||||||
|
|
||||||
class PFService(object):
|
class PFService(object):
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ class PFService(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_actifs(cls, request, no_id):
|
def get_actifs(cls, request, no_id):
|
||||||
if no_id == '0':
|
if no_id == '0':
|
||||||
items = request.dbsession.query(Actifs).order_by(Actifs.classe, Actifs.libelle).all()
|
items = request.dbsession.query(Actifs, Allocation).join(Allocation).order_by(Allocation.ordre, Actifs.libelle).all()
|
||||||
else:
|
else:
|
||||||
# lire une allocation par le no_id
|
# lire une allocation par le no_id
|
||||||
items = request.dbsession.query(Actifs).filter(Actifs.no_id == no_id).first()
|
items = request.dbsession.query(Actifs).filter(Actifs.no_id == no_id).first()
|
||||||
@@ -17,22 +17,13 @@ class PFService(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_allocation(cls, request, no_cat):
|
def get_allocation(cls, request, no_cat):
|
||||||
if no_cat == '0':
|
if no_cat == '0':
|
||||||
query = request.dbsession.query(Allocation).join(Classes).filter(Classes.classe == Allocation.classe_id)
|
query = request.dbsession.query(Allocation)
|
||||||
query = query.order_by(sa.asc(Allocation.classe_id)).all()
|
query = query.order_by(sa.asc(Allocation.ordre)).all()
|
||||||
else:
|
else:
|
||||||
# lire une allocation par le no_id
|
# lire une allocation par le no_id
|
||||||
query = request.dbsession.query(Allocation).filter(Allocation.no_cat == no_cat).first()
|
query = request.dbsession.query(Allocation).filter(Allocation.no_cat == no_cat).first()
|
||||||
return query
|
return query
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_classes(cls, request, classe):
|
|
||||||
if classe == '0':
|
|
||||||
items = request.dbsession.query(Classes).order_by(sa.asc(Classes.ordre)).all()
|
|
||||||
else:
|
|
||||||
# lire une allocation par le no_id
|
|
||||||
items = request.dbsession.query(Classes).filter(Classes.classe == classe).first()
|
|
||||||
return items
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_histo(cls, request, no_id):
|
def get_histo(cls, request, no_id):
|
||||||
if no_id == '0':
|
if no_id == '0':
|
||||||
|
|||||||
@@ -17,6 +17,15 @@
|
|||||||
{{form.pc_cible(class_='form-control')}}
|
{{form.pc_cible(class_='form-control')}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="required-field" for="tag">{{form.type.label}}</label>
|
||||||
|
{{form.type(class_='form-control')}}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="required-field" for="tag">{{form.bg_color.label}}</label>
|
||||||
|
{{form.bg_color(class_='form-control')}}
|
||||||
|
</div>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<a class="btn btn-default" href="{{ request.route_url('portfolio') }}">
|
<a class="btn btn-default" href="{{ request.route_url('portfolio') }}">
|
||||||
|
|||||||
@@ -21,15 +21,15 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="{{ item.bg_color }}">{{ item.classe }}</td>
|
<td class="{{ item.bg_color }}"><a href="allocation_edit/{{ item.no_cat }}">{{ item.classe }}</a></td>
|
||||||
<td class="text-right"><a href="allocation_edit/{{ item.no_cat }}">{{ item.pc_cible }} %</a></td>
|
<td class="text-right">{{ item.pc_cible }} %</td>
|
||||||
<td class="text-right">{{ item.pc_atteint }}</td>
|
<td class="text-right">{{ item.pc_atteint }}</td>
|
||||||
{% if (item.pc_atteint - item.pc_cible) >= 0 %}
|
{% if (item.pc_atteint - item.pc_cible) >= 0 %}
|
||||||
<td class="text-right" style="color: green;">{{ item.pc_atteint }}</td>
|
<td class="text-right" style="color: green;">{{ '{0:0.1f}'.format(item.pc_ecart) }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="text-right" style="color: red;">{{ item.pc_atteint }}</td>
|
<td class="text-right" style="color: red;">{{ '{0:0.1f}'.format(item.pc_ecart) }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="text-right">{{ '{0:0.2f} €'.format(item.valeur) }}</td>
|
<td class="text-right">{{ '{0:0,.0f} €'.format(item.valeur).replace(',',' ') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<table id="actifs_list" class="table table-condensed table-bordered">
|
<table class="table table-condensed table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Classe</th>
|
<th>Classe</th>
|
||||||
@@ -118,40 +118,40 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for ligne in actifs %}
|
{% for ligne in actifs %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="{{ ligne.bg_color }}">{{ ligne.classe }}</td>
|
<td class="{{ ligne.Allocation.bg_color }}">{{ ligne.Allocation.classe }}</td>
|
||||||
{% if ligne.type=='ACTION' %}
|
{% if ligne.Allocation.type=='ACTION' %}
|
||||||
<td><a href="actif_edit/{{ ligne.no_id }}">{{ ligne.libelle }}</a></td>
|
<td><a href="actif_edit/{{ ligne.no_id }}">{{ ligne.Actifs.libelle }}</a></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><a href="actif2_edit/{{ ligne.no_id }}">{{ ligne.libelle }}</a></td>
|
<td><a href="actif2_edit/{{ ligne.no_id }}">{{ ligne.Actifs.libelle }}</a></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if ligne.devise=='EUR' %}
|
{% if ligne.Actifs.devise=='EUR' %}
|
||||||
<td>{{ '{0:0.2f} €'.format(ligne.cours) }}</td>
|
<td class="text-right">{{ '{0:0.2f} €'.format(ligne.Actifs.cours) }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td>{{ '{0:0.2f} $'.format(ligne.cours) }}</td>
|
<td class="text-right">{{ '{0:0.2f} $'.format(ligne.Actifs.cours) }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="text-right">{{ ligne.nombre }}</td>
|
<td class="text-right">{{ ligne.Actifs.nombre }}</td>
|
||||||
<td class="text-right">{{ '{0:0.2f} €'.format(ligne.valeur) }}</td>
|
<td class="text-right">{{ '{0:0,.2f} €'.format(ligne.Actifs.valeur).replace(',',' ') }}</td>
|
||||||
{% if ligne.plus_value >= 0 %}
|
{% if ligne.Actifs.plus_value >= 0 %}
|
||||||
<td class="text-right" style="color: green;">{{ '{0:0.2f} €'.format(ligne.plus_value) }}</td>
|
<td class="text-right" style="color: green;">{{ '{0:0.2f} €'.format(ligne.Actifs.plus_value) }}</td>
|
||||||
<td class="text-right" style="color: green;">{{ '{0:0.1f}'.format(ligne.pc_plusvalue) }}</td>
|
<td class="text-right" style="color: green;">{{ '{0:0.1f}'.format(ligne.Actifs.pc_plusvalue) }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="text-right" style="color: red;">{{ '{0:0.2f} €'.format(ligne.plus_value) }}</td>
|
<td class="text-right" style="color: red;">{{ '{0:0.2f} €'.format(ligne.Actifs.plus_value) }}</td>
|
||||||
<td class="text-right" style="color: red;">{{ '{0:0.1f}'.format(ligne.pc_plusvalue) }}</td>
|
<td class="text-right" style="color: red;">{{ '{0:0.1f}'.format(ligne.Actifs.pc_plusvalue) }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="text-right">{{ '{0:0.1f}'.format(ligne.ter) }}</td>
|
<td class="text-right">{{ '{0:0.1f}'.format(ligne.Actifs.ter) }}</td>
|
||||||
<td class="text-right">{{ '{0:0.1f}'.format(ligne.pc_allocation) }}</td>
|
<td class="text-right">{{ '{0:0.1f}'.format(ligne.Actifs.pc_allocation) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-right" colspan="4"><b>Total</b></td>
|
<td class="text-right" colspan="4"><b>Total</b></td>
|
||||||
<td>{{ '{0:0.2f} €'.format(total_valeur) }}</td>
|
<td>{{ '{0:0,.2f} €'.format(total_valeur).replace(',',' ') }}</td>
|
||||||
{% if total_pv >= 0 %}
|
{% if total_pv >= 0 %}
|
||||||
<td class="text-right" style="color: green;">{{ '{0:0.1f}'.format(total_pv) }}</td>
|
<td class="text-right" style="color: green;">{{ '{0:0.2f} €'.format(total_pv) }}</td>
|
||||||
<td class="text-right" style="color: green;">{{ '{0:0.2f} €'.format(total_pc_value) }}</td>
|
<td class="text-right" style="color: green;">{{ '{0:0.1f}'.format(total_pc_value) }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="text-right" style="color: red;">{{ '{0:0.1f}'.format(total_pv) }}</td>
|
<td class="text-right" style="color: red;">{{ '{0:0.2f} €'.format(total_pv) }}</td>
|
||||||
<td class="text-right" style="color: red;">{{ '{0:0.2f} €'.format(total_pc_value) }}</td>
|
<td class="text-right" style="color: red;">{{ '{0:0.1f}'.format(total_pc_value) }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td></td>
|
<td></td>
|
||||||
<td class="text-right"><b>100.0</b></td>
|
<td class="text-right"><b>100.0</b></td>
|
||||||
@@ -172,7 +172,7 @@
|
|||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="glyphicon glyphicon-remove"></span></button>
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="glyphicon glyphicon-remove"></span></button>
|
||||||
<h4 class="modal-title" id="choixTypeActif">Choix du type d'actif à créer</h4>
|
<h4 class="modal-title" id="choixTypeActif">Choix du type</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ def portfolio(request):
|
|||||||
|
|
||||||
# lire les categories
|
# lire les categories
|
||||||
items = PFService.get_allocation(request, '0')
|
items = PFService.get_allocation(request, '0')
|
||||||
import pdb;pdb.set_trace()
|
|
||||||
# construire la liste pour donut
|
# construire la liste pour donut
|
||||||
donut_cible=[]
|
donut_cible=[]
|
||||||
donut_cible.append(('Allocation cible', 'Pourcent'))
|
donut_cible.append(('Allocation cible', 'Pourcent'))
|
||||||
@@ -52,9 +51,9 @@ def portfolio(request):
|
|||||||
PFService.update_actif_devise(request, 'USD', ticker.info.get('regularMarketPrice'))
|
PFService.update_actif_devise(request, 'USD', ticker.info.get('regularMarketPrice'))
|
||||||
|
|
||||||
for item in actifs:
|
for item in actifs:
|
||||||
if item.type == 'ACTION':
|
if item.Allocation.type == 'ACTION':
|
||||||
# lire le cours de l'action
|
# lire le cours de l'action
|
||||||
ticker = yf.Ticker(item.symbole)
|
ticker = yf.Ticker(item.Actifs.symbole)
|
||||||
# ticker delisted ?
|
# ticker delisted ?
|
||||||
if ticker.info == None:
|
if ticker.info == None:
|
||||||
price = 0
|
price = 0
|
||||||
@@ -62,7 +61,7 @@ def portfolio(request):
|
|||||||
price = ticker.info.get('regularMarketPrice')
|
price = ticker.info.get('regularMarketPrice')
|
||||||
# caluler son rendement
|
# caluler son rendement
|
||||||
dividends = PFService.get_dividends(ticker)
|
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
|
# time.sleep(1) # attendre 2 secondes
|
||||||
|
|
||||||
# update du portefeuille
|
# update du portefeuille
|
||||||
@@ -74,14 +73,15 @@ def portfolio(request):
|
|||||||
total_valeur = 0
|
total_valeur = 0
|
||||||
total_pv = 0
|
total_pv = 0
|
||||||
total_rdt = 0
|
total_rdt = 0
|
||||||
|
|
||||||
for item in actifs:
|
for item in actifs:
|
||||||
total_valeur += item.valeur
|
total_valeur += item.Actifs.valeur
|
||||||
total_pv += item.plus_value
|
total_pv += item.Actifs.plus_value
|
||||||
if total_valeur == 0:
|
if total_valeur == 0:
|
||||||
total_pc_value = 0
|
total_pc_value = 0
|
||||||
else:
|
else:
|
||||||
total_pc_value = total_pv / total_valeur * 100
|
total_pc_value = total_pv / total_valeur * 100
|
||||||
total_rdt += item.rendement
|
total_rdt += item.Actifs.rendement
|
||||||
|
|
||||||
# lire l'historique
|
# lire l'historique
|
||||||
histos = PFService.get_histo(request,'0')
|
histos = PFService.get_histo(request,'0')
|
||||||
@@ -126,14 +126,10 @@ def allocation_edit(request):
|
|||||||
no_cat = request.matchdict['no_cat']
|
no_cat = request.matchdict['no_cat']
|
||||||
url = request.route_url('allocation_edit', no_cat=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':
|
if no_cat == '0':
|
||||||
# create a new allocation
|
# create a new allocation
|
||||||
entry = Allocation()
|
entry = Allocation()
|
||||||
form = AllocationForm(request.POST, entry)
|
form = AllocationForm(request.POST, entry)
|
||||||
form.classe.choices = [(row.classe, row.classe) for row in classes_list]
|
|
||||||
page_title = "Nouvelle allocation"
|
page_title = "Nouvelle allocation"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -143,10 +139,9 @@ def allocation_edit(request):
|
|||||||
request.session.flash(u"Allocation non trouvée : %s" % no_cat, 'warning')
|
request.session.flash(u"Allocation non trouvée : %s" % no_cat, 'warning')
|
||||||
return HTTPFound(location=request.route_url('portfolio'))
|
return HTTPFound(location=request.route_url('portfolio'))
|
||||||
form = AllocationForm(request.POST, entry)
|
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)
|
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':
|
if no_cat == '0':
|
||||||
form.populate_obj(entry)
|
form.populate_obj(entry)
|
||||||
entry.pc_atteint = 0
|
entry.pc_atteint = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user