Janik von Rotz

2 min read

Odoo Development: Show last updated date above list view

Odoo runs various reports in the background. Some of these report take a while to finish and therefore seeing the last updated date is important. In a few steps I will show how you can add the last updated date to a list view.

First we need a placeholder for the date that is updated once the list view is loaded. Add the following list view button element to the Odoo module.


<?xml version="1.0" encoding="UTF-8"?>
<template xml:space="preserve">
  <t t-extend="ListView.buttons">
    <t t-jquery="div.o_list_buttons" t-operation="append">
      <div class="o_list_selection_box container_last_updated_on" t-if="widget.modelName == 'critical.forecast'">
        <i><strong>Last Updated On: <span class="container_last_updated_date"/></strong></i>

Included the file in the __manifest__.py.

Next extend the JavaScript List Controller with the following file:


odoo.define('$MODULE_NAME.show_last_updated_date', function (require) {
    "use strict"

    var ListController = require('web.ListController')
    var session = require('web.session')
    var ulang = session.user_context['lang'].replace('_','-')
        renderButtons: function($node) {
            if(this.$buttons.find('.container_last_updated_on').length) {
         updateButtons() {
            if(this.$buttons.find('.container_last_updated_on').length) {
        set_last_update_date: function () {
            return this._rpc({
                model: this.modelName,
                method: 'search_read',
                args: [[], ['write_date']],
                kwargs: {
                    limit: 1,
            }).then((result) => {
				if (result.length > 0) {
                    var write_date = new Date(result[0].write_date)
                    write_date = new Date(write_date.setMinutes(write_date.getMinutes() - write_date.getTimezoneOffset()))
                    if (result.length) {
                    } else {

This extension will retrieve the last write date of the current model, convert it to the users timezone and locale and then display it in the placeholder.

The JavaScript file must be included in the assets backend template.

<template id="button_render_js" inherit_id="web.assets_backend">
	<xpath expr="." position="inside">
		<script src="$MODULE_NAME/static/src/js/show_last_updated_date.js" type="text/javascript"/>

Once these files are in place, the last write of the model records should be set automatically.

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