diff options
| author | Toufik Benjaa <tbe@odoo.com> | 2018-08-21 15:39:16 +0200 |
|---|---|---|
| committer | Toufik Benjaa <tbe@odoo.com> | 2018-09-05 18:36:54 +0200 |
| commit | 7700bd172f790858fb4cb9e64b90c9c77d9e5b0a (patch) | |
| tree | 7e64eefa1a1306ea32aaad5dace0b86053e2e072 | |
| parent | 0f3281e3b1dc943b81d79d2a8f82fca7b95b8186 (diff) | |
[FIX] mail: Avoid using default value for track fields logging
- When a tracked field is modified, a mail.message is created.
When create is called its tries to fill missing values with "default
values".
It first tries to find the default values in the context, which may
occurs.
For example, modifying a tracked field on a subtask will add a key
"default_parent_id" in the context, which is the parent_id of the project.task.
Create will try to use "default_parent_id" for the mail.message
parent_id field, which make the SQL Request invalid.
| -rw-r--r-- | addons/mail/models/mail_thread.py | 3 | ||||
| -rw-r--r-- | odoo/models.py | 14 | ||||
| -rw-r--r-- | odoo/tools/misc.py | 4 |
3 files changed, 9 insertions, 12 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 47d3a74734d..49ef44e35ae 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -27,6 +27,7 @@ from werkzeug import urls from odoo import _, api, exceptions, fields, models, tools from odoo.tools import pycompat, ustr +from odoo.tools.misc import clean_context from odoo.tools.safe_eval import safe_eval @@ -280,7 +281,7 @@ class MailThread(models.AbstractModel): # Perform the tracking if tracked_fields: - track_self.message_track(tracked_fields, initial_values) + track_self.with_context(clean_context(self._context)).message_track(tracked_fields, initial_values) return result diff --git a/odoo/models.py b/odoo/models.py index 5e6344847ab..e32b35a5870 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -55,7 +55,7 @@ from .tools import frozendict, lazy_classproperty, lazy_property, ormcache, \ Collector, LastOrderedSet, OrderedSet, pycompat, groupby from .tools.config import config from .tools.func import frame_codeinfo -from .tools.misc import CountingStream, DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT +from .tools.misc import CountingStream, clean_context, DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT from .tools.safe_eval import safe_eval from .tools.translate import _ @@ -3232,11 +3232,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): # set the value of non-column fields if other_fields: # discard default values from context - other = self.with_context({ - key: val - for key, val in self._context.items() - if not key.startswith('default_') - }) + other = self.with_context(clean_context(self._context)) for field in sorted(other_fields, key=attrgetter('_sequence')): field.write(other, vals[field.name]) @@ -3404,11 +3400,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): # set the value of non-column fields if other_fields: # discard default values from context - other = self.with_context({ - key: val - for key, val in self._context.items() - if not key.startswith('default_') - }) + other = self.with_context(clean_context(self._context)) for field in sorted(other_fields, key=attrgetter('_sequence')): field.write(other, vals[field.name], create=True) diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 8a33558c790..762c07e535c 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -960,6 +960,10 @@ def freehash(arg): else: return id(arg) +def clean_context(context): + """ This function take a dictionary and remove each entry with its key starting with 'default_' """ + return {k: v for k, v in context.items() if not k.startswith('default_')} + class frozendict(dict): """ An implementation of an immutable dictionary. """ def __delitem__(self, key): |
