From 5f22eed49c1242cf25f628e87fe44eba3852f17c Mon Sep 17 00:00:00 2001 From: Chauhan Aadil Riyazmohamed Date: Fri, 27 Oct 2023 16:32:02 +0530 Subject: [PATCH] [FIX] hr_timesheet: hide WIP report in timesheet views Before this commit, when `mrp_account` module is installed, a new report to print is added in all views of `account.analytic.line`. the problem is since timesheet model is `account.analytic.line` then that report is available in the timesheets views and when the user chooses that report to print in a timesheet view then he will get a traceback because that report does not for the timesheet record. This commit hides `WIP` report in the print menu when the view displayed timesheets records only. That is all the views in the timesheets app. task-3465424 closes odoo/odoo#145597 X-original-commit: https://github.com/odoo/odoo/pull/132005/commits/b293a6c9a5b2f7fb3a0c7624eccf5406c71521f1 Signed-off-by: Xavier Bol (xbo) --- addons/hr_timesheet/models/hr_timesheet.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index ed64d3ab209..fc9282d7892 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -249,6 +249,24 @@ class AccountAnalyticLine(models.Model): key = super()._get_view_cache_key(view_id, view_type, **options) return key + (self.env.company.timesheet_encode_uom_id,) + @api.model + def get_views(self, views, options=None): + res = super().get_views(views, options) + if options and options.get('toolbar'): + wip_report_id = None + + def get_wip_report_id(): + return self.env['ir.model.data']._xmlid_to_res_id("mrp_account.wip_report", raise_if_not_found=False) + + for view_data in res['views'].values(): + print_data_list = view_data.get('toolbar', {}).get('print') + if print_data_list: + if wip_report_id is None and re.search(r'widget="timesheet_uom(\w)*"', view_data['arch']): + wip_report_id = get_wip_report_id() + if wip_report_id: + view_data['toolbar']['print'] = [print_data for print_data in print_data_list if print_data['id'] != wip_report_id] + return res + @api.model def _get_view(self, view_id=None, view_type='form', **options): """ Set the correct label for `unit_amount`, depending on company UoM """