Development Book V17: Add time spent

Add time spent in each stage to the status bar

In Odoo 17, a mixin called MailTrackingDurationMixin has been introduced. This mixin can be included in a model that has a many2one field. Its functionality involves calculating the time a record remains in each possible value of the many2one field and storing this information in a JSON field named duration_tracking.

class MailTrackingDurationMixin(models.AbstractModel):
      _name = "mail.tracking.duration.mixin"
      _description = "Mixin to compute the time a record has spent in each value a many2one field can take"
      
      duration_tracking = fields.Json(
          string="Status time", compute="_compute_duration_tracking",
          help="JSON that maps ids from a many2one field to seconds spent")

The primary application of this mixin is with a newly introduced field called StatusBarDurationField (with the widget attribute set to 'statusbar_duration').


                    <field name="stage_id" widget="statusbar_duration" />
            

This field is designed to calculate and showcase the duration a record has spent in each stage.It is specifically designed for use in the form view's status bar. The StatusBarDurationField inherits from the StatusBarField.

odoo-development

To define the field on which the computation should be conducted, the model inheriting from this mixin must specify _track_duration_field. For instance, _track_duration_field = 'stage_id'.

The computation relies on mail.tracking.value messages; therefore, tracking must be enabled for the relevant field.

In the widget, time is displayed using a Luxon Duration object, and the "narrow" setting ensures that time is represented with a single character. Luxon is responsible for handling translations.

whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message