The archiving-feature is based on a simple boolean field, which is used to filter out from display:
class BlogPost(models.Model):
_inherit = 'blog.post'
active = fields.Boolean(string='Active', default=True)
The record field: "active" will change when it's toggled but the corresponding record and its relations remain unchanged.
The underlying code corresponding to the filtering can be found in the file 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)
To display all records (archived and active):
class Blog(models.Model):
_inherit = 'blog'
post_ids = fields.One2many(
'blog.post', 'id',
domain=['|', ('active', '=', True), ('active', '=', False)],
context={'active_test': False})