diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py
index 4f06e298a00..81fba1c3da1 100644
--- a/addons/sale_timesheet/models/sale_order.py
+++ b/addons/sale_timesheet/models/sale_order.py
@@ -24,6 +24,7 @@ class SaleOrder(models.Model):
help='Select a non billable project on which tasks can be created.')
project_ids = fields.Many2many('project.project', compute="_compute_project_ids", string='Projects', copy=False, groups="project.group_project_user", help="Projects used in this sales order.")
timesheet_encode_uom_id = fields.Many2one('uom.uom', related='company_id.timesheet_encode_uom_id')
+ timesheet_total_duration = fields.Float("Timesheet Total Duration", compute='_compute_timesheet_total_duration', help="Total recorded duration, expressed in the encoding UoM")
@api.depends('analytic_account_id.line_ids')
def _compute_timesheet_ids(self):
@@ -60,6 +61,18 @@ class SaleOrder(models.Model):
projects |= order.project_id
order.project_ids = projects
+ @api.depends('timesheet_ids', 'company_id.timesheet_encode_uom_id')
+ def _compute_timesheet_total_duration(self):
+ for sale_order in self:
+ duration_list = []
+ for timesheet in sale_order.timesheet_ids:
+ timesheet_uom = timesheet.product_uom_id or timesheet.company_id.project_time_mode_id
+ if timesheet_uom != sale_order.timesheet_encode_uom_id and timesheet_uom.category_id == sale_order.timesheet_encode_uom_id.category_id:
+ duration_list.append(timesheet_uom._compute_quantity(timesheet.unit_amount, sale_order.timesheet_encode_uom_id))
+ else:
+ duration_list.append(timesheet.unit_amount)
+ sale_order.timesheet_total_duration = sum(duration_list)
+
@api.onchange('project_id')
def _onchange_project_id(self):
""" Set the SO analytic account to the selected project's analytic account """
diff --git a/addons/sale_timesheet/views/sale_order_views.xml b/addons/sale_timesheet/views/sale_order_views.xml
index 016e0ce66de..0b4a502cd8e 100644
--- a/addons/sale_timesheet/views/sale_order_views.xml
+++ b/addons/sale_timesheet/views/sale_order_views.xml
@@ -26,6 +26,7 @@
groups="project.group_project_user">
+