summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/sale_timesheet/models/account.py6
-rw-r--r--addons/sale_timesheet/models/project.py23
-rw-r--r--addons/sale_timesheet_edit/models/account_analytic_line.py2
3 files changed, 7 insertions, 24 deletions
diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py
index 5d2c503e9b1..74b039fa6d3 100644
--- a/addons/sale_timesheet/models/account.py
+++ b/addons/sale_timesheet/models/account.py
@@ -57,10 +57,10 @@ class AccountAnalyticLine(models.Model):
else:
self.so_line = False
- @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'employee_id')
+ @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'employee_id', 'project_id.allow_billable')
def _compute_so_line(self):
for timesheet in self._get_not_billed(): # Get only the timesheets are not yet invoiced
- timesheet.so_line = timesheet._timesheet_determine_sale_line(timesheet.task_id, timesheet.employee_id, timesheet.project_id)
+ timesheet.so_line = timesheet.project_id.allow_billable and timesheet._timesheet_determine_sale_line(timesheet.task_id, timesheet.employee_id, timesheet.project_id)
def _get_not_billed(self):
return self.filtered(lambda t: not t.timesheet_invoice_id or t.timesheet_invoice_id.state == 'cancel')
@@ -94,8 +94,6 @@ class AccountAnalyticLine(models.Model):
values = super(AccountAnalyticLine, self)._timesheet_preprocess(values)
# task implies so line (at create)
if any([field_name in values for field_name in ['task_id', 'project_id']]) and not values.get('so_line') and (values.get('employee_id') or self.mapped('employee_id')):
- if not values.get('employee_id') and len(self.mapped('employee_id')) > 1:
- raise UserError(_('You can not modify timesheets from different employees'))
task = self.env['project.task'].sudo().browse(values['task_id']) if values.get('task_id') else self.env['project.task']
employee = self.env['hr.employee'].sudo().browse(values['employee_id']) if values.get('employee_id') else self.mapped('employee_id')
project = self.env['project.project'].sudo().browse(values['project_id']) if values.get('project_id') else task.project_id
diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py
index 597b858ded6..cf215b5dd09 100644
--- a/addons/sale_timesheet/models/project.py
+++ b/addons/sale_timesheet/models/project.py
@@ -294,10 +294,11 @@ class ProjectTask(models.Model):
elif not task.sale_order_id:
task.sale_order_id = False
- @api.depends('commercial_partner_id', 'sale_line_id.order_partner_id.commercial_partner_id', 'parent_id.sale_line_id', 'project_id.sale_line_id')
+ @api.depends('commercial_partner_id', 'sale_line_id.order_partner_id.commercial_partner_id', 'parent_id.sale_line_id', 'project_id.sale_line_id', 'allow_billable')
def _compute_sale_line(self):
- super(ProjectTask, self)._compute_sale_line()
- for task in self.filtered(lambda t: not t.sale_line_id):
+ billable_tasks = self.filtered('allow_billable')
+ super(ProjectTask, billable_tasks)._compute_sale_line()
+ for task in billable_tasks.filtered(lambda t: not t.sale_line_id):
task.sale_line_id = task._get_last_sol_of_customer()
@api.depends('project_id.sale_line_employee_ids')
@@ -325,22 +326,6 @@ class ProjectTask(models.Model):
project_dest = self.env['project.project'].browse(values['project_id'])
if project_dest.bill_type == 'customer_project' and project_dest.pricing_type == 'employee_rate':
self.write({'sale_line_id': False})
- if 'sale_line_id' in values and self.filtered('allow_timesheets').sudo().timesheet_ids:
- so = self.env['sale.order.line'].browse(values['sale_line_id']).order_id
- if so and not so.analytic_account_id:
- so.analytic_account_id = self.project_id.analytic_account_id
- timesheet_ids = self.filtered('allow_timesheets').timesheet_ids.filtered(
- lambda t: (not t.timesheet_invoice_id or t.timesheet_invoice_id.state == 'cancel')
- )
- timesheet_ids.write({'so_line': values['sale_line_id']})
- if 'project_id' in values:
-
- # Special case when we edit SOL an project in same time, as we edit SOL of
- # timesheet lines, function '_get_timesheet' won't find the right timesheet
- # to edit so we must edit those here.
- project = self.env['project.project'].browse(values.get('project_id'))
- if project.allow_timesheets:
- timesheet_ids.write({'project_id': values.get('project_id')})
if 'non_allow_billable' in values and self.filtered('allow_timesheets').sudo().timesheet_ids:
timesheet_ids = self.filtered('allow_timesheets').timesheet_ids.filtered(
lambda t: (not t.timesheet_invoice_id or t.timesheet_invoice_id.state == 'cancel')
diff --git a/addons/sale_timesheet_edit/models/account_analytic_line.py b/addons/sale_timesheet_edit/models/account_analytic_line.py
index 69a9cc3df30..5ff797ddc34 100644
--- a/addons/sale_timesheet_edit/models/account_analytic_line.py
+++ b/addons/sale_timesheet_edit/models/account_analytic_line.py
@@ -10,7 +10,7 @@ class AccountAnalyticLine(models.Model):
is_so_line_edited = fields.Boolean()
- @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'employee_id')
+ @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'project_id.allow_billable', 'employee_id')
def _compute_so_line(self):
super(AccountAnalyticLine, self.filtered(lambda t: not t.is_so_line_edited))._compute_so_line()