odoo 12.0 track_visibility = 'always' 无效
-
原因
- odoo12.0 对属性track_visibility 只做了非False判断, 也就是说track_visibility 属性不写False, 或者不定义这个属性,其他都为onchange
if getattr(field, 'track_visibility', False):
- odoo12.0 对属性track_visibility 只做了非False判断, 也就是说track_visibility 属性不写False, 或者不定义这个属性,其他都为onchange
-
解决方法修改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
-
不过
- 我发现, 这个always和我想的用法不太一样, 他是只有在修改track_visibility为onchange的字段的值时才会记录, 也就是说, 当你修改没有设定track_visibility 的字段时, 不会记录always对应字段的值
-
啰啰嗦嗦
- 看源码发现问题后
- 就google了下
odoo addon mail mail_thread.py "always"
- 找到了不知啥版本的odoo
- 看了看,美滋滋, 对always做了判断
- 直接替换, 哪报错改哪, 完美