8000 [IMP] brand_external_report_layout : keep original company for report… by metaminux · Pull Request #180 · OCA/brand · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[IMP] brand_external_report_layout : keep original company for report… #180

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

Closed
wants to merge 2 commits into from
Closed
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
35 changes: 24 additions & 11 deletions brand_external_report_layout/models/res_brand.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@
external_report_layout_id = fields.Many2one(
comodel_name="ir.ui.view", string="Document Template"
)
report_header = fields.Text(
help="Appears by default on the top right corner of your printed "
"documents (report header).",
)
report_footer = fields.Text(
translate=True,
help="Footer text displayed at the bottom of all reports.",
report_header = fields.Html(
string="Brand Tagline",
help="Appears by default on the top right corner of your printed documents "
"(report header).",
)
paperformat_id = fields.Many2one(
"report.paperformat",
Expand All @@ -64,10 +61,6 @@
)
primary_color = fields.Char()
secondary_color = fields.Char()
company_details = fields.Html(
string="Brand Details",
help="Header text displayed at the top of all reports.",
)
layout_background = fields.Selection(
[("Blank", "Blank"), ("Geometric", "Geometric"), ("Custom", "Custom")],
default="Blank",
Expand Down Expand Up @@ -112,6 +105,26 @@
def _get_style_fields(self):
return {"external_report_layout_id", "font", "primary_color", "secondary_color"}

@api.model
def _get_company_overriden_fields(self):
return {

Check warning on line 110 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#L110

Added line #L110 was not covered by tests
"name",
"logo",
"external_report_layout_id",
"report_header",
"paperformat_id",
"font",
"primary_color",
"secondary_color",
"layout_background",
"layout_background_image",
}

def _get_style_vals(self):
res = self.read(self._get_company_overriden_fields())[0]
res.pop("id")
return res

Check warning on line 126 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#L124-L126

Added lines #L124 - L126 were not covered by tests

@api.model_create_multi
def create(self, vals_list):
companies = super().create(vals_list)
Expand Down
18 changes: 18 additions & 0 deletions brand_external_report_layout/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Guillaume Masson <guillaume.masson@meta-it.fr>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class ResCompany(models.Model):

_inherit = "res.company"

def _get_style_vals(self):
res = self.read(self.env["res.brand"]._get_company_overriden_fields())[0]
res.pop("id")
return res

Check warning on line 14 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-L14

Added lines #L12 - L14 were not covered by tests

def update_style(self, vals):
self.write(vals)
return self

Check warning on line 18 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-L18

Added lines #L17 - L18 were not covered by tests
45 changes: 35 additions & 10 deletions brand_external_report_layout/views/report_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,44 @@
<template id="brand_external_layout" inherit_id="web.external_layout">
<xpath expr="//t[@t-if='not company']" position="after">
<t t-if="doc and not o" t-set="o" t-value="doc" />
<t t-if="brand" t-set="brand_id" t-value="brand.id" />
<t
t-elif="o and 'brand_id' in o.fields_get() and o.brand_id and o.brand_id.external_report_layout_id"
t-if="brand_document_layout"
t-set="brand_id"
t-value="o.brand_id.id"
t-value="brand_document_layout.id"
/>
<t t-else="" t-set="brand_id" t-value="0" />
<t
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-elif="o and 'brand_id' in o.fields_get() and o.brand_id">
<t t-set="brand" t-value="o.brand_id.sudo()" />
<t t-set="brand_id" t-value="brand.id" />
</t>
<t t-else="">
<t t-set="brand" t-value="0" />
<t t-set="brand_id" t-value="0" />
</t>
<t t-if="brand and brand.external_report_layout_id">
<t t-if="not company">
<t t-set="company" t-value="brand.sudo()" />
<t t-set="company_was_set" t-value="0" />
</t>
<t t-else="else">
<t t-set="company_was_set" t-value="1" />
<t t-set="brand_style_vals" t-value="brand._get_style_vals()" />
<t
t-set="company_style_vals"
t-value="company.sudo()._get_style_vals()"
/>
<t
t-set="company"
t-value="company.update_style(brand_style_vals)"
/>
</t>
<t t-call="{{brand.external_report_layout_id.sudo().key}}"><t
t-out="0"
/></t>
<t
t-if="company_was_set"
t-set="company"
t-value="company.update_style(company_style_vals)"
/>
</t>
<t t-else="else" name="brand_not_set" />
</xpath>
Expand Down
20 changes: 4 additions & 16 deletions brand_external_report_layout/wizards/brand_document_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class BrandDocumentLayout(models.TransientModel):
brand_id = fields.Many2one("res.brand", required=True)

logo = fields.Binary(related="brand_id.logo", readonly=False)
report_header = fields.Text(related="brand_id.report_header", readonly=False)
report_footer = fields.Text(related="brand_id.report_footer", readonly=False)
report_header = fields.Html(related="brand_id.report_header", readonly=False)
report_footer = fields.Html(default=None, readonly=True)
paperformat_id = fields.Many2one(related="brand_id.paperformat_id", readonly=False)
external_report_layout_id = fields.Many2one(
related="brand_id.external_report_layout_id", readonly=False
Expand All @@ -30,7 +30,7 @@ class BrandDocumentLayout(models.TransientModel):
font = fields.Selection(related="brand_id.font", readonly=False)
primary_color = fields.Char(related="brand_id.primary_color", readonly=False)
secondary_color = fields.Char(related="brand_id.secondary_color", readonly=False)
company_details = fields.Html(related="brand_id.company_details", readonly=False)
company_details = fields.Html(default=None, readonly=True)
layout_background = fields.Selection(
related="brand_id.layout_background", readonly=False
)
Expand All @@ -47,16 +47,6 @@ def _onchange_brand_id(self):
for wizard in self:
wizard.logo = wizard.brand_id.logo
wizard.report_header = wizard.brand_id.report_header
wizard.report_footer = (
wizard.brand_id.report_footer
if isinstance(wizard.brand_id.report_footer, str)
else wizard.report_footer
)
wizard.company_details = (
wizard.brand_id.company_details
if isinstance(wizard.brand_id.company_details, str)
else wizard.company_details
)
wizard.paperformat_id = wizard.brand_id.paperformat_id
wizard.external_report_layout_id = wizard.brand_id.external_report_layout_id
wizard.font = wizard.brand_id.font
Expand Down Expand Up @@ -104,10 +94,8 @@ def _get_asset_style(self):
"primary_color",
"secondary_color",
"report_header",
"report_footer",
"layout_background",
"layout_background_image",
"company_details",
)
def _compute_preview(self):
styles = self._get_asset_style()
Expand All @@ -124,7 +112,7 @@ def _compute_preview(self):
wizard.preview = ir_ui_view._render_template(
"web.report_invoice_wizard_preview",
{
"brand": wizard_with_logo,
"brand_document_layout": wizard_with_logo,
"c A128 ompany": wizard_with_logo,
"preview_css": preview_css,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<xpath expr="//field[@name='company_id']" position="after">
<field name="brand_id" invisible="1" />
</xpath>
<field name="company_details" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="report_footer" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
</odoo>
0