Track_visibility field parameter allows to track field changes in mail. Since commit https://github.com/odoo/odoo/commit/c99de4551583e801ecc6669ac456c4f7e2eef1da only updated values are tracked. Previously to that commit it was possible to have field values being tracked whenever any other change occurred. This feature has been removed to simplify tracking and avoid having unnecessary values in the tracking table. In this commit we rename the track_visibility parameter to tracking. Old parameter value is still supported in mail for backward compatibility. Commit https://github.com/odoo/odoo/commit/ec35eca7c6b772139c8fa143b388ad1d936bc9ea added sequence on tracking so that display of tracking values is coherent through various chatter messages. To ease tracking configuration it is merged with the tracking (old track_visibility) parameter. It means tracking parameter can either be True (default sequence of 100) or an integer giving the sequence to apply on the tracking. Purpose of those changes is to simplify tracking configuration with studio in mind. That way changing one parameter allow to customize the tracking of fields in chatter. Sequence field on mail.tracking.value model is renamed to tracking_sequence to have a coherent namespace for tracking information. Tracking information on ir.model.fields is also updated accordingly. To simplify manipulation boolean value for tracking is automatically transformed into a sequence of 100. This commit is linked to task ID 1903814 and PR #28430.
111 lines
5.0 KiB
Python
111 lines
5.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from datetime import datetime
|
|
|
|
from odoo import api, fields, models, tools
|
|
|
|
|
|
class MailTracking(models.Model):
|
|
_name = 'mail.tracking.value'
|
|
_description = 'Mail Tracking Value'
|
|
_rec_name = 'field'
|
|
_order = 'tracking_sequence asc'
|
|
|
|
# TDE CLEANME: why not a m2o to ir model field ?
|
|
field = fields.Char('Changed Field', required=True, readonly=1)
|
|
field_desc = fields.Char('Field Description', required=True, readonly=1)
|
|
field_type = fields.Char('Field Type')
|
|
|
|
old_value_integer = fields.Integer('Old Value Integer', readonly=1)
|
|
old_value_float = fields.Float('Old Value Float', readonly=1)
|
|
old_value_monetary = fields.Float('Old Value Monetary', readonly=1)
|
|
old_value_char = fields.Char('Old Value Char', readonly=1)
|
|
old_value_text = fields.Text('Old Value Text', readonly=1)
|
|
old_value_datetime = fields.Datetime('Old Value DateTime', readonly=1)
|
|
|
|
new_value_integer = fields.Integer('New Value Integer', readonly=1)
|
|
new_value_float = fields.Float('New Value Float', readonly=1)
|
|
new_value_monetary = fields.Float('New Value Monetary', readonly=1)
|
|
new_value_char = fields.Char('New Value Char', readonly=1)
|
|
new_value_text = fields.Text('New Value Text', readonly=1)
|
|
new_value_datetime = fields.Datetime('New Value Datetime', readonly=1)
|
|
|
|
mail_message_id = fields.Many2one('mail.message', 'Message ID', required=True, index=True, ondelete='cascade')
|
|
|
|
tracking_sequence = fields.Integer('Tracking field sequence', readonly=1, default=100, oldname='track_sequence')
|
|
|
|
@api.model
|
|
def create_tracking_values(self, initial_value, new_value, col_name, col_info, tracking_sequence):
|
|
tracked = True
|
|
values = {'field': col_name, 'field_desc': col_info['string'], 'field_type': col_info['type'], 'tracking_sequence': tracking_sequence}
|
|
|
|
if col_info['type'] in ['integer', 'float', 'char', 'text', 'datetime', 'monetary']:
|
|
values.update({
|
|
'old_value_%s' % col_info['type']: initial_value,
|
|
'new_value_%s' % col_info['type']: new_value
|
|
})
|
|
elif col_info['type'] == 'date':
|
|
values.update({
|
|
'old_value_datetime': initial_value and fields.Datetime.to_string(datetime.combine(fields.Date.from_string(initial_value), datetime.min.time())) or False,
|
|
'new_value_datetime': new_value and fields.Datetime.to_string(datetime.combine(fields.Date.from_string(new_value), datetime.min.time())) or False,
|
|
})
|
|
elif col_info['type'] == 'boolean':
|
|
values.update({
|
|
'old_value_integer': initial_value,
|
|
'new_value_integer': new_value
|
|
})
|
|
elif col_info['type'] == 'selection':
|
|
values.update({
|
|
'old_value_char': initial_value and dict(col_info['selection'])[initial_value] or '',
|
|
'new_value_char': new_value and dict(col_info['selection'])[new_value] or ''
|
|
})
|
|
elif col_info['type'] == 'many2one':
|
|
values.update({
|
|
'old_value_integer': initial_value and initial_value.id or 0,
|
|
'new_value_integer': new_value and new_value.id or 0,
|
|
'old_value_char': initial_value and initial_value.sudo().name_get()[0][1] or '',
|
|
'new_value_char': new_value and new_value.sudo().name_get()[0][1] or ''
|
|
})
|
|
else:
|
|
tracked = False
|
|
|
|
if tracked:
|
|
return values
|
|
return {}
|
|
|
|
@api.multi
|
|
def get_display_value(self, type):
|
|
assert type in ('new', 'old')
|
|
result = []
|
|
for record in self:
|
|
if record.field_type in ['integer', 'float', 'char', 'text', 'monetary']:
|
|
result.append(getattr(record, '%s_value_%s' % (type, record.field_type)))
|
|
elif record.field_type == 'datetime':
|
|
if record['%s_value_datetime' % type]:
|
|
new_datetime = getattr(record, '%s_value_datetime' % type)
|
|
result.append('%sZ' % new_datetime)
|
|
else:
|
|
result.append(record['%s_value_datetime' % type])
|
|
elif record.field_type == 'date':
|
|
if record['%s_value_datetime' % type]:
|
|
new_date = record['%s_value_datetime' % type]
|
|
result.append(fields.Date.to_string(new_date))
|
|
else:
|
|
result.append(record['%s_value_datetime' % type])
|
|
elif record.field_type == 'boolean':
|
|
result.append(bool(record['%s_value_integer' % type]))
|
|
else:
|
|
result.append(record['%s_value_char' % type])
|
|
return result
|
|
|
|
@api.multi
|
|
def get_old_display_value(self):
|
|
# grep : # old_value_integer | old_value_datetime | old_value_char
|
|
return self.get_display_value('old')
|
|
|
|
@api.multi
|
|
def get_new_display_value(self):
|
|
# grep : # new_value_integer | new_value_datetime | new_value_char
|
|
return self.get_display_value('new')
|