Conversation
a606c6b to
71dd976
Compare
71dd976 to
4f23ee2
Compare
…d add OU mail server routing
4f23ee2 to
d38676f
Compare
| a configured outgoing mail server, use it. | ||
| If the record has ``operating_unit_ids`` and all operating units | ||
| share the same outgoing mail server, use that server. | ||
| Otherwise return `False`. |
There was a problem hiding this comment.
| Otherwise return `False`. | |
| Otherwise, try to use the one of the operating unit the current user is logged on. |
In case records have different mail servers, perhaps we should use the one linked to the currently logged company/operating unit, by calling the method res.users._get_default_operating_unit.
Because, if a record has multiple operating_unit_ids, it just means it's available on all of them.. but the currently active company (and thus, active operating unit) is the one that matters IMO.
There was a problem hiding this comment.
Makes sense. It was originally designed to return False for the mail alias domain, so I decided to follow the idea.
| Otherwise return `False`. | ||
| """ | ||
| record.ensure_one() | ||
| if "operating_unit_id" in record and record.operating_unit_id: |
There was a problem hiding this comment.
record._fields instead
There was a problem hiding this comment.
NOTE: There are other cases like this
| email_values=None, | ||
| email_layout_xmlid=False, | ||
| ): | ||
| # OVERRIDE: to allow routing outgoing mail server from the operating unit. |
There was a problem hiding this comment.
We should exhaust all options before going for a complete overwrite of this method. It will be a pain to maintain in the long run.
Have you checked how the mail_outbound_static module handles this? I think it may apply in this case, too: https://github.com/OCA/social/blob/17.0/mail_outbound_static/models/ir_mail_server.py#L112
At that stage, you may be able to grab a reference to the record linked to the message (perhaps through the message['object_id']), and derive the mail server from there.
There was a problem hiding this comment.
Yep, I know we should avoid that.
I didn't find any other way so far to change the mail_server_id before mail is actually sent.
I'll check your suggestion.
Thanks for the review.
| email_layout_xmlid=email_layout_xmlid, | ||
| ) | ||
|
|
||
| def _is_operating_unit_use_mail_server_enabled(self): |
There was a problem hiding this comment.
IMHO this settings is useless.
It should always attempt to do this.
Users can decide whether to enable/disable this feature by simply not configuring any mail_server_id in their operating units.
There was a problem hiding this comment.
This feature is requested in the BA specifications 😄
I agree we can just decide by the mail_server_id set on the OU.
This PR extends
mail_operating_unitin two ways.First, it adds support for records using
operating_unit_idsin addition tooperating_unit_id. When amail.threadrecord has exactly one operating unit inoperating_unit_idsand this operating unit has an alias domain, the module now uses that alias domain for mail generation. This covers models such asres.partner, which store operating units on a many2many field and are used by reminder emails. The existing behavior foroperating_unit_idremains unchanged.Second, it adds optional outgoing mail server routing based on the operating unit. When enabled in
General Settings, and when no outgoing mail server is explicitly defined on the email template, the module selects the mail server from the target record:operating_unit_idwhen it has a configured mail server;operating_unit_idswhen all operating units share the same mail server.This allows emails such as reminders or invoices to be routed automatically through the proper SMTP server for each operating unit, while preserving template priority and falling back to standard Odoo behavior when no unambiguous operating-unit configuration can be determined.