Browse Source

[MIG] mail_compose_select_lang: Migrated to 10.0

Note this migration comes with a feature loss as translated reports
is no longer possible via a python override (translations are done
in the report templates themselves; therefore every report would
need an inherited version).

This module was migrated from 8.0 to 10.0 directly, which explains
the consequent diff.
pull/101/head
Damien Bouvy 8 years ago
parent
commit
3d1f18da25
No known key found for this signature in database GPG Key ID: 1D0AB759B4B928E3
  1. 14
      mail_compose_select_lang/README.rst
  2. 6
      mail_compose_select_lang/__manifest__.py
  3. 3
      mail_compose_select_lang/models/__init__.py
  4. 20
      mail_compose_select_lang/models/email_template.py
  5. 22
      mail_compose_select_lang/models/mail_template.py
  6. 20
      mail_compose_select_lang/models/report.py
  7. 29
      mail_compose_select_lang/wizard/mail_compose_message.py
  8. 11
      mail_compose_select_lang/wizard/mail_compose_message_view.xml

14
mail_compose_select_lang/README.rst

@ -4,8 +4,6 @@ Select language in mail compose window
This module allows to select the language for the mail content directly in
the mail compose window.
It also translates attachments that can be linked to the email template.
Usage
=====
@ -13,6 +11,18 @@ By default, mail compose window will use corresponding language for showing the
contents, but you will be able to select another language from the dropdown
box "Force language" in the bottom right part.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/10.0
Known issues / Roadmap
======================
* Translating attachments is no longer supported as the mechanism for report
translation has changed. Every report template is translated by a rebrowse
in the template itself; to make them translatable an inherited view is needed
for *every* report.
Bug Tracker
===========

6
mail_compose_select_lang/__manifest__.py

@ -6,17 +6,17 @@
{
'name': 'Select language in mail compose window',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'category': 'Marketing',
'author': 'Serv. Tecnol. Avanzados - Pedro M. Baeza, '
'Antiun Ingeniería S.L.,'
'Odoo Community Association (OCA)',
'website': 'http://www.serviciosbaeza.com',
'depends': [
'email_template',
'mail',
],
'data': [
'wizard/mail_compose_message_view.xml',
],
'installable': False,
'installable': True,
}

3
mail_compose_select_lang/models/__init__.py

@ -3,5 +3,4 @@
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See LICENSE file on root folder for details
##############################################################################
from . import email_template
from . import report
from . import mail_template

20
mail_compose_select_lang/models/email_template.py

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See LICENSE file on root folder for details
##############################################################################
from openerp import models, api
class EmailTemplate(models.Model):
_inherit = 'email.template'
@api.model
def get_email_template_batch(self, template_id=False, res_ids=None):
if template_id and res_ids and self.env.context.get('force_lang'):
template = self.env['email.template'].with_context(
lang=self.env.context['force_lang']).browse(template_id)
return dict.fromkeys(res_ids, template)
else:
return super(EmailTemplate, self).get_email_template_batch(
template_id=template_id, res_ids=res_ids)

22
mail_compose_select_lang/models/mail_template.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See LICENSE file on root folder for details
##############################################################################
from odoo import models, api
class MailTemplate(models.Model):
_inherit = 'mail.template'
@api.model
def get_email_template(self, res_ids):
"""
Rebrowse a template with force_lang context key if it is set.
"""
if self.ids and res_ids and self.env.context.get('force_lang'):
self.ensure_one() # keep behaviour consistent with super function
template = self.with_context(lang=self.env.context['force_lang'])
return dict.fromkeys(res_ids, template)
else:
return super(MailTemplate, self).get_email_template(res_ids)

20
mail_compose_select_lang/models/report.py

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See LICENSE file on root folder for details
##############################################################################
from openerp import models, api
class Report(models.Model):
_inherit = 'report'
@api.model
def translate_doc(self, doc_id, model, lang_field, template, values):
if self.env.context.get('force_lang'):
obj = self.with_context(lang=self.env.context['force_lang'],
translatable=True)
else:
obj = self
return super(Report, obj).translate_doc(
doc_id, model, lang_field, template, values)

29
mail_compose_select_lang/wizard/mail_compose_message.py

@ -3,7 +3,7 @@
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See LICENSE file on root folder for details
##############################################################################
from openerp import models, fields, api
from odoo import models, fields, api
class MailComposeMessage(models.TransientModel):
@ -12,14 +12,19 @@ class MailComposeMessage(models.TransientModel):
lang = fields.Many2one(
comodel_name="res.lang", string="Force language")
@api.multi
def onchange_lang(
self, lang, template_id, composition_mode, model, res_id):
res = {}
if lang:
lang = self.env['res.lang'].browse(lang)
obj = self.with_context(force_lang=lang.code)
res = obj.onchange_template_id(
composition_mode=composition_mode, model=model,
template_id=template_id, res_id=res_id)
return res
@api.onchange('lang', 'template_id')
def onchange_template_id_wrapper(self):
"""
Trigger the onchange with special context key.
This context key will trigger a rebrowse with the correct language
of the template in the get_email_template function of the mail.template
model
"""
self.ensure_one()
lang = self.lang.code
values = self.with_context(force_lang=lang).onchange_template_id(
self.template_id.id, self.composition_mode,
self.model, self.res_id)['value']
for fname, value in values.iteritems():
setattr(self, fname, value)

11
mail_compose_select_lang/wizard/mail_compose_message_view.xml

@ -5,16 +5,19 @@
<record model="ir.ui.view" id="email_compose_message_wizard_inherit_form_lang">
<field name="name">mail.compose.message.form.lang</field>
<field name="model">mail.compose.message</field>
<field name="inherit_id" ref="email_template.email_compose_message_wizard_inherit_form" />
<field name="inherit_id" ref="mail.email_compose_message_wizard_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='template_id']/.." position="before">
<div>Force language
<span attrs="{'invisible': [('template_id', '=', False)]}">
<label for="lang"/>
<field name="lang"
class="oe_inline"
options="{'no_create': True}"
on_change="onchange_lang(lang, template_id, composition_mode, model, res_id, context)"
/>
</div>
<span class="alert alert-warning" attrs="{'invisible': [('lang', '=', False)]}">
<i class="fa fa-exclamation-triangle"/> Attached documents will not be translated.
</span>
</span>
</xpath>
</field>
</record>

Loading…
Cancel
Save