From e0824571f071b279cdc3e6f31b94d46ea7a06ded Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Fri, 8 Apr 2022 10:00:18 +0000 Subject: [PATCH] [IMP] sale_timesheet: change timesheet action to get the correct pivot Before this commit, in the project right side panel, we use the action used with the stat button displayed in project form view. This action has a pivot view grouped by invoice type. However, in the right side panel, the timesheet invoice types shown in revenues and costs subsection of the project profitability section does not need this group by but we would like to group by invoice (if the row concerned "Timesheet (Billed on Time)") or group by employee (for the other rows) This commit changes the action to use the action as template created for Sales section in project right side panel. With this changes, we no longer have to change the views to have the ones expected, we will just change the pivot view according to the row selected (concerning the timesheets part) in Profitability section. task-2814466 Part-of: odoo/odoo#88219 --- addons/sale_timesheet/models/project.py | 24 +++++++++---------- .../views/hr_timesheet_views.xml | 14 +++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 653dbf38a25..eb5375f28b1 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -286,23 +286,14 @@ class Project(models.Model): def action_billable_time_button(self): self.ensure_one() - action = self.env["ir.actions.actions"]._for_xml_id("hr_timesheet.timesheet_action_all") + action = self.env["ir.actions.actions"]._for_xml_id("sale_timesheet.timesheet_action_from_sales_order_item") action.update({ 'context': { 'grid_range': 'week', 'search_default_groupby_timesheet_invoice_type': True, - 'pivot_row_groupby': ['date:month'], 'default_project_id': self.id, }, 'domain': [('project_id', '=', self.id)], - 'view_mode': 'tree,kanban,pivot,graph,form', - 'views': [ - [self.env.ref('hr_timesheet.timesheet_view_tree_user').id, 'tree'], - [self.env.ref('hr_timesheet.view_kanban_account_analytic_line').id, 'kanban'], - [self.env.ref('sale_timesheet.view_hr_timesheet_line_pivot_billing_rate').id, 'pivot'], - [self.env.ref('hr_timesheet.view_hr_timesheet_line_graph_all').id, 'graph'], - [self.env.ref('hr_timesheet.timesheet_view_form_user').id, 'form'], - ], }) return action @@ -310,10 +301,18 @@ class Project(models.Model): self.ensure_one() if section_name in ['billable_fixed', 'billable_time', 'billable_milestones', 'billable_manual', 'non_billable']: action = self.action_billable_time_button() - action['name'] = _('Timesheets') if domain: action['domain'] = expression.AND([[('project_id', '=', self.id)], domain]) action['context'].update(search_default_groupby_timesheet_invoice_type=False, **self.env.context) + pivot_view = False + if section_name == 'billable_time': + pivot_view = self.env.ref('sale_timesheet.view_hr_timesheet_pivot_view_per_invoice').id + else: + pivot_view = self.env.ref('sale_timesheet.timesheet_view_pivot_revenue').id + action['views'] = [ + (view_id, view_type) if view_type != 'pivot' else (pivot_view, view_type) + for view_id, view_type in action['views'] + ] if res_id: if 'views' in action: action['views'] = [ @@ -322,8 +321,7 @@ class Project(models.Model): if view_type == 'form' ] or [False, 'form'] action['view_mode'] = 'form' - if res_id: - action['res_id'] = res_id + action['res_id'] = res_id return action return super().action_profitability_items(section_name, domain, res_id) diff --git a/addons/sale_timesheet/views/hr_timesheet_views.xml b/addons/sale_timesheet/views/hr_timesheet_views.xml index b7fb9c91d48..ce675a38a6f 100644 --- a/addons/sale_timesheet/views/hr_timesheet_views.xml +++ b/addons/sale_timesheet/views/hr_timesheet_views.xml @@ -59,6 +59,7 @@ + @@ -68,6 +69,7 @@ account.analytic.line + @@ -75,6 +77,18 @@ + + account.analytic.line.pivot.per.invoice + account.analytic.line + + primary + + + timesheet_invoice_id + + + +