Merge dev from main #1
@@ -193,7 +193,7 @@ class Dashboard(ModelSQL, ModelView):
|
|||||||
self.chatbot = 'chatbot:' + json.dumps(dial, ensure_ascii=False)
|
self.chatbot = 'chatbot:' + json.dumps(dial, ensure_ascii=False)
|
||||||
logger.info("EXITONCHANGE",self.chatbot)
|
logger.info("EXITONCHANGE",self.chatbot)
|
||||||
|
|
||||||
def get_last_two_fx_rates(self, from_code='USD', to_code='EUR'):
|
def get_last_five_fx_rates(self, from_code='USD', to_code='EUR'):
|
||||||
"""
|
"""
|
||||||
Retourne (dernier_taux, avant_dernier_taux) pour le couple de devises.
|
Retourne (dernier_taux, avant_dernier_taux) pour le couple de devises.
|
||||||
"""
|
"""
|
||||||
@@ -208,28 +208,36 @@ class Dashboard(ModelSQL, ModelView):
|
|||||||
rates = CurrencyRate.search(
|
rates = CurrencyRate.search(
|
||||||
[('currency', '=', to_currency.id)],
|
[('currency', '=', to_currency.id)],
|
||||||
order=[('date', 'DESC')],
|
order=[('date', 'DESC')],
|
||||||
limit=2,
|
limit=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not rates:
|
if not rates:
|
||||||
return None, None
|
return None, None, None, None, None
|
||||||
|
|
||||||
# Calcul du taux EUR/USD
|
# Calcul du taux EUR/USD
|
||||||
# Si la devise principale de la société est EUR, et que le taux stocké est
|
# Si la devise principale de la société est EUR, et que le taux stocké est
|
||||||
# "1 USD = X EUR", on veut l'inverse pour avoir EUR/USD
|
# "1 USD = X EUR", on veut l'inverse pour avoir EUR/USD
|
||||||
last_rate = rates[0].rate
|
f1 = rates[0].rate
|
||||||
prev_rate = rates[1].rate if len(rates) > 1 else None
|
f2 = rates[1].rate if len(rates) > 1 else None
|
||||||
|
f3 = rates[2].rate if len(rates) > 2 else None
|
||||||
|
f4 = rates[3].rate if len(rates) > 3 else None
|
||||||
|
f5 = rates[4].rate if len(rates) > 4 else None
|
||||||
|
d1 = rates[0].date
|
||||||
|
d2 = rates[1].date if len(rates) > 1 else None
|
||||||
|
d3 = rates[2].date if len(rates) > 2 else None
|
||||||
|
d4 = rates[3].date if len(rates) > 3 else None
|
||||||
|
d5 = rates[4].date if len(rates) > 4 else None
|
||||||
|
|
||||||
# if from_currency != to_currency:
|
# if from_currency != to_currency:
|
||||||
# last_rate = 1 / last_rate if last_rate else None
|
# last_rate = 1 / last_rate if last_rate else None
|
||||||
# prev_rate = 1 / prev_rate if prev_rate else None
|
# prev_rate = 1 / prev_rate if prev_rate else None
|
||||||
|
|
||||||
if last_rate and prev_rate:
|
return round(1/f1,6), round(1/f2,6) if f2 else None, round(1/f3,6) if f3 else None, round(1/f4,6) if f4 else None, round(1/f5,6) if f5 else None, d1, d2, d3, d4, d5
|
||||||
return round(1/last_rate,6), round(1/prev_rate,6)
|
|
||||||
|
|
||||||
def get_tremor(self,name):
|
def get_tremor(self,name):
|
||||||
Configuration = Pool().get('gr.configuration')
|
Configuration = Pool().get('gr.configuration')
|
||||||
config = Configuration.search(['id','>',0])[0]
|
config = Configuration.search(['id','>',0])[0]
|
||||||
|
f1,f2,f3,f4,f5,d1,d2,d3,d4,d5 = self.get_last_five_fx_rates()
|
||||||
Pnl = Pool().get('valuation.valuation')
|
Pnl = Pool().get('valuation.valuation')
|
||||||
pnls = Pnl.search(['id','>',0])
|
pnls = Pnl.search(['id','>',0])
|
||||||
pnl_amount = "{:,.0f}".format(round(sum([e.amount for e in pnls]),0))
|
pnl_amount = "{:,.0f}".format(round(sum([e.amount for e in pnls]),0))
|
||||||
@@ -301,6 +309,26 @@ class Dashboard(ModelSQL, ModelView):
|
|||||||
+ str(topay)
|
+ str(topay)
|
||||||
+ "&toreceive="
|
+ "&toreceive="
|
||||||
+ str(toreceive)
|
+ str(toreceive)
|
||||||
|
+ "&eurusd="
|
||||||
|
+ str(f1)
|
||||||
|
+ "&eurusd="
|
||||||
|
+ str(f2)
|
||||||
|
+ "&eurusd="
|
||||||
|
+ str(f3)
|
||||||
|
+ "&eurusd="
|
||||||
|
+ str(f4)
|
||||||
|
+ "&eurusd="
|
||||||
|
+ str(f5)
|
||||||
|
+ "&eurusd_date="
|
||||||
|
+ str(d1)
|
||||||
|
+ "&eurusd_date="
|
||||||
|
+ str(d2)
|
||||||
|
+ "&eurusd_date="
|
||||||
|
+ str(d3)
|
||||||
|
+ "&eurusd_date="
|
||||||
|
+ str(d4)
|
||||||
|
+ "&eurusd_date="
|
||||||
|
+ str(d5)
|
||||||
+ "&draft_p="
|
+ "&draft_p="
|
||||||
+ str(draft_p)
|
+ str(draft_p)
|
||||||
+ "&val_p="
|
+ "&val_p="
|
||||||
@@ -346,7 +374,7 @@ class Dashboard(ModelSQL, ModelView):
|
|||||||
News = Pool().get('news.news')
|
News = Pool().get('news.news')
|
||||||
Date = Pool().get('ir.date')
|
Date = Pool().get('ir.date')
|
||||||
news_list = News.search([('active', '=', True)], limit=5, order=[('publish_date', 'DESC')])
|
news_list = News.search([('active', '=', True)], limit=5, order=[('publish_date', 'DESC')])
|
||||||
last_rate,prev_rate = self.get_last_two_fx_rates()
|
last_rate,prev_rate, = self.get_last_five_fx_rates()
|
||||||
if last_rate and prev_rate:
|
if last_rate and prev_rate:
|
||||||
variation = ((last_rate - prev_rate) / prev_rate) * 100 if prev_rate else 0
|
variation = ((last_rate - prev_rate) / prev_rate) * 100 if prev_rate else 0
|
||||||
direction = "📈" if variation > 0 else "📉"
|
direction = "📈" if variation > 0 else "📉"
|
||||||
|
|||||||
Reference in New Issue
Block a user