Skip to content

Commit

Permalink
[ADD] operating_unit_custom_header
Browse files Browse the repository at this point in the history
  • Loading branch information
cjallais committed Jan 17, 2024
1 parent 8c5be33 commit 355f134
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 0 deletions.
48 changes: 48 additions & 0 deletions operating_unit_custom_header/README.rst
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
24 changes: 24 additions & 0 deletions operating_unit_custom_header/__init__.py
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,
}
)
18 changes: 18 additions & 0 deletions operating_unit_custom_header/__manifest__.py
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",
}
1 change: 1 addition & 0 deletions operating_unit_custom_header/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import operating_unit
86 changes: 86 additions & 0 deletions operating_unit_custom_header/models/operating_unit.py
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()

Check warning on line 65 in operating_unit_custom_header/models/operating_unit.py

View check run for this annotation

Codecov / codecov/patch

operating_unit_custom_header/models/operating_unit.py#L61-L65

Added lines #L61 - L65 were not covered by tests

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 = (

Check warning on line 74 in operating_unit_custom_header/models/operating_unit.py

View check run for this annotation

Codecov / codecov/patch

operating_unit_custom_header/models/operating_unit.py#L74

Added line #L74 was not covered by tests
"operating_unit_custom_header.header_%s" % self.code
)
self.footer_view_id.key = (

Check warning on line 77 in operating_unit_custom_header/models/operating_unit.py

View check run for this annotation

Codecov / codecov/patch

operating_unit_custom_header/models/operating_unit.py#L77

Added line #L77 was not covered by tests
"operating_unit_custom_header.footer_%s" % self.code
)
return res

def open_translations_header(self):
return self.header_view_id.open_translations()

Check warning on line 83 in operating_unit_custom_header/models/operating_unit.py

View check run for this annotation

Codecov / codecov/patch

operating_unit_custom_header/models/operating_unit.py#L83

Added line #L83 was not covered by tests

def open_translations_footer(self):
return self.footer_view_id.open_translations()

Check warning on line 86 in operating_unit_custom_header/models/operating_unit.py

View check run for this annotation

Codecov / codecov/patch

operating_unit_custom_header/models/operating_unit.py#L86

Added line #L86 was not covered by tests
46 changes: 46 additions & 0 deletions operating_unit_custom_header/views/operating_unit_views.xml
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>
Loading

0 comments on commit 355f134

Please sign in to comment.