Skip to content

Commit

Permalink
[16.0][IMP] choose between brand or company values in layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche committed Jan 8, 2025
1 parent 89b83f5 commit 5e809c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions brand_external_report_layout/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import res_brand
from . import res_company
15 changes: 15 additions & 0 deletions brand_external_report_layout/models/res_brand.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ class ResBrand(models.Model):

_inherit = "res.brand"

def _get_company_overriden_fields(self):
return [

Check warning on line 15 in brand_external_report_layout/models/res_brand.py

View check run for this annotation

Codecov / codecov/patch

brand_external_report_layout/models/res_brand.py#L15

Added line #L15 was not covered by tests
"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(
Expand Down
24 changes: 24 additions & 0 deletions brand_external_report_layout/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>

from odoo import models


class CompanyBrandAdapter:
def __init__(self, company, brand):
super().__init__()

Check warning on line 9 in brand_external_report_layout/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

brand_external_report_layout/models/res_company.py#L9

Added line #L9 was not covered by tests
for field in dir(company):
if field.startswith("__"):
continue
brands_fields = brand._get_company_overriden_fields()

Check warning on line 13 in brand_external_report_layout/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

brand_external_report_layout/models/res_company.py#L12-L13

Added lines #L12 - L13 were not covered by tests
if field in brands_fields and getattr(brand, field):
setattr(self, field, getattr(brand, field))

Check warning on line 15 in brand_external_report_layout/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

brand_external_report_layout/models/res_company.py#L15

Added line #L15 was not covered by tests
else:
setattr(self, field, getattr(company, field))

Check warning on line 17 in brand_external_report_layout/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

brand_external_report_layout/models/res_company.py#L17

Added line #L17 was not covered by tests


class ResCompany(models.Model):
_inherit = "res.company"

def _get_company_brand_adapter(self, brand):
return CompanyBrandAdapter(self, brand)

Check warning on line 24 in brand_external_report_layout/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

brand_external_report_layout/models/res_company.py#L24

Added line #L24 was not covered by tests
7 changes: 5 additions & 2 deletions brand_external_report_layout/views/report_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
>
<t t-set="company" t-value="o.brand_id.sudo()" />
<t t-raw="0" />
<t
t-set="company"
t-value="company.sudo()._get_company_brand_adapter(o.brand_id)"
/>
<t t-out="0" />
</t>
<t t-else="else" name="brand_not_set" />
</xpath>
Expand Down

0 comments on commit 5e809c3

Please sign in to comment.