diff --git a/language_path_mixin/README.rst b/language_path_mixin/README.rst new file mode 100644 index 000000000..86ce31855 --- /dev/null +++ b/language_path_mixin/README.rst @@ -0,0 +1,85 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Language path mixin +=================== +This is a technical module to restore the possibility of Odoo to print reports +in other languages than the user's language (for instance, the customer's +language in the case of a sale order). + +Odoo 8.0 has lost that capability due to an unlucky combination of technical +aspects of the deprecated RML report functionality and the new API. While the +static content of the report is translated fine, any translatable fields will +still be rendered in the language of the user. + +See https://github.com/odoo/odoo/issues/7301 for the original bug report. + +This module provides a tool for developers to work around this bug in their +Python code. + +Configuration +============= + +After installation of the module, you can import the mixin class that it +provides and have any model inherit from it in your python class definition. + +You can then assign your class a *_language_path* member to indicate where +to find the language into which its reports are to be translated. See the +following code example: + +.. code:: + + class SaleOrder(models.Model): + _name = 'sale.order' + _inherit = ['sale.order', 'language.path.mixin'] + _language_path = 'partner_id.lang' + +In RML reports for such a model, you can then iterate over the records in the +correct language using + + [[ repeatIn(objects.with_language_path(), 'o') ]] + +Usage +===== + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +* Kudos if you find a way to do this more elegantly, preferably with a simple +bugfix in the Odoo core + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 +`here `_. + +Credits +======= + +Contributors +------------ + +* Stefan Rijnhart +* Holger Brunn + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/language_path_mixin/__init__.py b/language_path_mixin/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/language_path_mixin/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/language_path_mixin/__openerp__.py b/language_path_mixin/__openerp__.py new file mode 100644 index 000000000..d443ee03e --- /dev/null +++ b/language_path_mixin/__openerp__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Odoo, an open source suite of business apps +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Language path mixin', + 'summary': "Setting the partner's language in RML reports", + 'version': '1.0', + 'author': 'Therp BV,Odoo Community Association (OCA)', + 'maintainer': 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/server-tools', + 'license': 'AGPL-3', + 'category': 'Tools', + 'depends': [ + 'base', + ], +} diff --git a/language_path_mixin/models/__init__.py b/language_path_mixin/models/__init__.py new file mode 100644 index 000000000..bbccf6111 --- /dev/null +++ b/language_path_mixin/models/__init__.py @@ -0,0 +1 @@ +from . import language_path_mixin diff --git a/language_path_mixin/models/language_path_mixin.py b/language_path_mixin/models/language_path_mixin.py new file mode 100644 index 000000000..843cb766c --- /dev/null +++ b/language_path_mixin/models/language_path_mixin.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Odoo, an open source suite of business apps +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import models + + +class LanguagePathMixin(models.AbstractModel): + """ Mixin class to print reports in a language taken from a field in the + record. """ + _name = 'language.path.mixin' + _language_path = False + + def with_language_path(self, path=None): + """ This method allows the system to iterate over a RecordSet with each + of the records being browsed in the language specified by the model's + _language_path attribute. Of course, this is a cache killer. It was + conceived to make translations in rml reports work again as using + setLang() in the report does not work as expected anymore in 8.0 due + to the way that caching works in the new API """ + path = path or self._language_path + for record in self: + if not path: + yield record + continue + lang = record + for part in path.split('.'): + lang = lang[part] + if not lang: + yield record + break + else: + yield record.with_context(lang=lang) diff --git a/language_path_mixin/static/description/icon.png b/language_path_mixin/static/description/icon.png new file mode 100644 index 000000000..ce901879b Binary files /dev/null and b/language_path_mixin/static/description/icon.png differ