Skip to content
Browse files

some cleaning

  • Loading branch information...
Xavier-Do committed Mar 22, 2019
1 parent b0177ff commit 5e7176f3f91715502f831be646f2317b97f0aefd
Showing with 24 additions and 22 deletions.
  1. +24 −22 addons/mail/models/
@@ -273,12 +273,14 @@ def create(self, vals_list):
threads = super(MailThread, self).create(vals_list)

# auto_subscribe: take values and defaults into account
create_values_list = {}
for thread, values in zip(threads, vals_list):
create_values = dict(values)
for key, val in self._context.items():
if key.startswith('default_') and key[8:] not in create_values:
create_values[key[8:]] = val
create_values_list[] = create_values

# automatic logging unless asked not to (mainly for various testing purpose)
if not self._context.get('mail_create_nolog'):
@@ -291,31 +293,25 @@ def create(self, vals_list):
thread._message_log(body=body) # todo optimise email_from

# post track template if a tracked field changed
if not self._context.get('mail_notrack'):
if 'lang' not in self._context:
track_threads = threads.with_context(lang=self.env.user.lang)
track_threads = threads
for thread, values in zip(track_threads, vals_list):
changes = set(key for (key, value) in values.items() if value)
track_threads = threads.with_lang()
for thread in track_threads:
create_values = create_values_list[]
tracked_fields = self._get_tracked_fields(list(create_values))
changes = [field for field in tracked_fields if create_values.get(field)] # based on tracked field to stay consistent with write

return threads

def _creation_subtype(self):
return False

def write(self, values):
if self._context.get('tracking_disable'):
return super(MailThread, self).write(values)

# Track initial values of tracked fields
if 'lang' not in self._context:
track_self = self.with_context(lang=self.env.user.lang)
track_self = self

track_self = self.with_lang()

tracked_fields = None
if not self._context.get('mail_notrack'):
tracked_fields = track_self._get_tracked_fields(list(values))
@@ -431,6 +427,11 @@ def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu
# Technical methods / wrappers / tools
# ------------------------------------------------------

def with_lang(self):
if 'lang' not in self._context:
return self.with_context(lang=self.env.user.lang)
return self

def _replace_local_links(self, html, base_url=None):
""" Replace local links by absolute links. It is required in various
cases, for example when sending emails on chatter or sending mass
@@ -562,13 +563,17 @@ def _get_tracked_fields(self, updated_fields):
return self.fields_get(tracked_fields)
return {}

def _creation_subtype(self):
""" Give the subtypes triggered by the creation of a record
:returns: a subtype browse record or False if no subtype is trigerred

def _track_subtype(self, init_values):
""" Give the subtypes triggered by the changes on the record according
to values that have been updated.
:param ids: list of a single ID, the ID of the record being modified
:type ids: singleton list
:param init_values: the original values of the record; only modified fields
are present in the dict
:type init_values: dict
@@ -608,7 +613,7 @@ def _message_track(self, tracked_fields, initial):
# generate tracked_values data structure: {'col_name': {col_info, new_value, old_value}}
for col_name, col_info in tracked_fields.items():
initial_value = initial[col_name]
new_value = getattr(self, col_name)
new_value = self[col_name]

if new_value != initial_value and (new_value or initial_value): # because browse null != False
tracking_sequence = getattr(self._fields[col_name], 'tracking',
@@ -618,9 +623,7 @@ def _message_track(self, tracked_fields, initial):
tracking = self.env['mail.tracking.value'].create_tracking_values(initial_value, new_value, col_name, col_info, tracking_sequence)
if tracking:
tracking_value_ids.append([0, 0, tracking])

if col_name in tracked_fields:

return changes, tracking_value_ids

@@ -744,8 +747,7 @@ def _notify_classify_recipients(self, message, recipient_data):
access_link = self._notify_get_action_link('view')

if message.model:
model = self.env['ir.model'].with_context(
lang=self.env.context.get('lang', self.env.user.lang))
model = self.with_lang().env['ir.model']
model_name = model._get(message.model).display_name
view_title = _('View %s') % model_name

0 comments on commit 5e7176f

Please sign in to comment.
You can’t perform that action at this time.