[FIX] mail: let auto_subscribe use up-to-date values
`_message_auto_subscribe` relies on `_get_subscription_data` to know who is subscribed to what. This method uses a raw SQL query but doesn't flush the relevant records beforehand. This is not an issue in most normal cases, but if followers are edited manually for example in order to merge existing records. It may cause issues when assigning a user to the record after merging, as the this will attempt to add them to the list of followers automatically, when they already were on it. task-3713472 original issue in opw-3634410 closes odoo/odoo#155139 X-original-commit: d1b0e46f7d3034c400ba3c60f343c21c68aa011e Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Renaud Thiry (reth) <reth@odoo.com>
This commit is contained in:
@@ -167,7 +167,7 @@ class TestLeadConvertMass(crm_common.TestLeadConvertMassCommon):
|
||||
user_ids = self.assign_users.ids
|
||||
|
||||
# randomness: at least 1 query
|
||||
with self.assertQueryCount(user_sales_manager=1801): # crm 1503 / com 1790 / ent 1800
|
||||
with self.assertQueryCount(user_sales_manager=1802): # crm 1481 / com 1794 / ent 1802
|
||||
mass_convert = self.env['crm.lead2opportunity.partner.mass'].with_context({
|
||||
'active_model': 'crm.lead',
|
||||
'active_ids': test_leads.ids,
|
||||
|
||||
@@ -349,6 +349,8 @@ class Followers(models.Model):
|
||||
share status of partner (returned only if include_pshare is True)
|
||||
active flag status of partner (returned only if include_active is True)
|
||||
"""
|
||||
self.env['mail.followers'].flush_model(['partner_id', 'res_id', 'res_model', 'subtype_ids'])
|
||||
self.env['res.partner'].flush_model(['active', 'partner_share'])
|
||||
# base query: fetch followers of given documents
|
||||
where_clause = ' OR '.join(['fol.res_model = %s AND fol.res_id IN %s'] * len(doc_data))
|
||||
where_params = list(itertools.chain.from_iterable((rm, tuple(rids)) for rm, rids in doc_data))
|
||||
|
||||
@@ -248,6 +248,21 @@ class BaseFollowersTest(MailCommon):
|
||||
self.assertEqual(document.message_follower_ids.partner_id, self.env.user.partner_id)
|
||||
self.assertEqual(document.message_follower_ids.subtype_ids, self.default_group_subtypes)
|
||||
|
||||
@users('employee')
|
||||
def test_subscriptions_data_fetch(self):
|
||||
""" Test that _get_subscription_data gives correct values when modifying followers manually."""
|
||||
test_record = self.test_record
|
||||
test_record_copy = self.test_record.copy()
|
||||
test_records = test_record + test_record_copy
|
||||
test_record.message_subscribe([self.user_employee.partner_id.id])
|
||||
subscription_data = self.env['mail.followers']._get_subscription_data([(test_records._name, test_records.ids)], None)
|
||||
self.assertEqual(len(subscription_data), 1)
|
||||
self.assertEqual(subscription_data[0][1], test_record.id)
|
||||
self.env['mail.followers'].browse(subscription_data[0][0]).sudo().res_id = test_record_copy
|
||||
subscription_data = self.env['mail.followers']._get_subscription_data([(test_records._name, test_records.ids)], None)
|
||||
self.assertEqual(len(subscription_data), 1)
|
||||
self.assertEqual(subscription_data[0][1], test_record_copy.id)
|
||||
|
||||
|
||||
@tagged('mail_followers')
|
||||
class AdvancedFollowersTest(MailCommon):
|
||||
|
||||
Reference in New Issue
Block a user