Merge dev from main #1
@@ -238,9 +238,12 @@ class Dashboard(ModelSQL, ModelView):
|
|||||||
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()
|
f1,f2,f3,f4,f5,d1,d2,d3,d4,d5 = self.get_last_five_fx_rates()
|
||||||
Pnl = Pool().get('valuation.valuation.line')
|
Valuation = Pool().get('valuation.valuation')
|
||||||
pnls = Pnl.search(['id','>',0])
|
total_t, total_t1, variation = Valuation.get_totals()
|
||||||
pnl_amount = "{:,.0f}".format(round(sum([e.amount for e in pnls]),0))
|
pnl_amount = "{:,.0f}".format(round(total_t,0))
|
||||||
|
pnl_variation = 0
|
||||||
|
if total_t1:
|
||||||
|
pnl_variation = "{:,.2f}".format(round((total_t/total_t1 - 1)*100,0))
|
||||||
Open = Pool().get('open.position')
|
Open = Pool().get('open.position')
|
||||||
opens = Open.search(['id','>',0])
|
opens = Open.search(['id','>',0])
|
||||||
exposure = "{:,.0f}".format(round(sum([e.net_exposure for e in opens]),0))
|
exposure = "{:,.0f}".format(round(sum([e.net_exposure for e in opens]),0))
|
||||||
@@ -303,6 +306,8 @@ class Dashboard(ModelSQL, ModelView):
|
|||||||
config.dashboard +
|
config.dashboard +
|
||||||
"/dashboard/index.html?pnl_amount="
|
"/dashboard/index.html?pnl_amount="
|
||||||
+ str(pnl_amount)
|
+ str(pnl_amount)
|
||||||
|
+ "&pnl_variation="
|
||||||
|
+ str(pnl_variation)
|
||||||
+ "&exposure="
|
+ "&exposure="
|
||||||
+ str(exposure)
|
+ str(exposure)
|
||||||
+ "&topay="
|
+ "&topay="
|
||||||
|
|||||||
@@ -353,6 +353,57 @@ class Valuation(ValuationBase, ModelView):
|
|||||||
"Valuation"
|
"Valuation"
|
||||||
__name__ = 'valuation.valuation'
|
__name__ = 'valuation.valuation'
|
||||||
|
|
||||||
|
class Valuation(ModelSQL):
|
||||||
|
__name__ = 'valuation.valuation'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_totals(cls):
|
||||||
|
cursor = Transaction().connection.cursor()
|
||||||
|
table = cls.__table__()
|
||||||
|
|
||||||
|
sql = f"""
|
||||||
|
WITH ranked AS (
|
||||||
|
SELECT
|
||||||
|
CASE
|
||||||
|
WHEN line IS NOT NULL THEN 'P:' || line::text
|
||||||
|
WHEN sale_line IS NOT NULL THEN 'S:' || sale_line::text
|
||||||
|
END AS block_key,
|
||||||
|
date,
|
||||||
|
amount,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY
|
||||||
|
CASE
|
||||||
|
WHEN line IS NOT NULL THEN 'P:' || line::text
|
||||||
|
WHEN sale_line IS NOT NULL THEN 'S:' || sale_line::text
|
||||||
|
END
|
||||||
|
ORDER BY date DESC
|
||||||
|
) AS rn
|
||||||
|
FROM {table}
|
||||||
|
WHERE line IS NOT NULL
|
||||||
|
OR sale_line IS NOT NULL
|
||||||
|
),
|
||||||
|
current_prev AS (
|
||||||
|
SELECT
|
||||||
|
block_key,
|
||||||
|
MAX(CASE WHEN rn = 1 THEN amount END) AS amount_t,
|
||||||
|
MAX(CASE WHEN rn = 2 THEN amount END) AS amount_t1
|
||||||
|
FROM ranked
|
||||||
|
WHERE rn <= 2
|
||||||
|
GROUP BY block_key
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
COALESCE(SUM(amount_t), 0) AS total_t,
|
||||||
|
COALESCE(SUM(amount_t1), 0) AS total_t1,
|
||||||
|
COALESCE(SUM(amount_t), 0)
|
||||||
|
- COALESCE(SUM(amount_t1), 0) AS variation
|
||||||
|
FROM current_prev
|
||||||
|
"""
|
||||||
|
|
||||||
|
cursor.execute(sql)
|
||||||
|
total_t, total_t1, variation = cursor.fetchone()
|
||||||
|
|
||||||
|
return total_t, total_t1, variation
|
||||||
|
|
||||||
class ValuationLine(ValuationBase, ModelView):
|
class ValuationLine(ValuationBase, ModelView):
|
||||||
"Last Valuation"
|
"Last Valuation"
|
||||||
__name__ = 'valuation.valuation.line'
|
__name__ = 'valuation.valuation.line'
|
||||||
|
|||||||
Reference in New Issue
Block a user