From 5368442e535116cc1aa9258199ca68b40ab4d10c Mon Sep 17 00:00:00 2001 From: Kev-Roche Date: Sun, 2 Jun 2024 15:04:27 +0200 Subject: [PATCH] [16.0][IMP] choose between brand or company values in layout --- .../models/__init__.py | 1 + .../models/res_brand.py | 15 ++++++++++++ .../models/res_company.py | 24 +++++++++++++++++++ .../views/report_template.xml | 7 ++++-- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 brand_external_report_layout/models/res_company.py diff --git a/brand_external_report_layout/models/__init__.py b/brand_external_report_layout/models/__init__.py index 3dc20cced..7ad212075 100644 --- a/brand_external_report_layout/models/__init__.py +++ b/brand_external_report_layout/models/__init__.py @@ -1 +1,2 @@ from . import res_brand +from . import res_company diff --git a/brand_external_report_layout/models/res_brand.py b/brand_external_report_layout/models/res_brand.py index 0d9c6d180..374335bea 100644 --- a/brand_external_report_layout/models/res_brand.py +++ b/brand_external_report_layout/models/res_brand.py @@ -11,6 +11,21 @@ class ResBrand(models.Model): _inherit = "res.brand" + def _get_company_overriden_fields(self): + return [ + "name", + "logo", + "external_report_layout_id", + "report_header", + "report_footer", + "paperformat_id", + "font", + "primary_color", + "secondary_color", + "layout_background", + "layout_background_image", + ] + def _get_default_brand_logo(self): return base64.b64encode( open( diff --git a/brand_external_report_layout/models/res_company.py b/brand_external_report_layout/models/res_company.py new file mode 100644 index 000000000..52512e475 --- /dev/null +++ b/brand_external_report_layout/models/res_company.py @@ -0,0 +1,24 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Kévin Roche + +from odoo import models + + +class CompanyBrandAdapter: + def __init__(self, company, brand): + super().__init__() + for field in dir(company): + if field.startswith("__"): + continue + brands_fields = brand._get_company_overriden_fields() + if field in brands_fields and getattr(brand, field): + setattr(self, field, getattr(brand, field)) + else: + setattr(self, field, getattr(company, field)) + + +class ResCompany(models.Model): + _inherit = "res.company" + + def _get_company_brand_adapter(self, brand): + return CompanyBrandAdapter(self, brand) diff --git a/brand_external_report_layout/views/report_template.xml b/brand_external_report_layout/views/report_template.xml index d53ed913c..72c61ccf1 100644 --- a/brand_external_report_layout/views/report_template.xml +++ b/brand_external_report_layout/views/report_template.xml @@ -16,8 +16,11 @@ t-if="o and 'brand_id' in o.fields_get() and o.brand_id and o.brand_id.external_report_layout_id" t-call="{{o.brand_id.external_report_layout_id.sudo().key}}" > - - + +