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

[12.0][IMP] - manage different report layouts by brand #16

Merged
merged 5 commits into from
Feb 9, 2020
Merged
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
103 changes: 103 additions & 0 deletions brand_external_report_layout/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
============================
Brand External Report Layout
============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbrand-lightgray.png?logo=github
:target: https://github.com/OCA/brand/tree/12.0/brand_external_report_layout
:alt: OCA/brand
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/brand-12-0/brand-12-0-brand_external_report_layout
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/284/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to have a different layout by brand for your external
reports.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

#. Go to Settings > Users & Companies > Brands
#. Add a new brand or select an existing one
#. Enter brand information and select the a layout
#. Go to any branded object abd print the PDF report. It includes the information of the brand.

Known issues / Roadmap
======================

To simplify the customization of the external layout we replaced the variable
company that odoo compute in the external_layout view by the object brand.

With this module, all custom layouts will display brand information out of the box.

This was possible and easy to implement as the company and the brand models
inherit from partner model and share the same informational fields.

The computed variable company is used to set report header and footer. It's not
meant to be used in the report business logic itself. But in that case
(if a custom layout use the variable company for some-reason other then header
and footer) this module can cause an issue because the used field can be
missing in the brand model or not correctly set.

In this case, we recommend to always use document field company for this use-end.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/brand/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/brand/issues/new?body=module:%20brand_external_report_layout%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Souheil Bejaoui <souheil.bejaoui@acsone.eu>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/brand <https://github.com/OCA/brand/tree/12.0/brand_external_report_layout>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions brand_external_report_layout/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import tests
16 changes: 16 additions & 0 deletions brand_external_report_layout/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Brand External Report Layout',
'summary': """
This module allows you to have a different layout by brand for your
external reports.""",
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV,'
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/brand',
'depends': ['base', 'brand', 'web'],
'data': ['views/res_brand.xml', 'views/report_template.xml'],
}
1 change: 1 addition & 0 deletions brand_external_report_layout/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_brand
64 changes: 64 additions & 0 deletions brand_external_report_layout/models/res_brand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import base64
import os
from odoo import api, fields, models, tools, _


class ResBrand(models.Model):

_inherit = 'res.brand'

def _get_default_brand_logo(self):
return base64.b64encode(
open(
os.path.join(
tools.config['root_path'],
'addons',
'base',
'static',
'img',
'res_company_logo.png',
),
'rb',
).read()
)

logo = fields.Binary(
related='partner_id.image',
default=_get_default_brand_logo,
string="Brand Logo",
readonly=False,
)
external_report_layout_id = fields.Many2one(
comodel_name='ir.ui.view', string='Document Template'
)
report_header = fields.Text(
string='Report Header',
help='Appears by default on the top right corner of your printed '
'documents (report header).',
)
report_footer = fields.Text(
string='Report Footer',
translate=True,
help='Footer text displayed at the bottom of all reports.',
)

@api.multi
def change_report_template(self):
self.ensure_one()
form_view = self.env.ref(
'brand_external_report_layout.res_brand_document_template_form'
)
return {
'name': _('Choose Your Document Layout'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_id': self.id,
'res_model': 'res.brand',
'views': [(form_view.id, 'form')],
'view_id': form_view.id,
'target': 'new',
}
1 change: 1 addition & 0 deletions brand_external_report_layout/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>
2 changes: 2 additions & 0 deletions brand_external_report_layout/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows you to have a different layout by brand for your external
reports.
15 changes: 15 additions & 0 deletions brand_external_report_layout/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
To simplify the customization of the external layout we replaced the variable
company that odoo compute in the external_layout view by the object brand.

With this module, all custom layouts will display brand information out of the box.

This was possible and easy to implement as the company and the brand models
inherit from partner model and share the same informational fields.

The computed variable company is used to set report header and footer. It's not
meant to be used in the report business logic itself. But in that case
(if a custom layout use the variable company for some-reason other then header
and footer) this module can cause an issue because the used field can be
missing in the brand model or not correctly set.

In this case, we recommend to always use document field company for this use-end.
6 changes: 6 additions & 0 deletions brand_external_report_layout/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this module, you need to:

#. Go to Settings > Users & Companies > Brands
#. Add a new brand or select an existing one
#. Enter brand information and select the a layout
#. Go to any branded object abd print the PDF report. It includes the information of the brand.
Loading