[IMP] sale_timesheet: compute partner_id in project when SOL is set
Before this commit, the user can choose any SOL for any customer in the sale_line_id field of the project and also in the employee mappings. The problem is when the user create a task for a customer A, the default SOL of the project can be no selected if this SOL is not for the customer A. Also, some employee mappings can be unused for this task if the SOL of the employee mapping is not for the customer A. Moreover, if the customer selects a customer in the project, the SOL initially choose in this project can be removed if the customer is not the same. For these reasons, the commit adds a compute for the partner_id field in the project.project model. This compute is trigger when the user select a default sales order item (SOL) for the project or select an SOL in the first employee mappings for this project. With this changes, the SOLs choose will be for only one partner (customer) in a project. task-2442683 closes #66181
This commit is contained in:
committed by
Yannick Tivisse
parent
6463755f15
commit
47971aa4be
@@ -49,6 +49,7 @@ class Project(models.Model):
|
||||
compute="_compute_timesheet_product_id", store=True, readonly=False,
|
||||
default=_default_timesheet_product_id)
|
||||
warning_employee_rate = fields.Boolean(compute='_compute_warning_employee_rate')
|
||||
partner_id = fields.Many2one(compute='_compute_partner_id', store=True, readonly=False)
|
||||
|
||||
@api.depends('sale_line_id', 'sale_line_employee_ids', 'allow_billable')
|
||||
def _compute_pricing_type(self):
|
||||
@@ -137,6 +138,15 @@ class Project(models.Model):
|
||||
for project in self.filtered(lambda p: not p.project_overview):
|
||||
project.project_overview = project.allow_billable or project.allow_timesheets
|
||||
|
||||
@api.depends('sale_line_employee_ids.sale_line_id', 'sale_line_id')
|
||||
def _compute_partner_id(self):
|
||||
for project in self:
|
||||
if project.partner_id:
|
||||
continue
|
||||
if project.allow_billable and project.allow_timesheets and project.pricing_type != 'task_rate':
|
||||
sol = project.sale_line_id or project.sale_line_employee_ids.sale_line_id[:1]
|
||||
project.partner_id = sol.order_partner_id
|
||||
|
||||
@api.constrains('sale_line_id')
|
||||
def _check_sale_line_type(self):
|
||||
for project in self.filtered(lambda project: project.sale_line_id):
|
||||
|
||||
@@ -26,9 +26,14 @@ class ProjectProductEmployeeMap(models.Model):
|
||||
('uniqueness_employee', 'UNIQUE(project_id,employee_id)', 'An employee cannot be selected more than once in the mapping. Please remove duplicate(s) and try again.'),
|
||||
]
|
||||
|
||||
@api.depends('project_id.partner_id')
|
||||
@api.depends('partner_id')
|
||||
def _compute_sale_line_id(self):
|
||||
self.filtered(lambda map_entry: map_entry.sale_line_id.order_partner_id != map_entry.project_id.partner_id).update({'sale_line_id': False})
|
||||
self.filtered(
|
||||
lambda map_entry:
|
||||
map_entry.sale_line_id
|
||||
and map_entry.partner_id
|
||||
and map_entry.sale_line_id.order_partner_id.commercial_partner_id != map_entry.partner_id.commercial_partner_id
|
||||
).update({'sale_line_id': False})
|
||||
|
||||
@api.depends('sale_line_id', 'sale_line_id.price_unit')
|
||||
def _compute_price_unit(self):
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
<field name="sale_line_employee_ids">
|
||||
<tree editable="bottom">
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="project_id" invisible="1"/>
|
||||
<field name="partner_id" invisible="1"/>
|
||||
<field name="employee_id" options="{'no_create': True}"/>
|
||||
<field name="sale_line_id" attrs="{'required': True}" options="{'no_create': True}"/>
|
||||
|
||||
Reference in New Issue
Block a user