diff --git a/cor_custom/models/analytic.py b/cor_custom/models/analytic.py index 8d4c801..4fe75d0 100755 --- a/cor_custom/models/analytic.py +++ b/cor_custom/models/analytic.py @@ -14,7 +14,52 @@ class AccountAnalyticLine(models.Model): start_time = fields.Float(string='Start Time', digits=(16, 2)) end_time = fields.Float(string='End Time', digits=(16, 2)) + unit_amount = fields.Float('Duration', default=0.0) + @api.onchange('employee_id') + def _onchange_employee_id(self): + domain = [] + if self.employee_id and self.employee_id.user_id: + manager_id = self.env['project.project'].search( + [('user_id', '=', self.employee_id.user_id.id), ('allow_forecast', '=', True)]).ids + emp_project_ids = self.env['project.project'].search( + [('privacy_visibility', 'in', ('employees', 'portal')), ('allow_forecast', '=', True)]).ids + project_ids = self.env['project.project'].search( + [('privacy_visibility', '=', 'followers'), ('allow_forecast', '=', True), + ('allowed_internal_user_ids', 'in', self.employee_id.user_id.id)]).ids + consul_ids = self.env['project.sale.line.employee.map'].search([('employee_id', '=', self.employee_id.id)]) + consul_project_ids = [val.project_id.id for val in consul_ids] + emp_all_project_ids = manager_id + emp_project_ids + project_ids + consul_project_ids + domain = [('id', 'in', list(set(emp_all_project_ids)))] + result = { + 'domain': {'project_id': domain}, + } + return result + + @api.onchange('project_id') + def _onchange_project_id(self): + domain = [] if not self.project_id else [('project_id', '=', self.project_id.id)] + manager_id = [] + user_ids = [] + consul_project_ids = [] + if self.project_id: + consul_ids = self.env['project.sale.line.employee.map'].search([('project_id', '=', self.project_id.id)]) + consul_project_ids = [val.employee_id.id for val in consul_ids] + if self.project_id and self.project_id.user_id: + manager_id = self.env['hr.employee'].search([('user_id', '=', self.project_id.user_id.id)]).ids + if self.project_id and self.project_id.privacy_visibility in ('employees', 'portal'): + user_ids = self.env['hr.employee'].search([('user_id', '!=', False)]).ids + if self.project_id and self.project_id.privacy_visibility == 'followers': + user_ids = self.env['hr.employee'].search( + [('user_id', 'in', self.project_id.allowed_internal_user_ids.ids)]).ids + project_all_emp_ids = manager_id + user_ids + consul_project_ids + result = { + 'domain': {'task_id': domain, 'employee_id': [('id', 'in', project_all_emp_ids)]}, + } + if self.project_id != self.task_id.project_id: + # reset task when changing project + self.task_id = False + return result _sql_constraints = [ ('check_start_time_lower_than_24', 'CHECK(start_time <= 24)', 'You cannot have a start hour greater than 24'), diff --git a/cor_custom/models/project.py b/cor_custom/models/project.py index 3625c4b..d7f2f10 100755 --- a/cor_custom/models/project.py +++ b/cor_custom/models/project.py @@ -41,13 +41,13 @@ class Project(models.Model): start_date = fields.Date(string='Start Date') end_date = fields.Date(string='End Date') - budgeted_hours = fields.Float(string='Total Budgeted Hours', compute='_compute_consultant_timesheet_hours') + budgeted_hours = fields.Float(string='Total Budgeted Hours', compute='_compute_calc') budgeted_hours2 = fields.Float(string='Total Budgeted Hours') budgeted_revenue = fields.Float(string='Budgeted Revenue', digits=(16, 2)) expenses_per = fields.Float(string='Expenses (%)', digits=(16, 2)) expenses_amt = fields.Float(string='Expenses Amount', digits=(16, 2)) cost = fields.Float("Total Revenue", compute='onchange_compute_values', store=True) - consultant_cost = fields.Float("Actual Cost", compute='_compute_consultant_timesheet_hours') + consultant_cost = fields.Float("Actual Cost", compute='_compute_calc') other_expenses = fields.Float(string='Other Expenses', related='expenses_amt') total_expenses = fields.Float(string='Total Expenses', digits=(16, 2), compute='_compute_calc', store=True) hourly_rate = fields.Float("Hourly Rate", default=0.0) @@ -65,6 +65,8 @@ class Project(models.Model): manager_hour = fields.Float(string='Manager Hour') employee_hour = fields.Float(string='Employee Hour') + + @api.depends('cost', 'expenses_amt', 'budgeted_revenue') def _compute_consultant_timesheet_hours(self): for record in self: consultant_cost = 0.0 @@ -76,6 +78,10 @@ class Project(models.Model): record.budgeted_hours = hour total_exp = record.consultant_cost + record.expenses_amt record.total_expenses = total_exp + profit_amt = record.budgeted_revenue - total_exp + record.profit_amt = profit_amt + if record.profit_amt > 0 and record.budgeted_revenue > 0: + record.profit_per = (record.profit_amt / record.budgeted_revenue) * 100 if record.project_type == 'hours_in_consultant' and record.budgeted_hours > 0.0: record.hourly_rate = (record.budgeted_revenue / record.budgeted_hours) if record.project_type == 'hours_no_limit' and record.budgeted_hours2 > 0.0: @@ -113,16 +119,6 @@ class Project(models.Model): if self.budgeted_hours > 0.0: self.hourly_rate = (self.budgeted_revenue / self.budgeted_hours) - @api.depends('cost', 'expenses_amt', 'budgeted_revenue') - def _compute_calc(self): - for record in self: - total_exp = record.consultant_cost + record.expenses_amt - record.total_expenses = total_exp - profit_amt = record.budgeted_revenue - total_exp - record.profit_amt = profit_amt - if record.profit_amt > 0 and record.budgeted_revenue > 0: - record.profit_per = (record.profit_amt / record.budgeted_revenue) * 100 - @api.depends('sale_line_employee_ids') def onchange_compute_values(self): for record in self: @@ -159,7 +155,7 @@ class InheritProjectProductEmployeeMap(models.Model): def _compute_timesheet_hour(self): for val in self: - self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line + self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line where project_id = %(project_id)s and employee_id = %(employee_id)s GROUP BY project_id, employee_id''', {'project_id': val.project_id._origin.id, 'employee_id': val.employee_id.id, }) @@ -207,4 +203,4 @@ class InheritProjectProductEmployeeMap(models.Model): line.currency_id = line.timesheet_product_id.currency_id else: # line.price_unit = 0 - line.currency_id = False + line.currency_id = False \ No newline at end of file diff --git a/cor_custom/views/analytic_view.xml b/cor_custom/views/analytic_view.xml index a03a447..117f463 100755 --- a/cor_custom/views/analytic_view.xml +++ b/cor_custom/views/analytic_view.xml @@ -15,6 +15,17 @@ --> + + Analytic line + account.analytic.line + + + + + + + + account.analytic.line.tree.hr_timesheet_inherit1 account.analytic.line diff --git a/cor_custom/views/project_view.xml b/cor_custom/views/project_view.xml index 2376f33..73389a7 100755 --- a/cor_custom/views/project_view.xml +++ b/cor_custom/views/project_view.xml @@ -6,11 +6,11 @@ project.project -
+ diff --git a/planning/models/planning.py b/planning/models/planning.py index f590aa0..6e88d55 100755 --- a/planning/models/planning.py +++ b/planning/models/planning.py @@ -321,8 +321,8 @@ class Planning(models.Model): ) else: name = '%s - %s %s' % ( - start_datetime.date(), - end_datetime.date(), + datetime.strftime(start_datetime.date(), "%d/%m/%Y"), + datetime.strftime(end_datetime.date(), "%d/%m/%Y"), name )