From f695e368115df3b5cfe7b837a479a23a02b794ef Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Thu, 25 Jun 2020 14:56:03 +0200 Subject: [PATCH] [IMP]GOLEM : allow force email sender --- golem_base/__manifest__.py | 2 +- golem_base/models/ir_mail_server.py | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/golem_base/__manifest__.py b/golem_base/__manifest__.py index e0edb47..e5e6f2d 100644 --- a/golem_base/__manifest__.py +++ b/golem_base/__manifest__.py @@ -19,7 +19,7 @@ { 'name': 'GOLEM base module for global dependencies', 'summary': 'GOLEM base installs base and shared dependencies for GOLEM', - 'version': '10.0.1.1.1', + 'version': '10.0.1.1.2', 'category': 'GOLEM', 'author': 'Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/golem_base/models/ir_mail_server.py b/golem_base/models/ir_mail_server.py index 3a62904..301f9c6 100644 --- a/golem_base/models/ir_mail_server.py +++ b/golem_base/models/ir_mail_server.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2018 Fabien Bourgeois +# Copyright 2018-2020 Fabien Bourgeois # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -21,8 +21,27 @@ from odoo import models, fields class IrMailServer(models.Model): - """IR Mail Server fix for >64 characters pass """ + """ IR Mail Server adaptations """ _inherit = 'ir.mail_server' + # IR Mail Server fix for >64 characters pass smtp_user = fields.Char(size=100) smtp_pass = fields.Char(size=100) + + def build_email(self, email_from, email_to, subject, body, email_cc=None, + email_bcc=None, reply_to=False, attachments=None, + message_id=None, references=None, object_id=False, + subtype='plain', headers=None, body_alternative=None, + subtype_alternative='plain'): + """ Overwrite to supercharge from_to """ + get_param = self.env['ir.config_parameter'].sudo().get_param + force_email_from = get_param('mail.force.email_from', email_from) + if force_email_from != email_from: + email_from = force_email_from + reply_to = force_email_from + msg = super(IrMailServer, self).build_email( + email_from, email_to, subject, body, email_cc, email_bcc, + reply_to, attachments, message_id, references, object_id, subtype, + headers, body_alternative, subtype_alternative + ) + return msg