[IMP] sale_timesheet: changes SOL in mapping if customer changes
Before this commit, when the user changes the customer of the project, the SOL of each mapping remains for the old customer of the project. To avoid the user forget to change the SOL of each SOL. This commit add a compute method on sale_line_id field in project.sale.line.employee.map to automatically remove the SOLs when the SO in project is removed because of a customer change in the project. Then, it also adds a require in this field to display a validation error as long as the SOL of each mapping is not set. task-2424382
This commit is contained in:
@@ -10,7 +10,7 @@ class ProjectProductEmployeeMap(models.Model):
|
||||
|
||||
project_id = fields.Many2one('project.project', "Project", required=True)
|
||||
employee_id = fields.Many2one('hr.employee', "Employee", required=True)
|
||||
sale_line_id = fields.Many2one('sale.order.line', "Sale Order Item", domain=[('is_service', '=', True)])
|
||||
sale_line_id = fields.Many2one('sale.order.line', "Sale Order Item", compute="_compute_sale_line_id", store=True, readonly=False, required=True, domain=[('is_service', '=', True)])
|
||||
company_id = fields.Many2one('res.company', string='Company', related='project_id.company_id')
|
||||
timesheet_product_id = fields.Many2one(
|
||||
'product.product', string='Service',
|
||||
@@ -26,6 +26,10 @@ 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.sale_order_id')
|
||||
def _compute_sale_line_id(self):
|
||||
self.filtered(lambda map_entry: not map_entry.project_id.sale_order_id and map_entry.sale_line_id).update({'sale_line_id': None})
|
||||
|
||||
@api.depends('sale_line_id', 'sale_line_id.price_unit', 'timesheet_product_id')
|
||||
def _compute_price_unit(self):
|
||||
for line in self:
|
||||
|
||||
Reference in New Issue
Block a user