[FIX] sale_timesheet: more flexible domain for sale line on task

Imagine the following use case: you have a partner (company) with
children (person). Selling a service to that company will create
a task on SO confirmation. Then the project lives its life, and
sometime a person of that company requests a task. The task
customer is the person, but should be linked to the SO as the
time spent on its should be invoiced to the client (the company,
customer of the SO).
This is not possible, as the selectable Sale lines for a task was
the one of the exact partner of the the task.

This commit changes that by checking the commercial partner instead
of the partner. So, for reporting purpose, we can keep the real
customer of the task, and correctly invoice the related timesheet
on the SO of customer company.

opw-1915703

closes odoo/odoo#29921
This commit is contained in:
jem-odoo
2019-01-04 07:44:23 +00:00
parent 581c16ef94
commit 4fd15e82bc
+5 -2
View File
@@ -186,7 +186,7 @@ class ProjectTask(models.Model):
self.partner_id = self.sale_line_id.order_partner_id
# set domain on SO: on non billable project, all SOL of customer, otherwise the one from the SO
result = result or {}
domain = [('is_service', '=', True), ('is_expense', '=', False), ('order_partner_id', '=', self.partner_id.id), ('state', 'in', ['sale', 'done'])]
domain = [('is_service', '=', True), ('is_expense', '=', False), ('order_partner_id', 'child_of', self.partner_id.commercial_partner_id.id), ('state', 'in', ['sale', 'done'])]
if self.project_id.sale_order_id:
domain += [('order_id', '=', self.project_id.sale_order_id.id)]
result.setdefault('domain', {})['sale_line_id'] = domain
@@ -195,8 +195,11 @@ class ProjectTask(models.Model):
@api.onchange('partner_id')
def _onchange_partner_id(self):
result = super(ProjectTask, self)._onchange_partner_id()
if self.sale_line_id.order_partner_id != self.partner_id:
result = result or {}
if self.sale_line_id.order_partner_id.commercial_partner_id != self.partner_id.commercial_partner_id:
self.sale_line_id = False
if self.partner_id:
result.setdefault('domain', {})['sale_line_id'] = [('is_service', '=', True), ('is_expense', '=', False), ('order_partner_id', 'child_of', self.partner_id.commercial_partner_id.id), ('state', 'in', ['sale', 'done'])]
return result
@api.multi