runbot/runbot_merge/models/mail_thread.py
Xavier Morel aa1df22657 [MERGE] bot from 16.0 to 17.0
Broken (can't run odoo at all):

- In Odoo 17.0, the `pre_init_hook` takes an env, not a cursor, update
  `_check_citext`.
- Odoo 17.0 rejects `@attrs` and doesn't say where they are or how to
  update them, fun, hunt down `attrs={'invisible': ...` and try to fix
  them.
- Odoo 17.0 warns on non-multi creates, update them, most were very
  reasonable, one very wasn't.

Test failures:

- Odoo 17.0 deprecates `name_get` and doesn't use it as a *source*
  anymore, replace overrides by overrides to `_compute_display_name`.
- Multiple tracking changes:
  - `_track_set_author` takes a `Partner` not an id.
  - `_message_compute_author` still requires overriding in order to
    handle record creation, which in standard doesn't support author
    overriding.
  - `mail.tracking.value.field_type` has been removed, the field type
    now needs to be retrieved from the `field_id`.
  - Some tracking ordering have changed and require adjusting a few
    tests.

Also added a few flushes before SQL queries which are not (obviously
at least) at the start of a cron or controller, no test failure
observed but better safe than sorry (probably).
2024-08-12 13:13:03 +02:00

34 lines
1.3 KiB
Python

from collections import ChainMap
from odoo import models
from odoo.tools import ConstantMapping
class MailThread(models.AbstractModel):
_inherit = 'mail.thread'
def _message_compute_author(self, author_id=None, email_from=None, raise_on_email=True):
if author_id is None and self:
mta = self.env.cr.precommit.data.get(f'mail.tracking.author.{self._name}', {})
authors = self.env['res.partner'].union(*(p for r in self if (p := mta.get(r.id))))
if len(authors) == 1:
author_id = authors.id
v = super()._message_compute_author(author_id, email_from, raise_on_email)
return v
def _track_set_author(self, author, *, fallback=False):
""" Set the author of the tracking message. """
if not self._track_get_fields():
return
authors = self.env.cr.precommit.data.setdefault(f'mail.tracking.author.{self._name}', {})
if fallback:
details = authors
if isinstance(authors, ChainMap):
details = authors.maps[0]
self.env.cr.precommit.data[f'mail.tracking.author.{self._name}'] = ChainMap(
details,
ConstantMapping(author),
)
else:
return super()._track_set_author(author)