From f192c3e90f63766efd0ca32211beb8f354a3eebf Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Mon, 13 Aug 2018 09:49:07 +0200 Subject: [PATCH] [IMP] sale_timesheet: add project stat button on overview The config of a project will become more important and usefull for project manager, so adding a shortcut from the overview to setup correclty its project makes sense. This commit adds this button on the overview. Task #34703 --- addons/sale_timesheet/controllers/main.py | 22 +++++++++++++++++-- .../static/src/js/timesheet_plan.js | 14 +++++++----- .../views/hr_timesheet_templates.xml | 4 ++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/addons/sale_timesheet/controllers/main.py b/addons/sale_timesheet/controllers/main.py index 1e0cd17a038..2b82f175ac1 100644 --- a/addons/sale_timesheet/controllers/main.py +++ b/addons/sale_timesheet/controllers/main.py @@ -362,6 +362,13 @@ class SaleTimesheetController(http.Controller): def _plan_get_stat_button(self, projects): stat_buttons = [] + if len(projects) == 1: + stat_buttons.append({ + 'name': _('Project'), + 'res_model': 'project.project', + 'res_id': projects.id, + 'icon': 'fa fa-puzzle-piece', + }) stat_buttons.append({ 'name': _('Timesheets'), 'res_model': 'account.analytic.line', @@ -397,7 +404,7 @@ class SaleTimesheetController(http.Controller): return stat_buttons @http.route('/timesheet/plan/action', type='json', auth="user") - def plan_stat_button(self, domain, res_model='account.analytic.line'): + def plan_stat_button(self, domain=[], res_model='account.analytic.line', res_id=False): action = { 'type': 'ir.actions.act_window', 'view_id': False, @@ -405,7 +412,18 @@ class SaleTimesheetController(http.Controller): 'view_type': 'list', 'domain': domain, } - if res_model == 'account.analytic.line': + if res_model == 'project.project': + view_form_id = request.env.ref('project.edit_project').id + action = { + 'name': _('Project'), + 'type': 'ir.actions.act_window', + 'res_model': res_model, + 'view_mode': 'form', + 'view_type': 'form', + 'views': [[view_form_id, 'form']], + 'res_id': res_id, + } + elif res_model == 'account.analytic.line': ts_view_tree_id = request.env.ref('hr_timesheet.hr_timesheet_line_tree').id ts_view_form_id = request.env.ref('hr_timesheet.hr_timesheet_line_form').id action = { diff --git a/addons/sale_timesheet/static/src/js/timesheet_plan.js b/addons/sale_timesheet/static/src/js/timesheet_plan.js index afebfac23fe..90cbcd98379 100644 --- a/addons/sale_timesheet/static/src/js/timesheet_plan.js +++ b/addons/sale_timesheet/static/src/js/timesheet_plan.js @@ -232,7 +232,7 @@ var ProjectPlan = AbstractAction.extend(ControlPanelMixin, { views: [[false, 'list'], [false, 'form']], view_type: 'list', view_mode: 'form', - domain: domain, + domain: domain || [], }); }, /** @@ -242,12 +242,16 @@ var ProjectPlan = AbstractAction.extend(ControlPanelMixin, { _onClickStatButton: function (event) { var self = this; var data = $(event.currentTarget).data(); + var parameters = { + domain: data.domain || [], + res_model: data.resModel, + } + if (data.resId) { + parameters['res_id'] = data.resId; + } return this._rpc({ route:"/timesheet/plan/action", - params: { - domain: data.domain, - res_model: data.resModel, - }, + params: parameters, }).then(function(action){ self.do_action(action); }); diff --git a/addons/sale_timesheet/views/hr_timesheet_templates.xml b/addons/sale_timesheet/views/hr_timesheet_templates.xml index 782429c2e33..501fd515449 100644 --- a/addons/sale_timesheet/views/hr_timesheet_templates.xml +++ b/addons/sale_timesheet/views/hr_timesheet_templates.xml @@ -25,9 +25,9 @@
-