-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cjallais
committed
Jan 17, 2024
1 parent
8c5be33
commit 355f134
Showing
9 changed files
with
458 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
===================================================== | ||
Operating Unit Custom Header | ||
===================================================== | ||
|
||
This module adds custom header and footer by operating unit on reports | ||
The header and footer of the Operating Unit will appears on the report | ||
instead of the company header and footer. | ||
This module works with the four Odoo layout: light, boxed, clean and | ||
background. | ||
|
||
|
||
Configuration | ||
============= | ||
|
||
* Go to Settings / Users & Companies / Operating Units and modify the header and footer. By default, they are a copy of the company header and footer. | ||
|
||
|
||
note:: | ||
Ex. to change the logo in the header: | ||
|
||
*<img t-if="o.operating_unit_id.partner_id.image_1920" t-att-src="image_data_uri(o.operating_unit_id.partner_id.image_1920)" style="max-height: 45px;" alt="Logo"/>* | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Problems with the module? | ||
Write to: <support@archeti.com> | ||
|
||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* ArcheTI | ||
|
||
Contributors | ||
------------ | ||
|
||
|
||
* Cécile Jallais <cjallais@archeti.com> | ||
|
||
|
||
.. image:: https://www.archeti.com/logo.png | ||
:alt: ArcheTI | ||
:target: https://archeti.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from . import models | ||
from odoo import api, SUPERUSER_ID | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
op_ids = env["operating.unit"].search([]) | ||
for op in op_ids: | ||
op.footer_view_id = op._get_default_footer() | ||
op.header_view_id = op._get_default_header() | ||
op.footer = op._get_default_footer_xml() | ||
op.header = op._get_default_header_xml() | ||
op.header_view_id.write( | ||
{ | ||
"arch_base": op.header, | ||
"key": "operating_unit_custom_header.header_%s" % op.code, | ||
} | ||
) | ||
op.footer_view_id.write( | ||
{ | ||
"arch_base": op.footer, | ||
"key": "operating_unit_custom_header.footer_%s" % op.code, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Operating Unit Custom Header", | ||
"summary": """Custom header and footer by operating unit on reports""", | ||
"author": "ArcheTI, " "Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/operating-unit", | ||
"category": "report", | ||
"version": "14.0.1.0.0", | ||
"license": "LGPL-3", | ||
"depends": [ | ||
"base", | ||
"operating_unit", | ||
], | ||
"data": [ | ||
"views/templates.xml", | ||
"views/operating_unit_views.xml", | ||
], | ||
"post_init_hook": "post_init_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import operating_unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class OperatingUnit(models.Model): | ||
_inherit = "operating.unit" | ||
|
||
def _get_default_header(self): | ||
header_id = False | ||
header = self.env.ref("operating_unit_custom_header.op_header", False) | ||
if header: | ||
header_id = header.copy() | ||
return header_id | ||
|
||
def _get_default_header_xml(self): | ||
header_id = self.env.ref("operating_unit_custom_header.op_header", False) | ||
return header_id and header_id.arch_base or False | ||
|
||
def _get_default_footer_xml(self): | ||
footer_id = self.env.ref("operating_unit_custom_header.op_footer", False) | ||
return footer_id and footer_id.arch_base or False | ||
|
||
def _get_default_footer(self): | ||
footer_id = False | ||
footer = self.env.ref("operating_unit_custom_header.op_footer", False) | ||
if footer: | ||
footer_id = footer.copy() | ||
return footer_id | ||
|
||
footer_view_id = fields.Many2one( | ||
"ir.ui.view", "Footer Template", default=_get_default_footer | ||
) | ||
|
||
header_view_id = fields.Many2one( | ||
"ir.ui.view", "Header Template", default=_get_default_header | ||
) | ||
|
||
footer = fields.Text(string="Footer", default=_get_default_footer_xml) | ||
|
||
header = fields.Text(string="Header", default=_get_default_header_xml) | ||
|
||
@api.model | ||
def create(self, values): | ||
res = super(OperatingUnit, self).create(values) | ||
res.header_view_id.write( | ||
{ | ||
"arch_base": res.header, | ||
"key": "operating_unit_custom_header.header_%s" % res.code, | ||
} | ||
) | ||
res.footer_view_id.write( | ||
{ | ||
"arch_base": res.footer, | ||
"key": "operating_unit_custom_header.footer_%s" % res.code, | ||
} | ||
) | ||
|
||
return res | ||
|
||
def unlink(self): | ||
for op in self: | ||
footer_id = op.footer_view_id | ||
header_id = op.header_view_id | ||
super(OperatingUnit, op).unlink() | ||
footer_id.unlink() | ||
header_id.unlink() | ||
|
||
def write(self, vals): | ||
res = super(OperatingUnit, self).write(vals) | ||
if vals.get("header", False): | ||
self.header_view_id.arch_base = self.header | ||
if vals.get("footer", False): | ||
self.footer_view_id.arch_base = self.footer | ||
if vals.get("code", False): | ||
self.header_view_id.key = ( | ||
"operating_unit_custom_header.header_%s" % self.code | ||
) | ||
self.footer_view_id.key = ( | ||
"operating_unit_custom_header.footer_%s" % self.code | ||
) | ||
return res | ||
|
||
def open_translations_header(self): | ||
return self.header_view_id.open_translations() | ||
|
||
def open_translations_footer(self): | ||
return self.footer_view_id.open_translations() | ||
46 changes: 46 additions & 0 deletions
46
operating_unit_custom_header/views/operating_unit_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<odoo> | ||
|
||
<record id="view_op_default_header_form" model="ir.ui.view"> | ||
<field name="name">op.default_header.form</field> | ||
<field name="model">operating.unit</field> | ||
<field name="inherit_id" ref="operating_unit.view_operating_unit_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group" position="after"> | ||
<notebook> | ||
<page string="Header" name="header_page"> | ||
<field name="header_view_id" invisible="1" /> | ||
<button | ||
type="object" | ||
name="open_translations_header" | ||
string="Edit Translations" | ||
class="oe_link oe_right" | ||
/> | ||
<field | ||
name="header" | ||
widget="ace" | ||
options="{'mode': 'xml'}" | ||
readonly="0" | ||
/> | ||
|
||
</page> | ||
<page string="Footer" name="footer_page"> | ||
<field name="footer_view_id" invisible="1" /> | ||
<button | ||
type="object" | ||
name="open_translations_footer" | ||
string="Edit Translations" | ||
class="oe_link oe_right" | ||
/> | ||
<field | ||
name="footer" | ||
widget="ace" | ||
options="{'mode': 'xml'}" | ||
readonly="0" | ||
/> | ||
</page> | ||
</notebook> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
Oops, something went wrong.