From 69209ae4bf22dbe55c3ec14ea734963d1d4b6d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 18 Jan 2023 14:42:16 +0000 Subject: [PATCH] [MOV] (mass_)mail(_ing): move 'model_is_thread' field to mail This field will be used to remove low-level asserts using existence of 'message_post' on a given model instead of correctly checking the inheritance on mail.thread. This is going to increase a bit query counters but those queries should be fast and have no real impact on performances. Task-2088884 (Mail: Use editable computed stored fields in composer) Part-of: odoo/odoo#107356 --- addons/mail/wizard/mail_compose_message.py | 8 ++++++++ addons/mail/wizard/mail_compose_message_views.xml | 1 + addons/mass_mailing/wizard/mail_compose_message.py | 9 +-------- .../mass_mailing/wizard/mail_compose_message_views.xml | 1 - 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 9ffbfd42276..b32c39ed554 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -149,6 +149,7 @@ class MailComposer(models.TransientModel): composition_batch = fields.Boolean( 'Batch composition', compute='_compute_composition_batch') # more than 1 record (raw source) model = fields.Char('Related Document Model') + model_is_thread = fields.Boolean('Thread-Enabled', compute='_compute_model_is_thread') res_ids = fields.Text('Related Document IDs') res_domain = fields.Text('Active domain') res_domain_user_id = fields.Many2one( @@ -227,6 +228,13 @@ class MailComposer(models.TransientModel): res_ids = composer._evaluate_res_ids() composer.composition_batch = len(res_ids) > 1 if res_ids else False + @api.depends('model') + def _compute_model_is_thread(self): + """ Determine if model is thread enabled. """ + for composer in self: + model = self.env['ir.model']._get(composer.model) + composer.model_is_thread = model.is_mail_thread + @api.depends('subtype_id') def _compute_subtype_is_log(self): """ In comment mode, tells whether the subtype is a note. Subtype has diff --git a/addons/mail/wizard/mail_compose_message_views.xml b/addons/mail/wizard/mail_compose_message_views.xml index 0419c1ab393..2ab4ea3cc49 100644 --- a/addons/mail/wizard/mail_compose_message_views.xml +++ b/addons/mail/wizard/mail_compose_message_views.xml @@ -19,6 +19,7 @@ + diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py index c522ee8d07a..70bc9d72c40 100644 --- a/addons/mass_mailing/wizard/mail_compose_message.py +++ b/addons/mass_mailing/wizard/mail_compose_message.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models +from odoo import fields, models class MailComposeMessage(models.TransientModel): @@ -11,13 +11,6 @@ class MailComposeMessage(models.TransientModel): campaign_id = fields.Many2one('utm.campaign', string='Mass Mailing Campaign', ondelete='set null') mass_mailing_name = fields.Char(string='Mass Mailing Name', help='If set, a mass mailing will be created so that you can track its results in the Email Marketing app.') mailing_list_ids = fields.Many2many('mailing.list', string='Mailing List') - model_is_thread = fields.Boolean(compute='_compute_model_is_thread') - - @api.depends('model') - def _compute_model_is_thread(self): - for composer in self: - model = self.env['ir.model']._get(composer.model) - composer.model_is_thread = model.is_mail_thread def _action_send_mail(self, auto_commit=False): """ Override to generate the mass mailing in case only the name was diff --git a/addons/mass_mailing/wizard/mail_compose_message_views.xml b/addons/mass_mailing/wizard/mail_compose_message_views.xml index 3f42753d1a9..b4111a23f66 100644 --- a/addons/mass_mailing/wizard/mail_compose_message_views.xml +++ b/addons/mass_mailing/wizard/mail_compose_message_views.xml @@ -8,7 +8,6 @@ -