[FIX] hr_timesheet: prevent perf issues in project kanban
Prior to this commit the total_timesheet_time field is used in the kanban view in order to decide whether or not a menu entry has to be displayed. This commit introduce a new compute non stored field in order to count the number of timesheets and use that info in order to decide whether or not the menu entry has to be displayed. closes odoo/odoo#80080 X-original-commit: 1dce6aea852b1496bdcfd3b98c4da531d2646ad0 Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
This commit is contained in:
@@ -38,6 +38,7 @@ class Project(models.Model):
|
||||
)
|
||||
|
||||
timesheet_ids = fields.One2many('account.analytic.line', 'project_id', 'Associated Timesheets')
|
||||
timesheet_count = fields.Boolean(compute="_compute_timesheet_count")
|
||||
timesheet_encode_uom_id = fields.Many2one('uom.uom', related='company_id.timesheet_encode_uom_id')
|
||||
total_timesheet_time = fields.Integer(
|
||||
compute='_compute_total_timesheet_time',
|
||||
@@ -130,6 +131,17 @@ class Project(models.Model):
|
||||
total_time *= project.timesheet_encode_uom_id.factor
|
||||
project.total_timesheet_time = int(round(total_time))
|
||||
|
||||
@api.depends('timesheet_ids')
|
||||
def _compute_timesheet_count(self):
|
||||
timesheet_read_group = self.env['account.analytic.line'].read_group(
|
||||
[('project_id', 'in', self.ids)],
|
||||
['project_id'],
|
||||
['project_id']
|
||||
)
|
||||
timesheet_project_map = {project_info['project_id'][0]: project_info['project_id_count'] for project_info in timesheet_read_group}
|
||||
for project in self:
|
||||
project.timesheet_count = timesheet_project_map.get(project.id, 0)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
""" Create an analytic account if project allow timesheet and don't provide one
|
||||
|
||||
@@ -274,13 +274,13 @@
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_id" position="after">
|
||||
<field name="allow_timesheets" invisible="1"/>
|
||||
<field name="total_timesheet_time" invisible="1"/>
|
||||
<field name="timesheet_count" invisible="1"/>
|
||||
<field name="remaining_hours" invisible="1"/>
|
||||
<field name="has_planned_hours_tasks" invisible="1"/>
|
||||
<field name="encode_uom_in_days" invisible="1"/>
|
||||
</field>
|
||||
<xpath expr="//div[hasclass('o_kanban_manage_view')]" position="inside">
|
||||
<div role="menuitem" t-if="record.allow_timesheets.raw_value and record.total_timesheet_time.raw_value" groups="hr_timesheet.group_hr_timesheet_user">
|
||||
<div role="menuitem" t-if="record.allow_timesheets.raw_value and record.timesheet_count.raw_value" groups="hr_timesheet.group_hr_timesheet_user">
|
||||
<a name="%(act_hr_timesheet_line_by_project)d" type="action">Timesheets</a>
|
||||
</div>
|
||||
</xpath>
|
||||
|
||||
Reference in New Issue
Block a user