Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Live Chat

Entity: im_livechat.channel.member.history

Compute Method: _compute_session_duration_hour

Inputs Method Outputs
ongoing_chats = self.channel_id.filtered(lambda c: not c.livechat_end_dt)
last_msg_dt_by_channel_id = {
            message.res_id: message.create_date for message in ongoing_chats._get_last_messages()
        }
for history in self:
            end = history.channel_id.livechat_end_dt or last_msg_dt_by_channel_id.get(
                history.channel_id.id, fields.Datetime.now()
            )
            history.session_duration_hour = max((end - history.create_date).total_seconds() / 3600, 0)

Back to entity