Browse Source

Merge pull request #192 from StefanRijnhart/8.0-language_path_mixin_therp

[ADD] Language path mixin
pull/198/head
Daniel Reis 10 years ago
parent
commit
506d535d37
  1. 83
      language_path_mixin/README.rst
  2. 1
      language_path_mixin/__init__.py
  3. 33
      language_path_mixin/__openerp__.py
  4. 1
      language_path_mixin/models/__init__.py
  5. 49
      language_path_mixin/models/language_path_mixin.py
  6. BIN
      language_path_mixin/static/description/icon.png

83
language_path_mixin/README.rst

@ -0,0 +1,83 @@
.. 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 RML
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
=============
With a dependency on this module, you can have any model inherit from the mixin
model 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 <https://github.com/OCA/server-tools/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 <https://github.com/OCA/server-tools/issues/new?body=module:%20language_path_mixin%0Aversion:%201.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Stefan Rijnhart <stefan@therp.nl>
* Holger Brunn <hbrunn@therp.nl>
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.

1
language_path_mixin/__init__.py

@ -0,0 +1 @@
from . import models

33
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 (<http://therp.nl>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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',
],
}

1
language_path_mixin/models/__init__.py

@ -0,0 +1 @@
from . import language_path_mixin

49
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 (<http://therp.nl>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)

BIN
language_path_mixin/static/description/icon.png

After

Width: 48  |  Height: 48  |  Size: 4.0 KiB

Loading…
Cancel
Save