|
|
timesheets_read_group = self.env['account.analytic.line']._read_group(
[('project_id', 'in', self.ids)],
['project_id', 'product_uom_id'],
['unit_amount:sum'],
)
timesheet_time_dict = defaultdict(list)
for project, product_uom, unit_amount_sum in timesheets_read_group:
timesheet_time_dict[project.id].append((product_uom, unit_amount_sum))
for project in self:
# Timesheets may be stored in a different unit of measure, so first
# we convert all of them to the reference unit
# if the timesheet has no product_uom_id then we take the one of the project
total_time = 0.0
for product_uom, unit_amount in timesheet_time_dict[project.id]:
factor = (product_uom or project.timesheet_encode_uom_id).factor_inv
total_time += unit_amount * (1.0 if project.encode_uom_in_days else factor)
# Now convert to the proper unit of measure set in the settings
total_time *= project.timesheet_encode_uom_id.factor
project.total_timesheet_time = int(round(total_time))
|
|