odoo 12.0 track_visibility = 'always' 无效

  • 原因

    • odoo12.0 对属性track_visibility 只做了非False判断, 也就是说track_visibility 属性不写False, 或者不定义这个属性,其他都为onchange
      • if getattr(field, 'track_visibility', False):
  • 解决方法修改addons/mail/models/mail_thread.py的_message_track方法为

def _message_track(self, tracked_fields, initial):
    """ For a given record, fields to check (tuple column name, column info)
    and initial values, return a structure that is a tuple containing :

        - a set of updated column names
        - a list of changes (initial value, new value, column name, column info) """
    self.ensure_one()
    changes = set()  # contains always and onchange tracked fields that changed
    displays = set()  # contains always tracked field that did not change but displayed for information
    tracking_value_ids = []
    display_values_ids = []

    # generate tracked_values data structure: {'col_name': {col_info, new_value, old_value}}
    for col_name, col_info in tracked_fields.items():
        track_visibility = getattr(self._fields[col_name], 'track_visibility', 'onchange')
        initial_value = initial[col_name]
        new_value = getattr(self, col_name)

        if new_value != initial_value and (new_value or initial_value):  # because browse null != False
            track_sequence = getattr(self._fields[col_name], 'track_sequence', 100)
            tracking = self.env['mail.tracking.value'].create_tracking_values(initial_value, new_value, col_name,
                                                                                col_info, track_sequence)
            if tracking:
                tracking_value_ids.append([0, 0, tracking])

            if col_name in tracked_fields:
                changes.add(col_name)
        # 'always' tracked fields in separate variable; added if other changes
        elif new_value == initial_value and track_visibility == 'always' and col_name in tracked_fields:
            track_sequence = getattr(self._fields[col_name], 'track_sequence', 100)
            tracking = self.env['mail.tracking.value'].create_tracking_values(initial_value, new_value, col_name,
                                                                                col_info, track_sequence)
            if tracking:
                display_values_ids.append([0, 0, tracking])
                displays.add(col_name)

    if changes and displays:
        tracking_value_ids = display_values_ids + tracking_value_ids

    return changes, tracking_value_ids
posted @ 2019-08-30 13:51  twfb  阅读(979)  评论(0编辑  收藏  举报