Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] choose between brand or company values in layout #201

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

_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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually some fields are still not overridden.

'report_header'
'company_details'
'report_layout_id'

To elaborate.
The error is gone. A report is generated. But it is rather a mixture of the report set on the company level and the brand level.

The colors are a mixture of both settings.
The tag line/header is not filled with the "brand" one.
Background image not working.

The adress still show the company adress. Instead of the adress of the Brand.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsie part of this bug is actually fixed in #195

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bosd

Can you mark this as resolved to allow merging again ?

@OCA/brand-maintainers Can someone approve this PR ? Please...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bosd

Can you mark this as resolved to allow merging again ?

@OCA/brand-maintainers Can someone approve this PR ? Please...

Yeah, I could do that. But it is actually not resolved. So maybe better fix the functionality before merging.

]

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
Loading