[FIX] sale_timesheet: cannot create task in billable project

Before this commit, the portal user cannot create task in billable
project because he has no access rights to employee mappings model.
Indeed, this model is used to know the pricing type of the project and
also to search the default partner of the new task. If the user cannot
access we need to do it in sudo.

This commit adds a sudo to search correctly the default partner of the
task.

task-2379518

closes #73341
This commit is contained in:
Xavier BOL (xbo)
2021-08-26 14:59:33 +02:00
parent 19a8bf9527
commit a55de1e0a1
+4 -2
View File
@@ -340,8 +340,10 @@ class ProjectTask(models.Model):
def _get_default_partner_id(self, project, parent):
res = super()._get_default_partner_id(project, parent)
if not res and project:
if project.pricing_type == 'employee_rate':
return project.sale_line_employee_ids.sale_line_id.order_partner_id[:1]
# project in sudo if the current user is a portal user.
related_project = project if not self.user_has_groups('!base.group_user,base.group_portal') else project.sudo()
if related_project.pricing_type == 'employee_rate':
return related_project.sale_line_employee_ids.sale_line_id.order_partner_id[:1]
return res
sale_order_id = fields.Many2one(domain="['|', '|', ('partner_id', '=', partner_id), ('partner_id', 'child_of', commercial_partner_id), ('partner_id', 'parent_of', partner_id)]")