19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:39 +01:00
parent 38c6088dcc
commit d9452d2060
243 changed files with 30797 additions and 10815 deletions

View file

@ -2,13 +2,13 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.base.tests.test_ir_actions import TestServerActionsBase
from odoo.addons.test_mail.tests.common import TestMailCommon
from odoo.addons.mail.tests.common import MailCommon
from odoo.tests import tagged
from odoo.tools import mute_logger
@tagged('ir_actions')
class TestServerActionsEmail(TestMailCommon, TestServerActionsBase):
class TestServerActionsEmail(MailCommon, TestServerActionsBase):
def setUp(self):
super(TestServerActionsEmail, self).setUp()
@ -61,6 +61,17 @@ class TestServerActionsEmail(TestMailCommon, TestServerActionsBase):
self.action.with_context(self.context).run()
self.assertEqual(self.test_partner.message_partner_ids, self.env.ref('base.partner_admin') | random_partner)
def test_action_followers_warning(self):
self.test_partner.message_unsubscribe(self.test_partner.message_partner_ids.ids)
self.action.write({
'state': 'followers',
"followers_type": "generic",
"followers_partner_field_name": "user_id.name"
})
self.assertEqual(self.action.warning, "The field 'Salesperson > Name' is not a partner field.")
self.action.write({"followers_partner_field_name": "parent_id.child_ids"})
self.assertEqual(self.action.warning, False)
def test_action_message_post(self):
# initial state
self.assertEqual(len(self.test_partner.message_ids), 1,
@ -78,7 +89,10 @@ class TestServerActionsEmail(TestMailCommon, TestServerActionsBase):
with self.assertSinglePostNotifications(
[{'partner': self.test_partner, 'type': 'email', 'status': 'ready'}],
message_info={'content': 'Hello %s' % self.test_partner.name,
'message_type': 'notification',
'mail_mail_values': {
'author_id': self.env.user.partner_id,
},
'message_type': 'auto_comment',
'subtype': 'mail.mt_comment',
}
):
@ -95,7 +109,7 @@ class TestServerActionsEmail(TestMailCommon, TestServerActionsBase):
with self.assertSinglePostNotifications(
[{'partner': self.test_partner, 'type': 'email', 'status': 'ready'}],
message_info={'content': 'Hello %s' % self.test_partner.name,
'message_type': 'notification',
'message_type': 'auto_comment',
'subtype': 'mail.mt_note',
}
):
@ -117,6 +131,18 @@ class TestServerActionsEmail(TestMailCommon, TestServerActionsBase):
self.assertEqual(self.env['mail.activity'].search_count([]), before_count + 1)
self.assertEqual(self.env['mail.activity'].search_count([('summary', '=', 'TestNew')]), 1)
def test_action_next_activity_warning(self):
self.action.write({
'state': 'next_activity',
'activity_user_type': 'generic',
"activity_user_field_name": "user_id.name",
'activity_type_id': self.env.ref('mail.mail_activity_data_meeting').id,
'activity_summary': 'TestNew',
})
self.assertEqual(self.action.warning, "The field 'Salesperson > Name' is not a user field.")
self.action.write({"activity_user_field_name": "parent_id.user_id"})
self.assertEqual(self.action.warning, False)
def test_action_next_activity_due_date(self):
""" Make sure we don't crash if a due date is set without a type. """
self.action.write({
@ -132,3 +158,66 @@ class TestServerActionsEmail(TestMailCommon, TestServerActionsBase):
self.assertFalse(run_res, 'ir_actions_server: create next activity action correctly finished should return False')
self.assertEqual(self.env['mail.activity'].search_count([]), before_count + 1)
self.assertEqual(self.env['mail.activity'].search_count([('summary', '=', 'TestNew')]), 1)
def test_action_next_activity_from_x2m_user(self):
self.test_partner.user_ids = self.user_demo | self.user_admin
self.action.write({
'state': 'next_activity',
'activity_user_type': 'generic',
'activity_user_field_name': 'user_ids',
'activity_type_id': self.env.ref('mail.mail_activity_data_meeting').id,
'activity_summary': 'TestNew',
})
before_count = self.env['mail.activity'].search_count([])
run_res = self.action.with_context(self.context).run()
self.assertFalse(run_res, 'ir_actions_server: create next activity action correctly finished should return False')
self.assertEqual(self.env['mail.activity'].search_count([]), before_count + 1)
self.assertRecordValues(
self.env['mail.activity'].search([('res_model', '=', 'res.partner'), ('res_id', '=', self.test_partner.id)]),
[{
'summary': 'TestNew',
'user_id': self.user_demo.id, # the first user found
}],
)
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
def test_action_send_mail_without_mail_thread(self):
""" Check running a server action to send an email with custom layout on a non mail.thread model """
no_thread_record = self.env['mail.test.nothread'].create({'name': 'Test NoMailThread', 'customer_id': self.test_partner.id})
no_thread_template = self._create_template(
'mail.test.nothread',
{
'email_from': 'someone@example.com',
'partner_to': '{{ object.customer_id.id }}',
'subject': 'About {{ object.name }}',
'body_html': '<p>Hello <t t-out="object.name"/></p>',
'email_layout_xmlid': 'mail.mail_notification_layout',
}
)
# update action: send an email
self.action.write({
'mail_post_method': 'email',
'state': 'mail_post',
'model_id': self.env['ir.model'].search([('model', '=', 'mail.test.nothread')], limit=1).id,
'model_name': 'mail.test.nothread',
'template_id': no_thread_template.id,
})
with self.mock_mail_gateway(), self.mock_mail_app():
action_ctx = {
'active_model': 'mail.test.nothread',
'active_id': no_thread_record.id,
}
self.action.with_context(action_ctx).run()
mail = self.assertMailMail(
self.test_partner,
None,
content='Hello Test NoMailThread',
fields_values={
'email_from': 'someone@example.com',
'subject': 'About Test NoMailThread',
}
)
self.assertNotIn('Powered by', mail.body_html, 'Body should contain the notification layout')