[FIX] mail: allow tracking values not loaded into registry
Use dict.get() instead of a subscriptable call. This way we let through selection values that are not loaded into the registry, instead of raising an error. This is especially useful in the upgrade environment where such values may be unavailable (because of being lambda-defined in a custom module for instance). closes odoo/odoo#94530 X-original-commit: 36a6943740f9b4fbd9a78986bee4cd84bb8469c7 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Thibault Delavallée
parent
ad5b2a277b
commit
cb07db6e41
@@ -71,7 +71,7 @@ class MailTracking(models.Model):
|
||||
})
|
||||
elif col_info['type'] == 'selection':
|
||||
values.update({
|
||||
'old_value_char': initial_value and dict(col_info['selection'])[initial_value] or '',
|
||||
'old_value_char': initial_value and dict(col_info['selection']).get(initial_value, initial_value) or '',
|
||||
'new_value_char': new_value and dict(col_info['selection'])[new_value] or ''
|
||||
})
|
||||
elif col_info['type'] == 'many2one':
|
||||
|
||||
@@ -105,6 +105,16 @@ class MailTestTrackMonetary(models.Model):
|
||||
revenue = fields.Monetary('Revenue', currency_field='company_currency', tracking=True)
|
||||
|
||||
|
||||
class MailTestSelectionTracking(models.Model):
|
||||
""" Test tracking for selection fields """
|
||||
_description = 'Test Selection Tracking'
|
||||
_name = 'mail.test.track.selection'
|
||||
_inherit = ['mail.thread']
|
||||
|
||||
name = fields.Char()
|
||||
selection_type = fields.Selection([('first', 'First'), ('second', 'Second')], tracking=True)
|
||||
|
||||
|
||||
class MailTestTrackAll(models.Model):
|
||||
_name = 'mail.test.track.all'
|
||||
_description = 'Test tracking on all field types'
|
||||
|
||||
@@ -31,6 +31,8 @@ access_mail_test_multi_company_user,mail.test.multi.company.user,model_mail_test
|
||||
access_mail_test_multi_company_portal,mail.test.multi.company.portal,model_mail_test_multi_company,base.group_portal,1,0,0,0
|
||||
access_mail_test_nothread_user,mail.test.nothread.user,model_mail_test_nothread,base.group_user,1,1,1,1
|
||||
access_mail_test_nothread_portal,mail.test.nothread.portal,model_mail_test_nothread,base.group_portal,1,0,0,0
|
||||
access_mail_test_track_all,mail.test.track.all,model_mail_test_track_all,base.group_user,1,1,1,1
|
||||
access_mail_test_track_compute,mail.test.track.compute,model_mail_test_track_compute,base.group_user,1,1,1,1
|
||||
access_mail_test_track_monetary,mail.test.track.monetary,model_mail_test_track_monetary,base.group_user,1,1,1,1
|
||||
access_mail_test_track_all,mail.test.track.all,model_mail_test_track_all,base.group_user,1,1,1,1
|
||||
access_mail_test_track_selection_portal,mail.test.track.selection.portal,model_mail_test_track_selection,base.group_portal,0,0,0,0
|
||||
access_mail_test_track_selection_user,mail.test.track.selection.user,model_mail_test_track_selection,base.group_user,1,1,1,1
|
||||
|
||||
|
@@ -165,6 +165,37 @@ class TestTracking(TestMailCommon):
|
||||
self.assertTrue(new_partner)
|
||||
self.assertEqual(new_partner.company_id, company1)
|
||||
|
||||
def test_track_invalid_selection(self):
|
||||
# Test: Check that initial invalid selection values are allowed when tracking
|
||||
# Create a record with an initially invalid selection value
|
||||
invalid_value = 'I love writing tests!'
|
||||
record = self.env['mail.test.track.selection'].create({
|
||||
'name': 'Test Invalid Selection Values',
|
||||
'selection_type': 'first',
|
||||
})
|
||||
|
||||
self.flush_tracking()
|
||||
self.env.cr.execute(
|
||||
"""
|
||||
UPDATE mail_test_track_selection
|
||||
SET selection_type = %s
|
||||
WHERE id = %s
|
||||
""",
|
||||
[invalid_value, record.id]
|
||||
)
|
||||
|
||||
record.invalidate_recordset()
|
||||
|
||||
self.assertEqual(record.selection_type, invalid_value)
|
||||
|
||||
# Write a valid selection value
|
||||
record.selection_type = "second"
|
||||
|
||||
self.flush_tracking()
|
||||
self.assertTracking(record.message_ids, [
|
||||
('selection_type', 'char', invalid_value, 'Second'),
|
||||
])
|
||||
|
||||
def test_track_template(self):
|
||||
# Test: Check that default_* keys are not taken into account in _message_track_post_template
|
||||
magic_code = 'Up-Up-Down-Down-Left-Right-Left-Right-Square-Triangle'
|
||||
|
||||
Reference in New Issue
Block a user