View difference between Paste ID: EUqtz4eF and VRP0BNBt
SHOW: | | - or go back to the newest paste.
1
"""
2
Here is what I have done in my code to be able to bypass tracked messages when needed (say a wizard already generates a more specific summary message for changes)
3
4
Monkey patching is not the best tool, I think OpenERP shall provide this out of the box (or a similar way to do this).
5
"""
6
import logging
7
8
from openerp.addons.project import project
9
10
11
_logger = logging.getLogger(__name__)
12
13
14
NO_TRACK_KEY = '_message_no_tracking'
15
16
17
def patch_message_track(cls):
18
    """Modification of message tracking mecanism, to be able to inihbate it. 
19
20
    Some time we generate our own message, bundling different updates.
21
    In those very case we don't want automatic messages to be issued.
22
23
    The new method will look at the context for a _message_no_tracking entry
24
    which has to exists and be set to true to inhibate auto tracking.
25
    """
26
27
    original = cls.message_track
28
29
    def message_track(
30
            self, cr, uid, ids, tracked_fields, initial_values, context=None):
31
        if context is not None and context.get(NO_TRACK_KEY, False):
32
            # no tracking, pass
33
            _logger.debug(
34
                "Bypassing tracking for %s,%s as requested by context" %
35
                (cls._name, ids))
36
            pass
37
        else:
38
            original(
39
                self, cr, uid, ids, tracked_fields, initial_values, context)
40
41
    cls.message_track = original