diff --git a/mail_compose_select_lang/README.rst b/mail_compose_select_lang/README.rst index c36740ac..0dcc4580 100644 --- a/mail_compose_select_lang/README.rst +++ b/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 =========== diff --git a/mail_compose_select_lang/__manifest__.py b/mail_compose_select_lang/__manifest__.py index 0a5ee4c1..f932bf4c 100644 --- a/mail_compose_select_lang/__manifest__.py +++ b/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, } diff --git a/mail_compose_select_lang/models/__init__.py b/mail_compose_select_lang/models/__init__.py index 208bd250..8801ee3b 100644 --- a/mail_compose_select_lang/models/__init__.py +++ b/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 diff --git a/mail_compose_select_lang/models/email_template.py b/mail_compose_select_lang/models/email_template.py deleted file mode 100644 index 9c349675..00000000 --- a/mail_compose_select_lang/models/email_template.py +++ /dev/null @@ -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) diff --git a/mail_compose_select_lang/models/mail_template.py b/mail_compose_select_lang/models/mail_template.py new file mode 100644 index 00000000..09ebb15f --- /dev/null +++ b/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) diff --git a/mail_compose_select_lang/models/report.py b/mail_compose_select_lang/models/report.py deleted file mode 100644 index 8e200a5b..00000000 --- a/mail_compose_select_lang/models/report.py +++ /dev/null @@ -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) diff --git a/mail_compose_select_lang/wizard/mail_compose_message.py b/mail_compose_select_lang/wizard/mail_compose_message.py index acfa7f6f..5bf48c51 100644 --- a/mail_compose_select_lang/wizard/mail_compose_message.py +++ b/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) diff --git a/mail_compose_select_lang/wizard/mail_compose_message_view.xml b/mail_compose_select_lang/wizard/mail_compose_message_view.xml index e4a7476c..e7415fee 100644 --- a/mail_compose_select_lang/wizard/mail_compose_message_view.xml +++ b/mail_compose_select_lang/wizard/mail_compose_message_view.xml @@ -5,17 +5,20 @@ mail.compose.message.form.lang mail.compose.message - + -
Force language + +
-
+ + Attached documents will not be translated. + + +