From 355f13484b5000e7c5fd68ac0f6171a3dfa9ac25 Mon Sep 17 00:00:00 2001 From: cjallais Date: Wed, 17 Jan 2024 15:36:41 -0500 Subject: [PATCH] [ADD] operating_unit_custom_header --- operating_unit_custom_header/README.rst | 48 ++++ operating_unit_custom_header/__init__.py | 24 ++ operating_unit_custom_header/__manifest__.py | 18 ++ .../models/__init__.py | 1 + .../models/operating_unit.py | 86 +++++++ .../views/operating_unit_views.xml | 46 ++++ .../views/templates.xml | 228 ++++++++++++++++++ .../odoo/addons/operating_unit_custom_header | 1 + setup/operating_unit_custom_header/setup.py | 6 + 9 files changed, 458 insertions(+) create mode 100644 operating_unit_custom_header/README.rst create mode 100644 operating_unit_custom_header/__init__.py create mode 100644 operating_unit_custom_header/__manifest__.py create mode 100644 operating_unit_custom_header/models/__init__.py create mode 100644 operating_unit_custom_header/models/operating_unit.py create mode 100644 operating_unit_custom_header/views/operating_unit_views.xml create mode 100644 operating_unit_custom_header/views/templates.xml create mode 120000 setup/operating_unit_custom_header/odoo/addons/operating_unit_custom_header create mode 100644 setup/operating_unit_custom_header/setup.py diff --git a/operating_unit_custom_header/README.rst b/operating_unit_custom_header/README.rst new file mode 100644 index 0000000000..4c9bb0cd68 --- /dev/null +++ b/operating_unit_custom_header/README.rst @@ -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: + + *Logo* + + +Bug Tracker +=========== + +Problems with the module? +Write to: + + +Credits +======= + +Authors +~~~~~~~ + +* ArcheTI + +Contributors +------------ + + +* Cécile Jallais + + +.. image:: https://www.archeti.com/logo.png + :alt: ArcheTI + :target: https://archeti.com diff --git a/operating_unit_custom_header/__init__.py b/operating_unit_custom_header/__init__.py new file mode 100644 index 0000000000..2b836b0017 --- /dev/null +++ b/operating_unit_custom_header/__init__.py @@ -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, + } + ) diff --git a/operating_unit_custom_header/__manifest__.py b/operating_unit_custom_header/__manifest__.py new file mode 100644 index 0000000000..f8f8edc04d --- /dev/null +++ b/operating_unit_custom_header/__manifest__.py @@ -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", +} diff --git a/operating_unit_custom_header/models/__init__.py b/operating_unit_custom_header/models/__init__.py new file mode 100644 index 0000000000..f5f887b83c --- /dev/null +++ b/operating_unit_custom_header/models/__init__.py @@ -0,0 +1 @@ +from . import operating_unit diff --git a/operating_unit_custom_header/models/operating_unit.py b/operating_unit_custom_header/models/operating_unit.py new file mode 100644 index 0000000000..f414ce0ac6 --- /dev/null +++ b/operating_unit_custom_header/models/operating_unit.py @@ -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() diff --git a/operating_unit_custom_header/views/operating_unit_views.xml b/operating_unit_custom_header/views/operating_unit_views.xml new file mode 100644 index 0000000000..6eaa67e285 --- /dev/null +++ b/operating_unit_custom_header/views/operating_unit_views.xml @@ -0,0 +1,46 @@ + + + + op.default_header.form + operating.unit + + + + + + +