OCA / server-env

Tools to manage environment-dependent configuration
GNU Affero General Public License v3.0
56 stars 149 forks source link

mail_environment and microsoft_outlook incompatibility. #162

Closed florian-dacosta closed 6 months ago

florian-dacosta commented 1 year ago

I only have tested with version 16 but it probably impacts all versions.

If both mail_environment and microsoft_outlook are installed, it is impossible to create an outgoing mail server with smtp_authentication = 'outlook', unless you manage the environment dependent fields in your Odoo config files. (So it does not work with default value or data_encryption_server_environment module)

During the creation, you will have a failure due to this constraints : https://github.com/OCA/OCB/blob/16.0/addons/microsoft_outlook/models/ir_mail_server.py#L46 The reason is, Odoo will check these constraint before the default environement value is set. Constraints are checked there https://github.com/OCA/OCB/blob/16.0/odoo/models.py#L4206 while the not stored fields with inverse method (which is the case of the environment dependent fields) are managed later on in the create method. During the constraint check, the value will always be False (unless defined in config file)

So, the source of the problem is the fact that server_environment some stored fields to not stored /computed fields. Actually, I think I already met issues with server_environment because of this, I think required field are not anymore, fields no more searchable, stuff like that.

Anyway, I have no perfect solution about this issue. For now, I intent to fix it for microsoft_outlook with the following :

class IrMailServer(models.Model):
    _inherit = "ir.mail_server"

    @api.model_create_multi
    def create(self, vals_list):
        res = super(IrMailServer, self.with_context(delay_field_validation=True)).create(vals_list)
        res.with_context(delay_field_validation=False)._validate_fields(name for vals in vals_list for name in vals)
        return res

    def _validate_fields(self, field_names, excluded_names=()):
        if self.env.context.get("delay_field_validation"):
            return
        return super()._validate_fields(field_names, excluded_names=excluded_names)

It seems good enough to me and not too dangerous because specific to the constraints of ir.mail_server

I wonder if anyone would have a better idea and/or if it was good enough to go to mail_environment_office365 module.

I guess the problem from this issue is the same as spotted here : https://github.com/OCA/server-env/pull/119#issuecomment-1407195170 Even though I did not experience this one.

Any feedback is appreciated @JordiBForgeFlow @simahawk @lmignon @StefanRijnhart

github-actions[bot] commented 7 months ago

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.