Skip to Content
Menu
This question has been flagged

There are models in Odoo that do not have the "Archive" action under the 'Action' button. Additionally, if we create a new model and do not check the option to allow records to be Archived, can we add it in later? 

Avatar
Discard
Author Best Answer

What does “Archive” Action do?

Before we jump into the steps for achieving this, let’s explore what the “Archive” button does. In Odoo, ‘Archive’ is nothing, but a filter based on a Boolean field. Odoo models that have archiving capabilities usually have a field called “Active”, which is a simple Boolean checkbox. Basically, if it is checked, it means that the record is active and if it is unchecked it means the record is not active i.e., archived. When you select a record and archive it, Odoo is unchecking the box for you and then filtering it out. By default, in a model view, you have displayed only the active records, and the archived ones are filtered. When you click on “Filters” and then select the Archived records it basically just shows you all the records that have the checkbox set to FALSE. For models that do not have the archiving function, we are missing this checkbox and some defaults which we can create later. The only step in this that may require direct XML coding will be adding the ribbon that says “Archived” on all the archived records.

Creating the Boolean field

The first step of the process is to create this checkbox that will help us differentiate archived from active records. Do not create this checkbox using studio because the field will be called x_studio_active and that won’t do. We will need to create the field directly on the model itself. 

Go into Settings > Technical > Models, find your model, and add a boolean field named "x_active" (label "Active")

Once you create the field on the model, you must add the field on the form and list views so that we can use it to create the filters.  You can add the field using Studio by simply finding it under “Existing Fields”. You don’t necessarily have to make it visible, as long as it is present in both views. In other models, this field is usually invisible so you can make it invisible after adding it.

Existing Records

If the model you are doing this has existing records, we need to make them active. When we add a new checkbox, Odoo defaults it to be unchecked for all records. This means that all the existing records will have the checkbox set to FALSE (meaning archived). This can be fixed by simply exporting all the existing records with external ID’s and the Active field, setting the Active field to be TRUE, and importing it back in so that all the records now have the Active field checked (hence meaning unarchived). 

Setting User-defined Defaults

For new records that will be created in the model, we need Odoo to automatically check the box. This means that the default for the Active field should be TRUE (checked). We can do this using User-defined Defaults.

Go into Settings > Technical > User-defined default and add a default set to true for the field.

Creating custom Filters for Archived records

We need a preset Filter for displaying all the Archived records. We can do this using Studio.

Open the model – Open Studio – Click on Views and select Search View. Drag a Filter and drop it under ‘Filters’. Label it “Archived” and set a domain on it – Active is not set (false) [["x_active","=",False]]

[OPTIONAL] Adding the Ribbon to Archived Records

We can also add the ribbon widget in the form view, but this can be done only through XML. Open the form view of the model, open studio, click on “View” on the left bar, click on the XML button to open the code and add the following lines of code as the first child of the sheet element in the form view.

Save the XML and exit Studio. You’re all set! 

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
1695
1
Aug 24
790
1
Aug 24
1067
1
Aug 24
857
1
Oct 24
1122