且看源码:

    @api.model
    def _get_tracked_fields(self, updated_fields):
        """ Return a structure of tracked fields for the current model.
            :param list updated_fields: modified field names
            :return dict: a dict mapping field name to description, containing on_change fields
        """
        tracked_fields = []
        for name, field in self._fields.items():
            if getattr(field, 'track_visibility', False):
                tracked_fields.append(name)

        if tracked_fields:
            return self.fields_get(tracked_fields)
        return {}

设置的关键字为track_visibility

源码设置实例:

    type = fields.Selection([
            ('out_invoice','Customer Invoice'),
            ('in_invoice','Vendor Bill'),
            ('out_refund','Customer Credit Note'),
            ('in_refund','Vendor Credit Note'),
        ], readonly=True, states={'draft': [('readonly', False)]}, index=True, change_default=True,
        default=lambda self: self._context.get('type', 'out_invoice'),
        track_visibility='always')

当然模型需要继承 mail 的一系列模型

相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2021-07-06
  • 2021-07-10
  • 2021-07-20
  • 2021-06-26
  • 2021-09-10
猜你喜欢
  • 2021-10-03
  • 2021-09-13
  • 2021-08-07
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案