Janik von Rotz

1 min read

Odoo Development: Add archiving functionality

Odoo has a builtin archiving function for any model. Once a record is archived it will not be displayed in any views and selections, but can is easily be unarchived. This functionality ensures that relations must not be removed if linked records is obsolete.

The examples are based on the Odoo App Certificate Planner.

We are going to add the archiving function to our model change_status. First simply add the well-known field active to the model class.


from odoo import models, fields, api, _

class ChangeStatus(models.Model):
    active = fields.Boolean(default=True)

This will enable the archive functionality.

If you have a custom search and form view, ensure that the archive filter is displayed.



  <record model="ir.ui.view" id="change_status_search">
    <field name="name">Change Status Search</field>
    <field name="model">certificate_planer.change_status</field>
    <field name="arch" type="xml">
        <field name="designation"/>
        <filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>

And show a ribbon if the record shown is archived.


  <record model="ir.ui.view" id="change_status_form">
    <field name="name">Change Status Form</field>
    <field name="model">certificate_planer.change_status</field>
    <field name="arch" type="xml">
      <form string="Change Status Form">
          <widget name="web_ribbon" title="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}"/>
          <field name="active" invisible="1"/>

The form and list actions to archive and unarchive the records will be generated automatically.

Categories: Odoo
Tags: odoo , development , tutorial
Improve this page
Show statistic for this page