From 9f04e393391246ff43245a684daf459de40c652a Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Thu, 25 Jun 2015 21:17:42 +0200 Subject: [PATCH] [ADD] Language path mixin --- language_path_mixin/README.rst | 85 ++++++++++++++++++ language_path_mixin/__init__.py | 1 + language_path_mixin/__openerp__.py | 33 +++++++ language_path_mixin/models/__init__.py | 1 + .../models/language_path_mixin.py | 49 ++++++++++ .../static/description/icon.png | Bin 0 -> 4080 bytes 6 files changed, 169 insertions(+) create mode 100644 language_path_mixin/README.rst create mode 100644 language_path_mixin/__init__.py create mode 100644 language_path_mixin/__openerp__.py create mode 100644 language_path_mixin/models/__init__.py create mode 100644 language_path_mixin/models/language_path_mixin.py create mode 100644 language_path_mixin/static/description/icon.png 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 0000000000000000000000000000000000000000..ce901879b1269f6df92997ac85c84cb23cd8c7cd GIT binary patch literal 4080 zcmVlvB>9*DWB`D};qb65 zqv()hc7G{6Oq>O~Iv2h#-0$y*w(SD(w@9ypv z4NY0~>Z`x{xU{r1g`|x|7PFmk(E6i9LGUbRh&QHZZtMD z@{%OgLzkZ2zWvLN2L`Zy{rUukBkKzCXGbL^rO=`%f}$wUG>yLgK2+CK@}dxUf6eN( zuMq@cjC}va7hg#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