diff --git a/addons/hr_holidays/models/hr_holidays.py b/addons/hr_holidays/models/hr_holidays.py index 59d942c2ff6..66f95b60946 100644 --- a/addons/hr_holidays/models/hr_holidays.py +++ b/addons/hr_holidays/models/hr_holidays.py @@ -61,7 +61,7 @@ class HolidaysType(models.Model): double_validation = fields.Boolean(string='Apply Double Validation', help="When selected, the Allocation/Leave Requests for this type require a second validation to be approved.") - company_id = fields.Many2one('res.company', string='Company') + company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.user.company_id) @api.multi def get_days(self, employee_id): diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 3023fdcea59..68a64a7fbde 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -30,25 +30,32 @@ class AccountAnalyticLine(models.Model): @api.model def create(self, vals): - vals = self._update_timesheet_values(vals) - if not vals.get('employee_id') and vals.get('project_id'): # compute employee only for timesheet lines, makes no sense for other lines - if vals.get('user_id'): - ts_user_id = vals['user_id'] - else: - ts_user_id = self.env.user.id - vals['employee_id'] = self.env['hr.employee'].search([('user_id', '=', ts_user_id)], limit=1).id + vals = self._timesheet_preprocess(vals) return super(AccountAnalyticLine, self).create(vals) @api.multi def write(self, vals): - vals = self._update_timesheet_values(vals) + vals = self._timesheet_preprocess(vals) return super(AccountAnalyticLine, self).write(vals) - def _update_timesheet_values(self, vals): - if vals.get('project_id'): + def _timesheet_preprocess(self, vals): + """ Deduce other field values from the one given. + Overrride this to compute on the fly some field that can not be computed fields. + :param values: dict values for `create`or `write`. + """ + # project implies analytic account + if vals.get('project_id') and not vals.get('account_id'): project = self.env['project.project'].browse(vals.get('project_id')) vals['account_id'] = project.analytic_account_id.id - if vals.get('employee_id'): + # employee implies user + if vals.get('employee_id') and not vals.get('user_id'): employee = self.env['hr.employee'].browse(vals['employee_id']) vals['user_id'] = employee.user_id.id + # compute employee only for timesheet lines, makes no sense for other lines + if not vals.get('employee_id') and vals.get('project_id'): + if vals.get('user_id'): + ts_user_id = vals['user_id'] + else: + ts_user_id = self._default_user() + vals['employee_id'] = self.env['hr.employee'].search([('user_id', '=', ts_user_id)], limit=1).id return vals diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 0fc7aa314bf..4202e49bc45 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -10,6 +10,7 @@ class Project(models.Model): allow_timesheets = fields.Boolean("Allow timesheets", default=True) + class Task(models.Model): _inherit = "project.task" @@ -25,7 +26,7 @@ class Task(models.Model): children_hours += max(child_task.planned_hours, child_task.effective_hours + child_task.children_hours) task.children_hours = children_hours - task.effective_hours = sum(task.timesheet_ids.mapped('unit_amount')) + task.effective_hours = sum(task.sudo().timesheet_ids.mapped('unit_amount')) # use 'sudo' here to allow project user (without timesheet user right) to create task task.remaining_hours = task.planned_hours - task.effective_hours - task.children_hours task.total_hours = max(task.planned_hours, task.effective_hours) task.total_hours_spent = task.effective_hours + task.children_hours @@ -42,7 +43,7 @@ class Task(models.Model): effective_hours = fields.Float(compute='_hours_get', store=True, string='Hours Spent', help="Computed using the sum of the task work done.") total_hours = fields.Float(compute='_hours_get', store=True, string='Total', help="Computed as: Time Spent + Remaining Time.") total_hours_spent = fields.Float(compute='_hours_get', store=True, string='Total Hours', help="Computed as: Time Spent + Sub-tasks Hours.") - progress = fields.Float(compute='_hours_get', store=True, string='Working Time Recorded', group_operator="avg") + progress = fields.Float(compute='_hours_get', store=True, string='Progress', group_operator="avg") delay_hours = fields.Float(compute='_hours_get', store=True, string='Delay Hours', help="Computed as difference between planned hours by the project manager and the total hours of the task.") children_hours = fields.Float(compute='_hours_get', store=True, string='Sub-tasks Hours', help="Sum of the planned hours of all sub-tasks (when a sub-task is closed or its spent hours exceed its planned hours, spent hours are counted instead)") timesheet_ids = fields.One2many('account.analytic.line', 'task_id', 'Timesheets') diff --git a/addons/hr_timesheet/report/hr_timesheet_report_view.xml b/addons/hr_timesheet/report/hr_timesheet_report_view.xml index 66e20b6bfcd..6ddd5333cbe 100644 --- a/addons/hr_timesheet/report/hr_timesheet_report_view.xml +++ b/addons/hr_timesheet/report/hr_timesheet_report_view.xml @@ -2,10 +2,10 @@ - Activities + By Employee account.analytic.line [('project_id', '!=', False)] - {"search_default_today":1} + {'search_default_groupby_employee':1,}

@@ -19,34 +19,131 @@ - + pivot - + tree - + form + + + By Project + account.analytic.line + [('project_id', '!=', False)] + {'search_default_groupby_project':1,} + + +

+ Click to record activities. +

+ You can register and track your workings hours by project every + day. Every time spent on a project will become a cost and can be re-invoiced to + customers if required. +

+
+
+ + + + pivot + + + + + + + tree + + + + + + + form + + + + + + By Task + account.analytic.line + [('project_id', '!=', False)] + {'search_default_groupby_task':1,} + + +

+ Click to record activities. +

+ You can register and track your workings hours by project every + day. Every time spent on a project will become a cost and can be re-invoiced to + customers if required. +

+
+
+ + + + pivot + + + + + + + tree + + + + + + + form + + + + - + + + name="By Employee" + sequence="10"/> + + + + +
diff --git a/addons/hr_timesheet/views/hr_timesheet_views.xml b/addons/hr_timesheet/views/hr_timesheet_views.xml index 6807e9ede77..f407a379c30 100644 --- a/addons/hr_timesheet/views/hr_timesheet_views.xml +++ b/addons/hr_timesheet/views/hr_timesheet_views.xml @@ -243,7 +243,12 @@ account.analytic.line [('project_id', '!=', False)] - {'search_default_week':1, 'search_default_groupby_employee':1} + { + 'search_default_week':1, + 'search_default_groupby_employee':1, + 'search_default_groupby_project':1, + 'search_default_groupby_task':1 + } @@ -272,8 +277,5 @@ parent="menu_hr_time_tracking" action="timesheet_action_all"/> - - diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index b7cbda8ac4c..50afd40a4d1 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -40,7 +40,7 @@ 24
@@ -55,16 +55,18 @@ project.task.form.inherited project.task - + - - - - - - - + + + + + + + + + @@ -116,16 +118,16 @@ -
+ - - + diff --git a/addons/hr_timesheet/views/res_config_settings_views.xml b/addons/hr_timesheet/views/res_config_settings_views.xml index ff3ecd6292b..0bd2760e6ec 100644 --- a/addons/hr_timesheet/views/res_config_settings_views.xml +++ b/addons/hr_timesheet/views/res_config_settings_views.xml @@ -59,19 +59,21 @@
-

Leaves

-
-
-
- -
-
-