You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. # (c) 2015 Pedro M. Baeza
  4. # License AGPL-3 - See LICENSE file on root folder for details
  5. ##############################################################################
  6. from odoo import models, fields, api
  7. class MailComposeMessage(models.TransientModel):
  8. _inherit = 'mail.compose.message'
  9. lang = fields.Many2one(
  10. comodel_name="res.lang", string="Force language")
  11. @api.onchange('lang', 'template_id')
  12. def onchange_template_id_wrapper(self):
  13. """
  14. Trigger the onchange with special context key.
  15. This context key will trigger a rebrowse with the correct language
  16. of the template in the get_email_template function of the mail.template
  17. model
  18. """
  19. self.ensure_one()
  20. lang = self.lang.code
  21. values = self.with_context(force_lang=lang).onchange_template_id(
  22. self.template_id.id, self.composition_mode,
  23. self.model, self.res_id)['value']
  24. for fname, value in values.iteritems():
  25. setattr(self, fname, value)