Files
external-public-addons/report_carbone/models/res/res_config_settings.py

41 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from odoo import fields, models
class CarboneResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
carbone_studio_url = fields.Char("Carbone Studio URL", config_parameter="report-engine.carbone_studio_url")
carbone_js_file_url = fields.Char("Carbone JS file URL", config_parameter="report-engine.carbone_js_file_url")
is_stage_mode = fields.Boolean(string="Test mode", config_parameter="report-engine.is_stage_mode")
prod_api_key = fields.Char(string="Prod API Key", config_parameter="report-engine.prod_api_key")
stage_api_key = fields.Char(string="Test API Key", config_parameter="report-engine.stage_api_key")
def open_ir_actions_reports(self):
return self.env["ir.actions.actions"]._for_xml_id("report_carbone.action_carbone_report_template_tree_all")
def retrieve_carbone_api_key(self, test_mode_key=False):
"""Depending on the ‘test mode’ checkbox or ‘test_mode_key’ parameter, either the production key or
the staging key is returned.
The value set in the UI (ir.config_parameter) takes priority. If absent, the environment variable
CARBONE_STAGE_API_KEY or CARBONE_PROD_API_KEY is used as a fallback.
"""
stage_mode = self.env["ir.config_parameter"].sudo().get_param("report-engine.is_stage_mode")
if stage_mode or test_mode_key:
return self.env["ir.config_parameter"].sudo().get_param("report-engine.stage_api_key") or os.environ.get(
"CARBONE_STAGE_API_KEY"
)
return self.env["ir.config_parameter"].sudo().get_param("report-engine.prod_api_key") or os.environ.get(
"CARBONE_PROD_API_KEY"
)
def action_download_carbone_documentation(self):
ir_action_report = self.env["ir.actions.report"]
return ir_action_report.action_download_carbone_documentation()
def action_download_carbone_file_sample(self):
ir_action_report = self.env["ir.actions.report"]
return ir_action_report.action_download_carbone_file_sample()