From 550ad57354576c4076bad5371453e333b66350ae Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Wed, 7 Jan 2026 16:17:21 +0100 Subject: [PATCH 1/5] 07.01.26 --- modules/purchase_trade/credit_risk.py | 2 +- modules/purchase_trade/dashboard.py | 4 +++- modules/purchase_trade/forex.py | 4 ++-- modules/purchase_trade/global_reporting.py | 5 ++++- modules/purchase_trade/purchase.py | 4 ++-- modules/purchase_trade/view/gr_configuration_form.xml | 6 ++++++ 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/purchase_trade/credit_risk.py b/modules/purchase_trade/credit_risk.py index 1f0d779..90bf2d0 100644 --- a/modules/purchase_trade/credit_risk.py +++ b/modules/purchase_trade/credit_risk.py @@ -155,7 +155,7 @@ class Party(metaclass=PoolMeta): if overdue > 0: # scale by overdue relative to limit limit = self.credit_limit or 1 - score += int(min(40, (overdue / float(limit)) * 100)) + score += int(min(40, (float(overdue) / float(limit)) * 100)) # cap if score > 100: diff --git a/modules/purchase_trade/dashboard.py b/modules/purchase_trade/dashboard.py index 6b5cb63..d01aec7 100755 --- a/modules/purchase_trade/dashboard.py +++ b/modules/purchase_trade/dashboard.py @@ -551,12 +551,14 @@ class Dashboard(ModelSQL, ModelView): return pu def gen_url(self,name=None): + Configuration = Pool().get('gr.configuration') + config = Configuration.search(['id','>',0])[0] payload = { "resource": {"dashboard": self.bi_id}, "params": {}, "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=30), } - token = jwt.encode(payload, "798f256d3119a3292bf121196c2a38dddf2cad155c0b6b0b444efc34c6db197c", algorithm="HS256") + token = jwt.encode(payload, config.payload, algorithm="HS256") logger.info("TOKEN:%s",token) return f"metabase:http://vps107.geneva.hosting:3000/embed/dashboard/{token}#bordered=true&titled=true" diff --git a/modules/purchase_trade/forex.py b/modules/purchase_trade/forex.py index 9c83e95..3945d71 100755 --- a/modules/purchase_trade/forex.py +++ b/modules/purchase_trade/forex.py @@ -385,11 +385,11 @@ class ForexBI(ModelSingleton,ModelSQL, ModelView): config = Configuration.search(['id','>',0])[0] payload = { - "resource": {"dashboard": 3}, + "resource": {"dashboard": config.forex_id}, "params": {}, "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=30), } - token = jwt.encode(payload, "798f256d3119a3292bf121196c2a38dddf2cad155c0b6b0b444efc34c6db197c", algorithm="HS256") + token = jwt.encode(payload, config.payload, algorithm="HS256") logger.info("TOKEN:%s",token) if config.dark: url = f"metabase:{config.bi}/embed/dashboard/{token}#theme=night&bordered=true&titled=true" diff --git a/modules/purchase_trade/global_reporting.py b/modules/purchase_trade/global_reporting.py index 45aa6eb..fa5c188 100644 --- a/modules/purchase_trade/global_reporting.py +++ b/modules/purchase_trade/global_reporting.py @@ -13,4 +13,7 @@ class GRConfiguration(ModelSingleton, ModelSQL, ModelView): bi = fields.Char("BI connexion") dashboard = fields.Char("Dashboard connexion") - dark = fields.Boolean("Dark mode") \ No newline at end of file + dark = fields.Boolean("Dark mode") + pnl_id = fields.Integer("Pnl ID") + forex_id = fields.Integer("Forex ID") + payload = fields.Char("Metabase payload") \ No newline at end of file diff --git a/modules/purchase_trade/purchase.py b/modules/purchase_trade/purchase.py index 643e31d..c3d046a 100755 --- a/modules/purchase_trade/purchase.py +++ b/modules/purchase_trade/purchase.py @@ -1011,11 +1011,11 @@ class PnlBI(ModelSingleton,ModelSQL, ModelView): config = Configuration.search(['id','>',0])[0] payload = { - "resource": {"dashboard": 2}, + "resource": {"dashboard": config.pnl_id}, "params": {}, "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=30), } - token = jwt.encode(payload, "5d95b70853af02897d1240e2ee4834e2bf065a5132b5d09840fbef6cf683ae45", algorithm="HS256") + token = jwt.encode(payload, config.payload, algorithm="HS256") logger.info("TOKEN:%s",token) if config.dark: url = f"metabase:{config.bi}/embed/dashboard/{token}#theme=night&bordered=true&titled=true" diff --git a/modules/purchase_trade/view/gr_configuration_form.xml b/modules/purchase_trade/view/gr_configuration_form.xml index 672251f..4d154c7 100644 --- a/modules/purchase_trade/view/gr_configuration_form.xml +++ b/modules/purchase_trade/view/gr_configuration_form.xml @@ -5,4 +5,10 @@