当我存档记录时,相关字段会发生什么情况?

What happens to related fields when I archive a record?

Odoo - 所有版本

归档记录时,所有相关字段都将丢失。当我再次激活记录时,关系记录再次显示。

那些外键会怎样??是否可以在它仍处于非活动状态时获取关系记录?另外,是否可以覆盖存档功能。如果是,如何? 谢谢。

archiving-feature基于一个简单的布尔字段,用于从显示中过滤掉:

  class BlogPost(models.Model):
     _inherit = 'blog.post'
     active = fields.Boolean(string='Active', default=True)

记录字段:“active”在切换时会发生变化,但对应的记录及其关系保持不变。

过滤对应的底层代码见文件src/odoo/odoo/models.py :

 class MetaModel(api.Meta):
 """ The metaclass of all model classes.
    Its main purpose is to register the models per module.
 """
    def action_archive(self):
        """
        Set active=False on a recordset, by calling toggle_active 
        to take the corresponding actions according to the model
        """
       return self.filtered(lambda record: record.active).toggle_active()

    @api.model
    def _where_calc(self, domain, active_test=True):
       """Computes the WHERE clause needed to implement an OpenERP domain.
       :param domain: the domain to compute
       :type domain: list
       :param active_test: whether the default filtering of 
        records with ``active`` field set to ``False`` should be 
       applied.
       :return: the query expressing the given domain as provided in domain
      :rtype: osv.query.Query
      """
      # if the object has a field named 'active', filter out all inactive
      # records unless they were explicitely asked for
      if 'active' in self._fields and active_test and self._context.get('active_test', True):
        # the item[0] trick below works for domain items and '&'/'|'/'!'
        # operators too
          if not any(item[0] == 'active' for item in domain):
            domain = [('active', '=', 1)] + domain

          if domain:
            e = expression.expression(domain, self)
            tables = e.get_tables()
            where_clause, where_params = e.to_sql()
            where_clause = [where_clause] if where_clause else []
          else:
             where_clause, where_params, tables = [], [], ['"%s"' 
             % self._table]

          return Query(tables, where_clause, where_params)

显示所有记录(存档和活动):

class Blog(models.Model):
    _inherit = 'blog'
    post_ids = fields.One2many(
        'blog.post', 'id', 
         domain=['|', ('active', '=', True), ('active', '=', False)],
        context={'active_test': False})