首页 > 其他 > 详细

odoo 如何设置字段变更跟踪

时间:2021-07-05 15:28:34      阅读:15      评论:0      收藏:0      [点我收藏+]

且看源码:

    @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 的一系列模型

odoo 如何设置字段变更跟踪

原文:https://www.cnblogs.com/qianxunman/p/14971295.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!